api: remove code for ContainerInspect on api < v1.20

API v1.23 and older are deprecated, so we can remove the code to adjust
responses for API v1.19 and lower.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2024-01-21 18:27:54 +01:00
parent dfdf2adf0c
commit f0dd554e3c
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
6 changed files with 2 additions and 127 deletions

View file

@ -1,35 +0,0 @@
// Package v1p19 provides specific API types for the API version 1, patch 19.
package v1p19 // import "github.com/docker/docker/api/types/versions/v1p19"
import (
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/versions/v1p20"
"github.com/docker/go-connections/nat"
)
// ContainerJSON is a backcompatibility struct for APIs prior to 1.20.
// Note this is not used by the Windows daemon.
type ContainerJSON struct {
*types.ContainerJSONBase
Volumes map[string]string
VolumesRW map[string]bool
Config *ContainerConfig
NetworkSettings *v1p20.NetworkSettings
}
// ContainerConfig is a backcompatibility struct for APIs prior to 1.20.
type ContainerConfig struct {
*container.Config
MacAddress string
NetworkDisabled bool
ExposedPorts map[nat.Port]struct{}
// backward compatibility, they now live in HostConfig
VolumeDriver string
Memory int64
MemorySwap int64
CPUShares int64 `json:"CpuShares"`
CPUSet string `json:"Cpuset"`
}

View file

@ -29,8 +29,6 @@ import (
// there is an error getting the data. // there is an error getting the data.
func (daemon *Daemon) ContainerInspect(ctx context.Context, name string, size bool, version string) (interface{}, error) { func (daemon *Daemon) ContainerInspect(ctx context.Context, name string, size bool, version string) (interface{}, error) {
switch { switch {
case versions.LessThan(version, "1.20"):
return daemon.containerInspectPre120(ctx, name)
case versions.Equal(version, "1.20"): case versions.Equal(version, "1.20"):
return daemon.containerInspect120(name) return daemon.containerInspect120(name)
case versions.LessThan(version, "1.45"): case versions.LessThan(version, "1.45"):

View file

@ -1,11 +1,8 @@
package daemon // import "github.com/docker/docker/daemon" package daemon // import "github.com/docker/docker/daemon"
import ( import (
"context"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/versions/v1p19"
"github.com/docker/docker/container" "github.com/docker/docker/container"
) )
@ -19,47 +16,6 @@ func setPlatformSpecificContainerFields(container *container.Container, contJSON
return contJSONBase return contJSONBase
} }
// containerInspectPre120 gets containers for pre 1.20 APIs.
func (daemon *Daemon) containerInspectPre120(ctx context.Context, name string) (*v1p19.ContainerJSON, error) {
ctr, err := daemon.GetContainer(name)
if err != nil {
return nil, err
}
ctr.Lock()
defer ctr.Unlock()
base, err := daemon.getInspectData(&daemon.config().Config, ctr)
if err != nil {
return nil, err
}
volumes := make(map[string]string)
volumesRW := make(map[string]bool)
for _, m := range ctr.MountPoints {
volumes[m.Destination] = m.Path()
volumesRW[m.Destination] = m.RW
}
return &v1p19.ContainerJSON{
ContainerJSONBase: base,
Volumes: volumes,
VolumesRW: volumesRW,
Config: &v1p19.ContainerConfig{
Config: ctr.Config,
MacAddress: ctr.Config.MacAddress, //nolint:staticcheck // ignore SA1019: field is deprecated, but still used on API < v1.44.
NetworkDisabled: ctr.Config.NetworkDisabled,
ExposedPorts: ctr.Config.ExposedPorts,
VolumeDriver: ctr.HostConfig.VolumeDriver,
Memory: ctr.HostConfig.Memory,
MemorySwap: ctr.HostConfig.MemorySwap,
CPUShares: ctr.HostConfig.CPUShares,
CPUSet: ctr.HostConfig.CpusetCpus,
},
NetworkSettings: daemon.getBackwardsCompatibleNetworkSettings(ctr.NetworkSettings),
}, nil
}
func inspectExecProcessConfig(e *container.ExecConfig) *backend.ExecProcessConfig { func inspectExecProcessConfig(e *container.ExecConfig) *backend.ExecProcessConfig {
return &backend.ExecProcessConfig{ return &backend.ExecProcessConfig{
Tty: e.Tty, Tty: e.Tty,

View file

@ -1,8 +1,6 @@
package daemon // import "github.com/docker/docker/daemon" package daemon // import "github.com/docker/docker/daemon"
import ( import (
"context"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend" "github.com/docker/docker/api/types/backend"
"github.com/docker/docker/container" "github.com/docker/docker/container"
@ -13,11 +11,6 @@ func setPlatformSpecificContainerFields(container *container.Container, contJSON
return contJSONBase return contJSONBase
} }
// containerInspectPre120 get containers for pre 1.20 APIs.
func (daemon *Daemon) containerInspectPre120(ctx context.Context, name string) (*types.ContainerJSON, error) {
return daemon.ContainerInspectCurrent(ctx, name, false)
}
func inspectExecProcessConfig(e *container.ExecConfig) *backend.ExecProcessConfig { func inspectExecProcessConfig(e *container.ExecConfig) *backend.ExecProcessConfig {
return &backend.ExecProcessConfig{ return &backend.ExecProcessConfig{
Tty: e.Tty, Tty: e.Tty,

View file

@ -37,7 +37,6 @@ func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) {
} else { } else {
cases = []acase{ cases = []acase{
{"v1.20", append(keysBase, "Mounts")}, {"v1.20", append(keysBase, "Mounts")},
{"v1.19", append(keysBase, "Volumes", "VolumesRW")},
} }
} }
@ -65,7 +64,7 @@ func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T)
out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout() out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
cases := []string{"v1.19", "v1.20"} cases := []string{"v1.20"}
for _, version := range cases { for _, version := range cases {
body := getInspectBody(c, version, cleanedContainerID) body := getInspectBody(c, version, cleanedContainerID)
@ -125,7 +124,7 @@ func (s *DockerAPISuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) {
out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout() out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
cleanedContainerID := strings.TrimSpace(out) cleanedContainerID := strings.TrimSpace(out)
cases := []string{"v1.19", "v1.20"} cases := []string{"v1.20"}
for _, version := range cases { for _, version := range cases {
body := getInspectBody(c, version, cleanedContainerID) body := getInspectBody(c, version, cleanedContainerID)

View file

@ -1,53 +1,17 @@
package container // import "github.com/docker/docker/integration/container" package container // import "github.com/docker/docker/integration/container"
import ( import (
"encoding/json"
"runtime" "runtime"
"strings" "strings"
"testing" "testing"
"time"
containertypes "github.com/docker/docker/api/types/container" containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/testutil/request" "github.com/docker/docker/testutil/request"
"gotest.tools/v3/assert" "gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp" is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/poll"
"gotest.tools/v3/skip"
) )
func TestInspectCpusetInConfigPre120(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType == "windows" || !testEnv.DaemonInfo.CPUSet)
ctx := setupTest(t)
apiClient := request.NewAPIClient(t, client.WithVersion("1.19"))
name := strings.ToLower(t.Name())
// Create container with up to-date-API
container.Run(ctx, t, request.NewAPIClient(t), container.WithName(name),
container.WithCmd("true"),
func(c *container.TestContainerConfig) {
c.HostConfig.Resources.CpusetCpus = "0"
},
)
poll.WaitOn(t, container.IsInState(ctx, apiClient, name, "exited"), poll.WithDelay(100*time.Millisecond))
_, body, err := apiClient.ContainerInspectWithRaw(ctx, name, false)
assert.NilError(t, err)
var inspectJSON map[string]interface{}
err = json.Unmarshal(body, &inspectJSON)
assert.NilError(t, err, "unable to unmarshal body for version 1.19: %s", err)
config, ok := inspectJSON["Config"]
assert.Check(t, is.Equal(true, ok), "Unable to find 'Config'")
cfg := config.(map[string]interface{})
_, ok = cfg["Cpuset"]
assert.Check(t, is.Equal(true, ok), "API version 1.19 expected to include Cpuset in 'Config'")
}
func TestInspectAnnotations(t *testing.T) { func TestInspectAnnotations(t *testing.T) {
ctx := setupTest(t) ctx := setupTest(t)
apiClient := request.NewAPIClient(t) apiClient := request.NewAPIClient(t)