api/types: move ContainerStartOptions to api/types/container

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-25 23:44:29 +02:00
parent 0f77875220
commit 7bce33eb0f
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
23 changed files with 60 additions and 64 deletions

View file

@ -43,12 +43,6 @@ type ContainerLogsOptions struct {
Details bool
}
// ContainerStartOptions holds parameters to start containers.
type ContainerStartOptions struct {
CheckpointID string
CheckpointDir string
}
// CopyToContainerOptions holds information
// about files to copy into a container
type CopyToContainerOptions struct {

View file

@ -34,3 +34,9 @@ type RemoveOptions struct {
RemoveLinks bool
Force bool
}
// StartOptions holds parameters to start containers.
type StartOptions struct {
CheckpointID string
CheckpointDir string
}

View file

@ -92,6 +92,11 @@ type ServiceCreateResponse = swarm.ServiceCreateResponse
// Deprecated: use [swarm.ServiceUpdateResponse].
type ServiceUpdateResponse = swarm.ServiceUpdateResponse
// ContainerStartOptions holds parameters to start containers.
//
// Deprecated: use [container.StartOptions].
type ContainerStartOptions = container.StartOptions
// ResizeOptions holds parameters to resize a TTY.
// It can be used to resize container TTYs and
// exec process TTYs too.

View file

@ -4,11 +4,11 @@ import (
"context"
"net/url"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
)
// ContainerStart sends a request to the docker daemon to start a container.
func (cli *Client) ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error {
func (cli *Client) ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error {
query := url.Values{}
if len(options.CheckpointID) != 0 {
query.Set("checkpoint", options.CheckpointID)

View file

@ -10,7 +10,7 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
@ -20,7 +20,7 @@ func TestContainerStartError(t *testing.T) {
client := &Client{
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
err := client.ContainerStart(context.Background(), "nothing", types.ContainerStartOptions{})
err := client.ContainerStart(context.Background(), "nothing", container.StartOptions{})
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
}
@ -51,7 +51,7 @@ func TestContainerStart(t *testing.T) {
}),
}
err := client.ContainerStart(context.Background(), "container_id", types.ContainerStartOptions{CheckpointID: "checkpoint_id"})
err := client.ContainerStart(context.Background(), "container_id", container.StartOptions{CheckpointID: "checkpoint_id"})
if err != nil {
t.Fatal(err)
}

View file

@ -69,7 +69,7 @@ type ContainerAPIClient interface {
ContainerStatPath(ctx context.Context, container, path string) (types.ContainerPathStat, error)
ContainerStats(ctx context.Context, container string, stream bool) (types.ContainerStats, error)
ContainerStatsOneShot(ctx context.Context, container string) (types.ContainerStats, error)
ContainerStart(ctx context.Context, container string, options types.ContainerStartOptions) error
ContainerStart(ctx context.Context, container string, options container.StartOptions) error
ContainerStop(ctx context.Context, container string, options container.StopOptions) error
ContainerTop(ctx context.Context, container string, arguments []string) (container.ContainerTopOKBody, error)
ContainerUnpause(ctx context.Context, container string) error

View file

@ -924,12 +924,12 @@ func (s *DockerAPISuite) TestContainerAPIStart(c *testing.T) {
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, name)
assert.NilError(c, err)
err = apiClient.ContainerStart(testutil.GetContext(c), name, types.ContainerStartOptions{})
err = apiClient.ContainerStart(testutil.GetContext(c), name, container.StartOptions{})
assert.NilError(c, err)
// second call to start should give 304
// maybe add ContainerStartWithRaw to test it
err = apiClient.ContainerStart(testutil.GetContext(c), name, types.ContainerStartOptions{})
err = apiClient.ContainerStart(testutil.GetContext(c), name, container.StartOptions{})
assert.NilError(c, err)
// TODO(tibor): figure out why this doesn't work on windows
@ -1572,7 +1572,7 @@ func (s *DockerAPISuite) TestContainerAPIStatsWithNetworkDisabled(c *testing.T)
_, err = apiClient.ContainerCreate(testutil.GetContext(c), &config, &container.HostConfig{}, &network.NetworkingConfig{}, nil, name)
assert.NilError(c, err)
err = apiClient.ContainerStart(testutil.GetContext(c), name, types.ContainerStartOptions{})
err = apiClient.ContainerStart(testutil.GetContext(c), name, container.StartOptions{})
assert.NilError(c, err)
assert.Assert(c, waitRun(name) == nil)
@ -2112,7 +2112,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
assert.Check(c, is.Equal(x.expected.Mode, mountPoint.Mode))
assert.Check(c, is.Equal(x.expected.Destination, mountPoint.Destination))
err = apiclient.ContainerStart(ctx, ctr.ID, types.ContainerStartOptions{})
err = apiclient.ContainerStart(ctx, ctr.ID, container.StartOptions{})
assert.NilError(c, err)
poll.WaitOn(c, containerExit(ctx, apiclient, ctr.ID), poll.WithDelay(time.Second))

View file

@ -10,7 +10,6 @@ import (
"testing"
winio "github.com/Microsoft/go-winio"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/testutil"
@ -66,7 +65,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsBindNamedPipe(c *testing.T
nil, nil, name)
assert.NilError(c, err)
err = client.ContainerStart(ctx, name, types.ContainerStartOptions{})
err = client.ContainerStart(ctx, name, container.StartOptions{})
assert.NilError(c, err)
err = <-ch

View file

@ -8,8 +8,8 @@ import (
"testing"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/checkpoint"
containertypes "github.com/docker/docker/api/types/container"
mounttypes "github.com/docker/docker/api/types/mount"
"github.com/docker/docker/client"
"github.com/docker/docker/integration/internal/container"
@ -128,7 +128,7 @@ func TestCheckpoint(t *testing.T) {
// Restore the container from a second checkpoint.
t.Log("Restore the container")
err = apiClient.ContainerStart(ctx, cID, types.ContainerStartOptions{
err = apiClient.ContainerStart(ctx, cID, containertypes.StartOptions{
CheckpointID: "test2",
})
assert.NilError(t, err)

View file

@ -8,9 +8,7 @@ import (
"testing"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
@ -253,7 +251,7 @@ func TestCreateWithCustomMaskedPaths(t *testing.T) {
checkInspect(t, ctx, name, tc.expected)
// Start the container.
err = apiClient.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, c.ID, container.StartOptions{})
assert.NilError(t, err)
poll.WaitOn(t, ctr.IsInState(ctx, apiClient, c.ID, "exited"), poll.WithDelay(100*time.Millisecond))
@ -331,7 +329,7 @@ func TestCreateWithCustomReadonlyPaths(t *testing.T) {
checkInspect(t, ctx, name, tc.expected)
// Start the container.
err = apiClient.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, c.ID, container.StartOptions{})
assert.NilError(t, err)
poll.WaitOn(t, ctr.IsInState(ctx, apiClient, c.ID, "exited"), poll.WithDelay(100*time.Millisecond))
@ -436,7 +434,7 @@ func TestCreateTmpfsOverrideAnonymousVolume(t *testing.T) {
)
defer func() {
err := apiClient.ContainerRemove(ctx, id, containertypes.RemoveOptions{Force: true})
err := apiClient.ContainerRemove(ctx, id, container.RemoveOptions{Force: true})
assert.NilError(t, err)
}()
@ -447,7 +445,7 @@ func TestCreateTmpfsOverrideAnonymousVolume(t *testing.T) {
assert.Assert(t, is.Len(inspect.Mounts, 0))
chWait, chErr := apiClient.ContainerWait(ctx, id, container.WaitConditionNextExit)
assert.NilError(t, apiClient.ContainerStart(ctx, id, types.ContainerStartOptions{}))
assert.NilError(t, apiClient.ContainerStart(ctx, id, container.StartOptions{}))
timeout := time.NewTimer(30 * time.Second)
defer timeout.Stop()
@ -483,7 +481,7 @@ func TestCreateDifferentPlatform(t *testing.T) {
Architecture: img.Architecture,
Variant: img.Variant,
}
_, err := apiClient.ContainerCreate(ctx, &containertypes.Config{Image: "busybox:latest"}, &containertypes.HostConfig{}, nil, &p, "")
_, err := apiClient.ContainerCreate(ctx, &container.Config{Image: "busybox:latest"}, &container.HostConfig{}, nil, &p, "")
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
})
t.Run("different cpu arch", func(t *testing.T) {
@ -493,7 +491,7 @@ func TestCreateDifferentPlatform(t *testing.T) {
Architecture: img.Architecture + "DifferentArch",
Variant: img.Variant,
}
_, err := apiClient.ContainerCreate(ctx, &containertypes.Config{Image: "busybox:latest"}, &containertypes.HostConfig{}, nil, &p, "")
_, err := apiClient.ContainerCreate(ctx, &container.Config{Image: "busybox:latest"}, &container.HostConfig{}, nil, &p, "")
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
})
}
@ -541,32 +539,32 @@ func TestCreateInvalidHostConfig(t *testing.T) {
testCases := []struct {
doc string
hc containertypes.HostConfig
hc container.HostConfig
expectedErr string
}{
{
doc: "invalid IpcMode",
hc: containertypes.HostConfig{IpcMode: "invalid"},
hc: container.HostConfig{IpcMode: "invalid"},
expectedErr: "Error response from daemon: invalid IPC mode: invalid",
},
{
doc: "invalid PidMode",
hc: containertypes.HostConfig{PidMode: "invalid"},
hc: container.HostConfig{PidMode: "invalid"},
expectedErr: "Error response from daemon: invalid PID mode: invalid",
},
{
doc: "invalid PidMode without container ID",
hc: containertypes.HostConfig{PidMode: "container"},
hc: container.HostConfig{PidMode: "container"},
expectedErr: "Error response from daemon: invalid PID mode: container",
},
{
doc: "invalid UTSMode",
hc: containertypes.HostConfig{UTSMode: "invalid"},
hc: container.HostConfig{UTSMode: "invalid"},
expectedErr: "Error response from daemon: invalid UTS mode: invalid",
},
{
doc: "invalid Annotations",
hc: containertypes.HostConfig{Annotations: map[string]string{"": "a"}},
hc: container.HostConfig{Annotations: map[string]string{"": "a"}},
expectedErr: "Error response from daemon: invalid Annotations: the empty string is not permitted as an annotation key",
},
}

View file

@ -49,7 +49,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
cID := container.Create(ctx, t, c)
defer c.ContainerRemove(ctx, cID, containertypes.RemoveOptions{Force: true})
err := c.ContainerStart(ctx, cID, types.ContainerStartOptions{})
err := c.ContainerStart(ctx, cID, containertypes.StartOptions{})
assert.Check(t, err, "error starting test container")
inspect, err := c.ContainerInspect(ctx, cID)
@ -68,7 +68,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) {
d.Start(t, "--iptables=false")
err = c.ContainerStart(ctx, cID, types.ContainerStartOptions{})
err = c.ContainerStart(ctx, cID, containertypes.StartOptions{})
assert.Check(t, err, "failed to start test container")
}

View file

@ -4,7 +4,6 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/testutil"
@ -100,7 +99,7 @@ func TestWindowsDevices(t *testing.T) {
// remove this skip.If and validate the expected behaviour under Hyper-V.
skip.If(t, d.isolation == containertypes.IsolationHyperV && !d.expectedStartFailure, "FIXME. HyperV isolation setup is probably incorrect in the test")
err := apiClient.ContainerStart(ctx, id, types.ContainerStartOptions{})
err := apiClient.ContainerStart(ctx, id, containertypes.StartOptions{})
if d.expectedStartFailure {
assert.ErrorContains(t, err, d.expectedStartFailureMessage)
return

View file

@ -7,7 +7,6 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
@ -68,7 +67,7 @@ func testIpcNonePrivateShareable(t *testing.T, mode string, mustBeMounted bool,
assert.NilError(t, err)
assert.Check(t, is.Equal(len(resp.Warnings), 0))
err = apiClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, resp.ID, containertypes.StartOptions{})
assert.NilError(t, err)
// get major:minor pair for /dev/shm from container's /proc/self/mountinfo
@ -140,7 +139,7 @@ func testIpcContainer(t *testing.T, donorMode string, mustWork bool) {
assert.Check(t, is.Equal(len(resp.Warnings), 0))
name1 := resp.ID
err = apiClient.ContainerStart(ctx, name1, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, name1, containertypes.StartOptions{})
assert.NilError(t, err)
// create and start the second container
@ -150,7 +149,7 @@ func testIpcContainer(t *testing.T, donorMode string, mustWork bool) {
assert.Check(t, is.Equal(len(resp.Warnings), 0))
name2 := resp.ID
err = apiClient.ContainerStart(ctx, name2, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, name2, containertypes.StartOptions{})
if !mustWork {
// start should fail with a specific error
assert.Check(t, is.ErrorContains(err, "non-shareable IPC"))
@ -206,7 +205,7 @@ func TestAPIIpcModeHost(t *testing.T) {
assert.Check(t, is.Equal(len(resp.Warnings), 0))
name := resp.ID
err = apiClient.ContainerStart(ctx, name, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, name, containertypes.StartOptions{})
assert.NilError(t, err)
// check that IPC is shared
@ -241,7 +240,7 @@ func testDaemonIpcPrivateShareable(t *testing.T, mustBeShared bool, arg ...strin
assert.NilError(t, err)
assert.Check(t, is.Equal(len(resp.Warnings), 0))
err = c.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
err = c.ContainerStart(ctx, resp.ID, containertypes.StartOptions{})
assert.NilError(t, err)
// get major:minor pair for /dev/shm from container's /proc/self/mountinfo

View file

@ -8,7 +8,6 @@ import (
"testing"
"time"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
mounttypes "github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/network"
@ -67,7 +66,7 @@ func TestContainerNetworkMountsNoChown(t *testing.T) {
ctrCreate, err := cli.ContainerCreate(ctx, &config, &hostConfig, &network.NetworkingConfig{}, nil, "")
assert.NilError(t, err)
// container will exit immediately because of no tty, but we only need the start sequence to test the condition
err = cli.ContainerStart(ctx, ctrCreate.ID, types.ContainerStartOptions{})
err = cli.ContainerStart(ctx, ctrCreate.ID, containertypes.StartOptions{})
assert.NilError(t, err)
// Check that host-located bind mount network file did not change ownership when the container was started

View file

@ -4,7 +4,7 @@ import (
"os"
"testing"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/integration/internal/container"
"gotest.tools/v3/assert"
@ -50,7 +50,7 @@ func TestPIDModeContainer(t *testing.T) {
ctr, err := container.CreateFromConfig(ctx, apiClient, container.NewTestConfig(container.WithPIDMode("container:"+pidCtrName)))
assert.NilError(t, err, "should not produce an error when creating, only when starting")
err = apiClient.ContainerStart(ctx, ctr.ID, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, ctr.ID, containertypes.StartOptions{})
assert.Check(t, is.ErrorType(err, errdefs.IsSystem), "should produce a System error when starting an existing container from an invalid state")
assert.Check(t, is.ErrorContains(err, "failed to join PID namespace"))
assert.Check(t, is.ErrorContains(err, cPIDContainerID+" is not running"))
@ -63,7 +63,7 @@ func TestPIDModeContainer(t *testing.T) {
ctr, err := container.CreateFromConfig(ctx, apiClient, container.NewTestConfig(container.WithPIDMode("container:"+pidCtrName)))
assert.NilError(t, err)
err = apiClient.ContainerStart(ctx, ctr.ID, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, ctr.ID, containertypes.StartOptions{})
assert.Check(t, err)
})
}

View file

@ -135,7 +135,7 @@ func TestRenameAnonymousContainer(t *testing.T) {
// FIXME(vdemeester) this is a really weird behavior as it fails otherwise
err = apiClient.ContainerStop(ctx, container1Name, containertypes.StopOptions{})
assert.NilError(t, err)
err = apiClient.ContainerStart(ctx, container1Name, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, container1Name, containertypes.StartOptions{})
assert.NilError(t, err)
count := "-c"

View file

@ -6,7 +6,6 @@ import (
"testing"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
testContainer "github.com/docker/docker/integration/internal/container"
@ -105,7 +104,7 @@ func TestDaemonRestartKillContainers(t *testing.T) {
defer apiClient.ContainerRemove(ctx, resp.ID, container.RemoveOptions{Force: true})
if tc.xStart {
err = apiClient.ContainerStart(ctx, resp.ID, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, resp.ID, container.StartOptions{})
assert.NilError(t, err)
}

View file

@ -4,7 +4,6 @@ import (
"testing"
"time"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/testutil"
@ -149,7 +148,7 @@ func TestWaitConditions(t *testing.T) {
assert.NilError(t, err)
defer streams.Close()
assert.NilError(t, cli.ContainerStart(ctx, containerID, types.ContainerStartOptions{}))
assert.NilError(t, cli.ContainerStart(ctx, containerID, containertypes.StartOptions{}))
waitResC, errC := cli.ContainerWait(ctx, containerID, tc.waitCond)
select {
case err := <-errC:

View file

@ -77,7 +77,7 @@ func Run(ctx context.Context, t *testing.T, apiClient client.APIClient, ops ...f
t.Helper()
id := Create(ctx, t, apiClient, ops...)
err := apiClient.ContainerStart(ctx, id, types.ContainerStartOptions{})
err := apiClient.ContainerStart(ctx, id, container.StartOptions{})
assert.NilError(t, err)
return id
@ -106,7 +106,7 @@ func RunAttach(ctx context.Context, t *testing.T, apiClient client.APIClient, op
})
assert.NilError(t, err)
err = apiClient.ContainerStart(ctx, id, types.ContainerStartOptions{})
err = apiClient.ContainerStart(ctx, id, container.StartOptions{})
assert.NilError(t, err)
s, err := demultiplexStreams(ctx, aresp)

View file

@ -62,7 +62,7 @@ func TestReadPluginNoRead(t *testing.T) {
assert.Assert(t, err)
defer client.ContainerRemove(ctx, c.ID, container.RemoveOptions{Force: true})
err = client.ContainerStart(ctx, c.ID, types.ContainerStartOptions{})
err = client.ContainerStart(ctx, c.ID, container.StartOptions{})
assert.Assert(t, err)
logs, err := client.ContainerLogs(ctx, c.ID, types.ContainerLogsOptions{ShowStdout: true})

View file

@ -3,7 +3,7 @@ package service // import "github.com/docker/docker/integration/service"
import (
"testing"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/integration/internal/container"
net "github.com/docker/docker/integration/internal/network"
@ -43,7 +43,7 @@ func TestDockerNetworkConnectAlias(t *testing.T) {
})
assert.NilError(t, err)
err = client.ContainerStart(ctx, cID1, types.ContainerStartOptions{})
err = client.ContainerStart(ctx, cID1, containertypes.StartOptions{})
assert.NilError(t, err)
ng1, err := client.ContainerInspect(ctx, cID1)
@ -66,7 +66,7 @@ func TestDockerNetworkConnectAlias(t *testing.T) {
})
assert.NilError(t, err)
err = client.ContainerStart(ctx, cID2, types.ContainerStartOptions{})
err = client.ContainerStart(ctx, cID2, containertypes.StartOptions{})
assert.NilError(t, err)
ng2, err := client.ContainerInspect(ctx, cID2)
@ -101,7 +101,7 @@ func TestDockerNetworkReConnect(t *testing.T) {
err := client.NetworkConnect(ctx, name, c1, &network.EndpointSettings{})
assert.NilError(t, err)
err = client.ContainerStart(ctx, c1, types.ContainerStartOptions{})
err = client.ContainerStart(ctx, c1, containertypes.StartOptions{})
assert.NilError(t, err)
n1, err := client.ContainerInspect(ctx, c1)

View file

@ -4,7 +4,6 @@ import (
"os"
"testing"
"github.com/docker/docker/api/types"
containertypes "github.com/docker/docker/api/types/container"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/testutil"
@ -48,7 +47,7 @@ func TestCgroupDriverSystemdMemoryLimit(t *testing.T) {
})
defer c.ContainerRemove(ctx, ctrID, containertypes.RemoveOptions{Force: true})
err := c.ContainerStart(ctx, ctrID, types.ContainerStartOptions{})
err := c.ContainerStart(ctx, ctrID, containertypes.StartOptions{})
assert.NilError(t, err)
s, err := c.ContainerInspect(ctx, ctrID)

View file

@ -157,7 +157,7 @@ COPY . /static`); err != nil {
Image: image,
}, &containertypes.HostConfig{}, nil, nil, container)
assert.NilError(t, err)
err = c.ContainerStart(context.Background(), b.ID, types.ContainerStartOptions{})
err = c.ContainerStart(context.Background(), b.ID, containertypes.StartOptions{})
assert.NilError(t, err)
// Find out the system assigned port