From 917dae58e17d7095cbab1b58f67cb0d6cab09956 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 11 Aug 2023 18:33:07 +0200 Subject: [PATCH 1/2] integration/internal/container: remove import aliases Some files used aliases, others didn't, and they didn't appear to be required. Signed-off-by: Sebastiaan van Stijn --- integration/internal/container/ops.go | 52 +++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/integration/internal/container/ops.go b/integration/internal/container/ops.go index 7f173ae0b9..ca443fe8af 100644 --- a/integration/internal/container/ops.go +++ b/integration/internal/container/ops.go @@ -3,9 +3,9 @@ package container import ( "strings" - containertypes "github.com/docker/docker/api/types/container" - mounttypes "github.com/docker/docker/api/types/mount" - networktypes "github.com/docker/docker/api/types/network" + "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/mount" + "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/strslice" "github.com/docker/go-connections/nat" ocispec "github.com/opencontainers/image-spec/specs-go/v1" @@ -42,7 +42,7 @@ func WithCmd(cmds ...string) func(*TestContainerConfig) { // WithNetworkMode sets the network mode of the container func WithNetworkMode(mode string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { - c.HostConfig.NetworkMode = containertypes.NetworkMode(mode) + c.HostConfig.NetworkMode = container.NetworkMode(mode) } } @@ -71,7 +71,7 @@ func WithWorkingDir(dir string) func(*TestContainerConfig) { } // WithMount adds an mount -func WithMount(m mounttypes.Mount) func(*TestContainerConfig) { +func WithMount(m mount.Mount) func(*TestContainerConfig) { return func(c *TestContainerConfig) { c.HostConfig.Mounts = append(c.HostConfig.Mounts, m) } @@ -115,34 +115,34 @@ func WithTmpfs(targetAndOpts string) func(config *TestContainerConfig) { } // WithIPv4 sets the specified ip for the specified network of the container -func WithIPv4(network, ip string) func(*TestContainerConfig) { +func WithIPv4(networkName, ip string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { if c.NetworkingConfig.EndpointsConfig == nil { - c.NetworkingConfig.EndpointsConfig = map[string]*networktypes.EndpointSettings{} + c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{} } - if v, ok := c.NetworkingConfig.EndpointsConfig[network]; !ok || v == nil { - c.NetworkingConfig.EndpointsConfig[network] = &networktypes.EndpointSettings{} + if v, ok := c.NetworkingConfig.EndpointsConfig[networkName]; !ok || v == nil { + c.NetworkingConfig.EndpointsConfig[networkName] = &network.EndpointSettings{} } - if c.NetworkingConfig.EndpointsConfig[network].IPAMConfig == nil { - c.NetworkingConfig.EndpointsConfig[network].IPAMConfig = &networktypes.EndpointIPAMConfig{} + if c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig == nil { + c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig = &network.EndpointIPAMConfig{} } - c.NetworkingConfig.EndpointsConfig[network].IPAMConfig.IPv4Address = ip + c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig.IPv4Address = ip } } // WithIPv6 sets the specified ip6 for the specified network of the container -func WithIPv6(network, ip string) func(*TestContainerConfig) { +func WithIPv6(networkName, ip string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { if c.NetworkingConfig.EndpointsConfig == nil { - c.NetworkingConfig.EndpointsConfig = map[string]*networktypes.EndpointSettings{} + c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{} } - if v, ok := c.NetworkingConfig.EndpointsConfig[network]; !ok || v == nil { - c.NetworkingConfig.EndpointsConfig[network] = &networktypes.EndpointSettings{} + if v, ok := c.NetworkingConfig.EndpointsConfig[networkName]; !ok || v == nil { + c.NetworkingConfig.EndpointsConfig[networkName] = &network.EndpointSettings{} } - if c.NetworkingConfig.EndpointsConfig[network].IPAMConfig == nil { - c.NetworkingConfig.EndpointsConfig[network].IPAMConfig = &networktypes.EndpointIPAMConfig{} + if c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig == nil { + c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig = &network.EndpointIPAMConfig{} } - c.NetworkingConfig.EndpointsConfig[network].IPAMConfig.IPv6Address = ip + c.NetworkingConfig.EndpointsConfig[networkName].IPAMConfig.IPv6Address = ip } } @@ -162,7 +162,7 @@ func WithAutoRemove(c *TestContainerConfig) { func WithPidsLimit(limit *int64) func(*TestContainerConfig) { return func(c *TestContainerConfig) { if c.HostConfig == nil { - c.HostConfig = &containertypes.HostConfig{} + c.HostConfig = &container.HostConfig{} } c.HostConfig.PidsLimit = limit } @@ -186,7 +186,7 @@ func WithUser(user string) func(c *TestContainerConfig) { func WithPrivileged(privileged bool) func(*TestContainerConfig) { return func(c *TestContainerConfig) { if c.HostConfig == nil { - c.HostConfig = &containertypes.HostConfig{} + c.HostConfig = &container.HostConfig{} } c.HostConfig.Privileged = privileged } @@ -196,9 +196,9 @@ func WithPrivileged(privileged bool) func(*TestContainerConfig) { func WithCgroupnsMode(mode string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { if c.HostConfig == nil { - c.HostConfig = &containertypes.HostConfig{} + c.HostConfig = &container.HostConfig{} } - c.HostConfig.CgroupnsMode = containertypes.CgroupnsMode(mode) + c.HostConfig.CgroupnsMode = container.CgroupnsMode(mode) } } @@ -220,12 +220,12 @@ func WithPlatform(p *ocispec.Platform) func(*TestContainerConfig) { // WithWindowsDevice specifies a Windows Device, ala `--device` on the CLI func WithWindowsDevice(device string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { - c.HostConfig.Devices = append(c.HostConfig.Devices, containertypes.DeviceMapping{PathOnHost: device}) + c.HostConfig.Devices = append(c.HostConfig.Devices, container.DeviceMapping{PathOnHost: device}) } } // WithIsolation specifies the isolation technology to apply to the container -func WithIsolation(isolation containertypes.Isolation) func(*TestContainerConfig) { +func WithIsolation(isolation container.Isolation) func(*TestContainerConfig) { return func(c *TestContainerConfig) { c.HostConfig.Isolation = isolation } @@ -248,7 +248,7 @@ func WithRuntime(name string) func(*TestContainerConfig) { // WithCDIDevices sets the CDI devices to use to start the container func WithCDIDevices(cdiDeviceNames ...string) func(*TestContainerConfig) { return func(c *TestContainerConfig) { - request := containertypes.DeviceRequest{ + request := container.DeviceRequest{ Driver: "cdi", DeviceIDs: cdiDeviceNames, } From 17571ff1993f62c21b2e60350b2fe19f5f57566c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 11 Aug 2023 20:35:56 +0200 Subject: [PATCH 2/2] integration/internal/container: add WithPIDMode option Some files used aliases, others didn't, and they didn't appear to be required. Signed-off-by: Sebastiaan van Stijn --- integration/container/pidmode_linux_test.go | 6 ++---- integration/internal/container/ops.go | 7 +++++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/integration/container/pidmode_linux_test.go b/integration/container/pidmode_linux_test.go index 5d6dabfa4b..c760794283 100644 --- a/integration/container/pidmode_linux_test.go +++ b/integration/container/pidmode_linux_test.go @@ -12,7 +12,7 @@ import ( "gotest.tools/v3/skip" ) -func TestPidHost(t *testing.T) { +func TestPIDModeHost(t *testing.T) { skip.If(t, testEnv.DaemonInfo.OSType != "linux") skip.If(t, testEnv.IsRemoteDaemon()) @@ -23,9 +23,7 @@ func TestPidHost(t *testing.T) { apiClient := testEnv.APIClient() ctx := context.Background() - cID := container.Run(ctx, t, apiClient, func(c *container.TestContainerConfig) { - c.HostConfig.PidMode = "host" - }) + cID := container.Run(ctx, t, apiClient, container.WithPIDMode("host")) poll.WaitOn(t, container.IsInState(ctx, apiClient, cID, "running"), poll.WithDelay(100*time.Millisecond)) cPid := container.GetContainerNS(ctx, t, apiClient, cID, "pid") assert.Assert(t, hostPid == cPid) diff --git a/integration/internal/container/ops.go b/integration/internal/container/ops.go index ca443fe8af..0c1e6fb2d1 100644 --- a/integration/internal/container/ops.go +++ b/integration/internal/container/ops.go @@ -273,3 +273,10 @@ func WithSecurityOpt(opt string) func(*TestContainerConfig) { c.HostConfig.SecurityOpt = append(c.HostConfig.SecurityOpt, opt) } } + +// WithPIDMode sets the PID-mode for the container. +func WithPIDMode(mode container.PidMode) func(c *TestContainerConfig) { + return func(c *TestContainerConfig) { + c.HostConfig.PidMode = mode + } +}