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.20. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
f0dd554e3c
commit
570d5a9645
3 changed files with 4 additions and 127 deletions
|
@ -14,7 +14,6 @@ import (
|
||||||
containertypes "github.com/docker/docker/api/types/container"
|
containertypes "github.com/docker/docker/api/types/container"
|
||||||
networktypes "github.com/docker/docker/api/types/network"
|
networktypes "github.com/docker/docker/api/types/network"
|
||||||
"github.com/docker/docker/api/types/versions"
|
"github.com/docker/docker/api/types/versions"
|
||||||
"github.com/docker/docker/api/types/versions/v1p20"
|
|
||||||
"github.com/docker/docker/container"
|
"github.com/docker/docker/container"
|
||||||
"github.com/docker/docker/daemon/config"
|
"github.com/docker/docker/daemon/config"
|
||||||
"github.com/docker/docker/daemon/network"
|
"github.com/docker/docker/daemon/network"
|
||||||
|
@ -29,8 +28,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.Equal(version, "1.20"):
|
|
||||||
return daemon.containerInspect120(name)
|
|
||||||
case versions.LessThan(version, "1.45"):
|
case versions.LessThan(version, "1.45"):
|
||||||
ctr, err := daemon.ContainerInspectCurrent(ctx, name, size)
|
ctr, err := daemon.ContainerInspectCurrent(ctx, name, size)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -115,35 +112,6 @@ func (daemon *Daemon) ContainerInspectCurrent(ctx context.Context, name string,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// containerInspect120 serializes the master version of a container into a json type.
|
|
||||||
func (daemon *Daemon) containerInspect120(name string) (*v1p20.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
|
|
||||||
}
|
|
||||||
|
|
||||||
return &v1p20.ContainerJSON{
|
|
||||||
ContainerJSONBase: base,
|
|
||||||
Mounts: ctr.GetMountPoints(),
|
|
||||||
Config: &v1p20.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,
|
|
||||||
},
|
|
||||||
NetworkSettings: daemon.getBackwardsCompatibleNetworkSettings(ctr.NetworkSettings),
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (daemon *Daemon) getInspectData(daemonCfg *config.Config, container *container.Container) (*types.ContainerJSONBase, error) {
|
func (daemon *Daemon) getInspectData(daemonCfg *config.Config, container *container.Container) (*types.ContainerJSONBase, error) {
|
||||||
// make a copy to play with
|
// make a copy to play with
|
||||||
hostConfig := *container.HostConfig
|
hostConfig := *container.HostConfig
|
||||||
|
@ -281,25 +249,6 @@ func (daemon *Daemon) ContainerExecInspect(id string) (*backend.ExecInspect, err
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (daemon *Daemon) getBackwardsCompatibleNetworkSettings(settings *network.Settings) *v1p20.NetworkSettings {
|
|
||||||
result := &v1p20.NetworkSettings{
|
|
||||||
NetworkSettingsBase: types.NetworkSettingsBase{
|
|
||||||
Bridge: settings.Bridge,
|
|
||||||
SandboxID: settings.SandboxID,
|
|
||||||
SandboxKey: settings.SandboxKey,
|
|
||||||
HairpinMode: settings.HairpinMode,
|
|
||||||
LinkLocalIPv6Address: settings.LinkLocalIPv6Address,
|
|
||||||
LinkLocalIPv6PrefixLen: settings.LinkLocalIPv6PrefixLen,
|
|
||||||
Ports: settings.Ports,
|
|
||||||
SecondaryIPAddresses: settings.SecondaryIPAddresses,
|
|
||||||
SecondaryIPv6Addresses: settings.SecondaryIPv6Addresses,
|
|
||||||
},
|
|
||||||
DefaultNetworkSettings: daemon.getDefaultNetworkSettings(settings.Networks),
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
// getDefaultNetworkSettings creates the deprecated structure that holds the information
|
// getDefaultNetworkSettings creates the deprecated structure that holds the information
|
||||||
// about the bridge network for a container.
|
// about the bridge network for a container.
|
||||||
func (daemon *Daemon) getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings {
|
func (daemon *Daemon) getDefaultNetworkSettings(networks map[string]*network.EndpointSettings) types.DefaultNetworkSettings {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/versions/v1p20"
|
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
"github.com/docker/docker/integration-cli/cli"
|
"github.com/docker/docker/integration-cli/cli"
|
||||||
"github.com/docker/docker/testutil"
|
"github.com/docker/docker/testutil"
|
||||||
|
@ -31,12 +30,13 @@ func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) {
|
||||||
var cases []acase
|
var cases []acase
|
||||||
|
|
||||||
if testEnv.DaemonInfo.OSType == "windows" {
|
if testEnv.DaemonInfo.OSType == "windows" {
|
||||||
|
// Windows only supports 1.25 or later
|
||||||
cases = []acase{
|
cases = []acase{
|
||||||
{"v1.25", append(keysBase, "Mounts")},
|
{"v1.25", append(keysBase, "Mounts")},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cases = []acase{
|
cases = []acase{
|
||||||
{"v1.20", append(keysBase, "Mounts")},
|
{"v1.24", append(keysBase, "Mounts")},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,28 +58,6 @@ func (s *DockerAPISuite) TestInspectAPIContainerResponse(c *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriverLegacy(c *testing.T) {
|
|
||||||
// No legacy implications for Windows
|
|
||||||
testRequires(c, DaemonIsLinux)
|
|
||||||
out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
|
|
||||||
cleanedContainerID := strings.TrimSpace(out)
|
|
||||||
|
|
||||||
cases := []string{"v1.20"}
|
|
||||||
for _, version := range cases {
|
|
||||||
body := getInspectBody(c, version, cleanedContainerID)
|
|
||||||
|
|
||||||
var inspectJSON map[string]interface{}
|
|
||||||
err := json.Unmarshal(body, &inspectJSON)
|
|
||||||
assert.NilError(c, err, "Unable to unmarshal body for version %s", version)
|
|
||||||
|
|
||||||
config, ok := inspectJSON["Config"]
|
|
||||||
assert.Assert(c, ok, "Unable to find 'Config'")
|
|
||||||
cfg := config.(map[string]interface{})
|
|
||||||
_, ok = cfg["VolumeDriver"]
|
|
||||||
assert.Assert(c, ok, "API version %s expected to include VolumeDriver in 'Config'", version)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriver(c *testing.T) {
|
func (s *DockerAPISuite) TestInspectAPIContainerVolumeDriver(c *testing.T) {
|
||||||
out := cli.DockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true").Stdout()
|
out := cli.DockerCmd(c, "run", "-d", "--volume-driver", "local", "busybox", "true").Stdout()
|
||||||
cleanedContainerID := strings.TrimSpace(out)
|
cleanedContainerID := strings.TrimSpace(out)
|
||||||
|
@ -117,47 +95,6 @@ func (s *DockerAPISuite) TestInspectAPIImageResponse(c *testing.T) {
|
||||||
assert.Check(c, is.Contains(imageJSON.RepoTags, "busybox:mytag"))
|
assert.Check(c, is.Contains(imageJSON.RepoTags, "busybox:mytag"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// #17131, #17139, #17173
|
|
||||||
func (s *DockerAPISuite) TestInspectAPIEmptyFieldsInConfigPre121(c *testing.T) {
|
|
||||||
// Not relevant on Windows
|
|
||||||
testRequires(c, DaemonIsLinux)
|
|
||||||
out := cli.DockerCmd(c, "run", "-d", "busybox", "true").Stdout()
|
|
||||||
cleanedContainerID := strings.TrimSpace(out)
|
|
||||||
|
|
||||||
cases := []string{"v1.20"}
|
|
||||||
for _, version := range cases {
|
|
||||||
body := getInspectBody(c, version, cleanedContainerID)
|
|
||||||
|
|
||||||
var inspectJSON map[string]interface{}
|
|
||||||
err := json.Unmarshal(body, &inspectJSON)
|
|
||||||
assert.NilError(c, err, "Unable to unmarshal body for version %s", version)
|
|
||||||
config, ok := inspectJSON["Config"]
|
|
||||||
assert.Assert(c, ok, "Unable to find 'Config'")
|
|
||||||
cfg := config.(map[string]interface{})
|
|
||||||
for _, f := range []string{"MacAddress", "NetworkDisabled", "ExposedPorts"} {
|
|
||||||
_, ok := cfg[f]
|
|
||||||
assert.Check(c, ok, "API version %s expected to include %s in 'Config'", version, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *DockerAPISuite) TestInspectAPIBridgeNetworkSettings120(c *testing.T) {
|
|
||||||
// Not relevant on Windows, and besides it doesn't have any bridge network settings
|
|
||||||
testRequires(c, DaemonIsLinux)
|
|
||||||
out := cli.DockerCmd(c, "run", "-d", "busybox", "top").Stdout()
|
|
||||||
containerID := strings.TrimSpace(out)
|
|
||||||
cli.WaitRun(c, containerID)
|
|
||||||
|
|
||||||
body := getInspectBody(c, "v1.20", containerID)
|
|
||||||
|
|
||||||
var inspectJSON v1p20.ContainerJSON
|
|
||||||
err := json.Unmarshal(body, &inspectJSON)
|
|
||||||
assert.NilError(c, err)
|
|
||||||
|
|
||||||
settings := inspectJSON.NetworkSettings
|
|
||||||
assert.Assert(c, len(settings.IPAddress) != 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inspect for API v1.21 and up; see
|
// Inspect for API v1.21 and up; see
|
||||||
//
|
//
|
||||||
// - https://github.com/moby/moby/issues/17131
|
// - https://github.com/moby/moby/issues/17131
|
||||||
|
|
|
@ -15,7 +15,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/versions/v1p20"
|
|
||||||
"github.com/docker/docker/integration-cli/cli"
|
"github.com/docker/docker/integration-cli/cli"
|
||||||
"github.com/docker/docker/integration-cli/daemon"
|
"github.com/docker/docker/integration-cli/daemon"
|
||||||
"github.com/docker/docker/libnetwork/driverapi"
|
"github.com/docker/docker/libnetwork/driverapi"
|
||||||
|
@ -1015,22 +1014,14 @@ func (s *DockerCLINetworkSuite) TestInspectAPIMultipleNetworks(c *testing.T) {
|
||||||
cli.DockerCmd(c, "network", "connect", "mybridge1", id)
|
cli.DockerCmd(c, "network", "connect", "mybridge1", id)
|
||||||
cli.DockerCmd(c, "network", "connect", "mybridge2", id)
|
cli.DockerCmd(c, "network", "connect", "mybridge2", id)
|
||||||
|
|
||||||
body := getInspectBody(c, "v1.20", id)
|
|
||||||
var inspect120 v1p20.ContainerJSON
|
|
||||||
err := json.Unmarshal(body, &inspect120)
|
|
||||||
assert.NilError(c, err)
|
|
||||||
|
|
||||||
versionedIP := inspect120.NetworkSettings.IPAddress
|
|
||||||
|
|
||||||
// Current API version (API v1.21 and up)
|
// Current API version (API v1.21 and up)
|
||||||
body = getInspectBody(c, "", id)
|
body := getInspectBody(c, "", id)
|
||||||
var inspectCurrent types.ContainerJSON
|
var inspectCurrent types.ContainerJSON
|
||||||
err = json.Unmarshal(body, &inspectCurrent)
|
err := json.Unmarshal(body, &inspectCurrent)
|
||||||
assert.NilError(c, err)
|
assert.NilError(c, err)
|
||||||
assert.Equal(c, len(inspectCurrent.NetworkSettings.Networks), 3)
|
assert.Equal(c, len(inspectCurrent.NetworkSettings.Networks), 3)
|
||||||
|
|
||||||
bridge := inspectCurrent.NetworkSettings.Networks["bridge"]
|
bridge := inspectCurrent.NetworkSettings.Networks["bridge"]
|
||||||
assert.Equal(c, bridge.IPAddress, versionedIP)
|
|
||||||
assert.Equal(c, bridge.IPAddress, inspectCurrent.NetworkSettings.IPAddress)
|
assert.Equal(c, bridge.IPAddress, inspectCurrent.NetworkSettings.IPAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue