Browse code

api/types/image: make `InspectResponse.GraphDriver` optional

This change makes the `GraphDriver` field in `image.InspectResponse` optional. This field will only be returned when using moby engine graph drivers as a backend storage implementation. It will be omitted when using the containerd image backend.

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>

Austin Vazquez authored on 2025/09/04 22:04:57
Showing 6 changed files
... ...
@@ -2057,6 +2057,7 @@ definitions:
2057 2057
         format: "int64"
2058 2058
         example: 1239828
2059 2059
       GraphDriver:
2060
+        x-nullable: true
2060 2061
         $ref: "#/definitions/DriverData"
2061 2062
       RootFS:
2062 2063
         description: |
... ...
@@ -111,7 +111,7 @@ type InspectResponse struct {
111 111
 
112 112
 	// GraphDriver holds information about the storage driver used to store the
113 113
 	// container's and image's filesystem.
114
-	GraphDriver storage.DriverData
114
+	GraphDriver *storage.DriverData `json:"GraphDriver,omitempty"`
115 115
 
116 116
 	// RootFS contains information about the image's RootFS, including the
117 117
 	// layer IDs.
... ...
@@ -12,7 +12,6 @@ import (
12 12
 	"github.com/distribution/reference"
13 13
 	imagespec "github.com/moby/docker-image-spec/specs-go/v1"
14 14
 	imagetypes "github.com/moby/moby/api/types/image"
15
-	"github.com/moby/moby/api/types/storage"
16 15
 	"github.com/moby/moby/v2/daemon/internal/sliceutil"
17 16
 	"github.com/moby/moby/v2/daemon/server/backend"
18 17
 	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
... ...
@@ -95,10 +94,6 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, opts ba
95 95
 		DockerVersion: "",
96 96
 		Size:          size,
97 97
 		Manifests:     manifests,
98
-		GraphDriver: storage.DriverData{
99
-			Name: i.snapshotter,
100
-			Data: nil,
101
-		},
102 98
 		Metadata: imagetypes.Metadata{
103 99
 			LastTagTime: lastUpdated,
104 100
 		},
... ...
@@ -71,7 +71,7 @@ func (i *ImageService) ImageInspect(ctx context.Context, refOrID string, opts ba
71 71
 		Os:              img.OperatingSystem(),
72 72
 		OsVersion:       img.OSVersion,
73 73
 		Size:            size,
74
-		GraphDriver: storage.DriverData{
74
+		GraphDriver: &storage.DriverData{
75 75
 			Name: i.layerStore.DriverName(),
76 76
 			Data: layerMetadata,
77 77
 		},
... ...
@@ -73,8 +73,10 @@ func TestGraphDriverPersistence(t *testing.T) {
73 73
 	assert.Check(t, is.Equal(info.Driver, prevDriver))
74 74
 
75 75
 	// Verify our image is still there
76
-	_, err = c.ImageInspect(ctx, testImage)
76
+	imageInspect, err := c.ImageInspect(ctx, testImage)
77 77
 	assert.NilError(t, err, "Test image should still be available after daemon restart")
78
+	assert.Check(t, imageInspect.GraphDriver != nil, "GraphDriver should be set for graphdriver backend")
79
+	assert.Check(t, is.Equal(imageInspect.GraphDriver.Name, prevDriver), "Image graphdriver data should match")
78 80
 
79 81
 	// Verify our container is still there
80 82
 	_, err = c.ContainerInspect(ctx, containerID)
... ...
@@ -111,7 +111,7 @@ type InspectResponse struct {
111 111
 
112 112
 	// GraphDriver holds information about the storage driver used to store the
113 113
 	// container's and image's filesystem.
114
-	GraphDriver storage.DriverData
114
+	GraphDriver *storage.DriverData `json:"GraphDriver,omitempty"`
115 115
 
116 116
 	// RootFS contains information about the image's RootFS, including the
117 117
 	// layer IDs.