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
This commit is contained in:
Sebastiaan van Stijn 2023-07-04 12:21:51 +02:00 committed by GitHub
commit 20364bd658
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 15 deletions

View file

@ -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 == "" {

View file

@ -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