Merge pull request #50857 from austinvazquez/add-container-inspect-storage-driver

Add container inspect storage field
This commit is contained in:
Sebastiaan van Stijn
2025-09-27 00:49:07 +02:00
committed by GitHub
14 changed files with 213 additions and 8 deletions

View File

@@ -1688,6 +1688,42 @@ definitions:
"WorkDir": "/var/lib/docker/overlay2/ef749362d13333e65fc95c572eb525abbe0052e16e086cb64bc3b98ae9aa6d74/work"
}
Storage:
description: |
Information about the storage used by the container.
type: "object"
properties:
RootFS:
description: |
Information about the storage used for the container's root filesystem.
type: "object"
x-nullable: true
$ref: "#/definitions/RootFSStorage"
RootFSStorage:
description: |
Information about the storage used for the container's root filesystem.
type: "object"
x-go-name: RootFSStorage
properties:
Snapshot:
description: |
Information about the snapshot used for the container's root filesystem.
type: "object"
x-nullable: true
$ref: "#/definitions/RootFSStorageSnapshot"
RootFSStorageSnapshot:
description: |
Information about a snapshot backend of the container's root filesystem.
type: "object"
x-go-name: RootFSStorageSnapshot
properties:
Name:
description: "Name of the snapshotter."
type: "string"
x-nullable: false
FilesystemChange:
description: |
Change in the container's filesystem.
@@ -5116,6 +5152,10 @@ definitions:
$ref: "#/definitions/HostConfig"
GraphDriver:
$ref: "#/definitions/DriverData"
x-nullable: true
Storage:
$ref: "#/definitions/Storage"
x-nullable: true
SizeRw:
description: |-
The size of files that have been created or changed by this container.

View File

@@ -1688,6 +1688,42 @@ definitions:
"WorkDir": "/var/lib/docker/overlay2/ef749362d13333e65fc95c572eb525abbe0052e16e086cb64bc3b98ae9aa6d74/work"
}
Storage:
description: |
Information about the storage used by the container.
type: "object"
properties:
RootFS:
description: |
Information about the storage used for the container's root filesystem.
type: "object"
x-nullable: true
$ref: "#/definitions/RootFSStorage"
RootFSStorage:
description: |
Information about the storage used for the container's root filesystem.
type: "object"
x-go-name: RootFSStorage
properties:
Snapshot:
description: |
Information about the snapshot used for the container's root filesystem.
type: "object"
x-nullable: true
$ref: "#/definitions/RootFSStorageSnapshot"
RootFSStorageSnapshot:
description: |
Information about a snapshot backend of the container's root filesystem.
type: "object"
x-go-name: RootFSStorageSnapshot
properties:
Name:
description: "Name of the snapshotter."
type: "string"
x-nullable: false
FilesystemChange:
description: |
Change in the container's filesystem.
@@ -5116,6 +5152,10 @@ definitions:
$ref: "#/definitions/HostConfig"
GraphDriver:
$ref: "#/definitions/DriverData"
x-nullable: true
Storage:
$ref: "#/definitions/Storage"
x-nullable: true
SizeRw:
description: |-
The size of files that have been created or changed by this container.

View File

@@ -134,7 +134,13 @@ type InspectResponse struct {
AppArmorProfile string
ExecIDs []string
HostConfig *HostConfig
GraphDriver storage.DriverData
// GraphDriver contains information about the container's graph driver.
GraphDriver *storage.DriverData `json:"GraphDriver,omitempty"`
// Storage contains information about the storage used for the container's filesystem.
Storage *storage.Storage `json:"Storage,omitempty"`
SizeRw *int64 `json:",omitempty"`
SizeRootFs *int64 `json:",omitempty"`
Mounts []MountPoint

View File

@@ -0,0 +1,16 @@
// Code generated by go-swagger; DO NOT EDIT.
package storage
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// RootFSStorage Information about the storage used for the container's root filesystem.
//
// swagger:model RootFSStorage
type RootFSStorage struct {
// Information about the snapshot used for the container's root filesystem.
//
Snapshot *RootFSStorageSnapshot `json:"Snapshot,omitempty"`
}

View File

@@ -0,0 +1,15 @@
// Code generated by go-swagger; DO NOT EDIT.
package storage
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// RootFSStorageSnapshot Information about a snapshot backend of the container's root filesystem.
//
// swagger:model RootFSStorageSnapshot
type RootFSStorageSnapshot struct {
// Name of the snapshotter.
Name string `json:"Name,omitempty"`
}

View File

@@ -0,0 +1,16 @@
// Code generated by go-swagger; DO NOT EDIT.
package storage
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// Storage Information about the storage used by the container.
//
// swagger:model Storage
type Storage struct {
// Information about the storage used for the container's root filesystem.
//
RootFS *RootFSStorage `json:"RootFS,omitempty"`
}

View File

@@ -147,20 +147,28 @@ func (daemon *Daemon) getInspectData(daemonCfg *config.Config, ctr *container.Co
ProcessLabel: ctr.ProcessLabel,
ExecIDs: ctr.GetExecIDs(),
HostConfig: &hostConfig,
GraphDriver: storage.DriverData{
Name: ctr.Driver,
},
Config: ctr.Config,
Config: ctr.Config,
}
// Now set any platform-specific fields
inspectResponse = setPlatformSpecificContainerFields(ctr, inspectResponse)
if daemon.UsesSnapshotter() {
inspectResponse.Storage = &storage.Storage{
RootFS: &storage.RootFSStorage{
Snapshot: &storage.RootFSStorageSnapshot{
Name: ctr.Driver,
},
},
}
// Additional information only applies to graphDrivers, so we're done.
return inspectResponse, nil
}
inspectResponse.GraphDriver = &storage.DriverData{
Name: ctr.Driver,
}
if ctr.RWLayer == nil {
if ctr.State.Dead {
return inspectResponse, nil

View File

@@ -83,6 +83,9 @@ EOT
generate_model types/storage <<- 'EOT'
DriverData
RootFSStorage
RootFSStorageSnapshot
Storage
EOT
generate_model types/swarm <<- 'EOT'

View File

@@ -19,10 +19,16 @@ func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) {
keysBase := []string{
"Id", "State", "Created", "Path", "Args", "Config", "Image", "NetworkSettings",
"ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "MountLabel", "ProcessLabel", "GraphDriver",
"ResolvConfPath", "HostnamePath", "HostsPath", "LogPath", "Name", "Driver", "MountLabel", "ProcessLabel",
"Mounts",
}
if testEnv.UsingSnapshotter() {
keysBase = append(keysBase, "Storage")
} else {
keysBase = append(keysBase, "GraphDriver")
}
cases := []struct {
version string
keys []string

View File

@@ -79,6 +79,8 @@ func TestGraphDriverPersistence(t *testing.T) {
assert.Check(t, is.Equal(imageInspect.GraphDriver.Name, prevDriver), "Image graphdriver data should match")
// Verify our container is still there
_, err = c.ContainerInspect(ctx, containerID)
containerInspect, err := c.ContainerInspect(ctx, containerID)
assert.NilError(t, err, "Test container should still exist after daemon restart")
assert.Check(t, containerInspect.GraphDriver != nil, "GraphDriver should be set for graphdriver backend")
assert.Check(t, is.Equal(containerInspect.GraphDriver.Name, prevDriver), "Container graphdriver data should match")
}

View File

@@ -134,7 +134,13 @@ type InspectResponse struct {
AppArmorProfile string
ExecIDs []string
HostConfig *HostConfig
GraphDriver storage.DriverData
// GraphDriver contains information about the container's graph driver.
GraphDriver *storage.DriverData `json:"GraphDriver,omitempty"`
// Storage contains information about the storage used for the container's filesystem.
Storage *storage.Storage `json:"Storage,omitempty"`
SizeRw *int64 `json:",omitempty"`
SizeRootFs *int64 `json:",omitempty"`
Mounts []MountPoint

View File

@@ -0,0 +1,16 @@
// Code generated by go-swagger; DO NOT EDIT.
package storage
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// RootFSStorage Information about the storage used for the container's root filesystem.
//
// swagger:model RootFSStorage
type RootFSStorage struct {
// Information about the snapshot used for the container's root filesystem.
//
Snapshot *RootFSStorageSnapshot `json:"Snapshot,omitempty"`
}

View File

@@ -0,0 +1,15 @@
// Code generated by go-swagger; DO NOT EDIT.
package storage
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// RootFSStorageSnapshot Information about a snapshot backend of the container's root filesystem.
//
// swagger:model RootFSStorageSnapshot
type RootFSStorageSnapshot struct {
// Name of the snapshotter.
Name string `json:"Name,omitempty"`
}

View File

@@ -0,0 +1,16 @@
// Code generated by go-swagger; DO NOT EDIT.
package storage
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
// Storage Information about the storage used by the container.
//
// swagger:model Storage
type Storage struct {
// Information about the storage used for the container's root filesystem.
//
RootFS *RootFSStorage `json:"RootFS,omitempty"`
}