Browse Source

Merge pull request #45873 from thaJeztah/systeminfo_no_ad_hoc_type

api: info: don't use ad-hoc type for compatibility with old api versions
Sebastiaan van Stijn 2 năm trước cách đây
mục cha
commit
20364bd658
2 tập tin đã thay đổi với 14 bổ sung15 xóa
  1. 7 15
      api/server/router/system/system_routes.go
  2. 7 0
      api/types/types.go

+ 7 - 15
api/server/router/system/system_routes.go

@@ -67,24 +67,16 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
 	version := httputils.VersionFromContext(ctx)
 	if versions.LessThan(version, "1.25") {
 		// TODO: handle this conversion in engine-api
-		type oldInfo struct {
-			*types.Info
-			ExecutionDriver string
-		}
-		old := &oldInfo{
-			Info:            info,
-			ExecutionDriver: "<not supported>",
-		}
-		nameOnlySecurityOptions := []string{}
-		kvSecOpts, err := types.DecodeSecurityOptions(old.SecurityOptions)
+		kvSecOpts, err := types.DecodeSecurityOptions(info.SecurityOptions)
 		if err != nil {
-			return err
+			info.Warnings = append(info.Warnings, err.Error())
 		}
-		for _, s := range kvSecOpts {
-			nameOnlySecurityOptions = append(nameOnlySecurityOptions, s.Name)
+		var nameOnly []string
+		for _, so := range kvSecOpts {
+			nameOnly = append(nameOnly, so.Name)
 		}
-		old.SecurityOptions = nameOnlySecurityOptions
-		return httputils.WriteJSON(w, http.StatusOK, old)
+		info.SecurityOptions = nameOnly
+		info.ExecutionDriver = "<not supported>" //nolint:staticcheck // ignore SA1019 (ExecutionDriver is deprecated)
 	}
 	if versions.LessThan(version, "1.39") {
 		if info.KernelVersion == "" {

+ 7 - 0
api/types/types.go

@@ -307,6 +307,9 @@ type Info struct {
 	ProductLicense      string               `json:",omitempty"`
 	DefaultAddressPools []NetworkAddressPool `json:",omitempty"`
 
+	// Legacy API fields for older API versions.
+	legacyFields
+
 	// Warnings contains a slice of warnings that occurred  while collecting
 	// system information. These warnings are intended to be informational
 	// messages for the user, and are not intended to be parsed / used for
@@ -314,6 +317,10 @@ type Info struct {
 	Warnings []string
 }
 
+type legacyFields struct {
+	ExecutionDriver string `json:",omitempty"` // Deprecated: deprecated since API v1.25, but returned for older versions.
+}
+
 // KeyValue holds a key/value pair
 type KeyValue struct {
 	Key, Value string