Inspect: API v1.51 compatibility

For API < v1.52:
- In container inspect:
  - Restore GraphDriver when a snapshotter is used.
  - Remove field Storage
  - Related to commit efa077848f
- In image inspect:
  - Restore GraphDriver when a snapshotter is used.
  - Related to commit c441b2ef19

Co-authored-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Rob Murray <rob.murray@docker.com>
This commit is contained in:
Rob Murray
2025-10-22 14:35:53 +01:00
parent 00abc3a9d5
commit 0971a3bcb8
6 changed files with 115 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/moby/moby/api/types/container"
imagetypes "github.com/moby/moby/api/types/image"
"github.com/moby/moby/api/types/registry"
"github.com/moby/moby/api/types/storage"
"github.com/moby/moby/v2/daemon/internal/filters"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
@@ -92,4 +93,8 @@ type InspectData struct {
//
// This field is removed in API v1.45, but used for API <= v1.44 responses.
ContainerConfig *container.Config
// GraphDriverLegacy is used for API versions < v1.52, which included the
// name of the snapshotter the GraphDriver field.
GraphDriverLegacy *storage.DriverData
}

View File

@@ -5,6 +5,7 @@ import (
"net/http"
"github.com/moby/moby/api/types/container"
"github.com/moby/moby/api/types/storage"
"github.com/moby/moby/api/types/versions"
"github.com/moby/moby/v2/daemon/internal/compat"
"github.com/moby/moby/v2/daemon/internal/stringid"
@@ -69,6 +70,15 @@ func (c *containerRouter) getContainersByName(ctx context.Context, w http.Respon
},
}))
}
// Restore the GraphDriver field, now omitted when a snapshotter is used.
// Remove the Storage field that replaced it.
if ctr.GraphDriver == nil && ctr.Storage != nil && ctr.Storage.RootFS != nil && ctr.Storage.RootFS.Snapshot != nil {
ctr.GraphDriver = &storage.DriverData{
Name: ctr.Storage.RootFS.Snapshot.Name,
}
ctr.Storage = nil
}
}
return httputils.WriteJSON(w, http.StatusOK, compat.Wrap(ctr, wrapOpts...))

View File

@@ -440,6 +440,11 @@ func (ir *imageRouter) getImagesByName(ctx context.Context, w http.ResponseWrite
"Config": legacyConfigFields["v1.50-v1.51"],
}))
}
// Restore the GraphDriver field, now omitted when a snapshotter is used.
if imageInspect.GraphDriver == nil && inspectData.GraphDriverLegacy != nil {
imageInspect.GraphDriver = inspectData.GraphDriverLegacy
}
} else {
if inspectData.Parent != "" {
// field is deprecated, but still included in response when present (built with legacy builder).