Skip to content

Commit cd76e3e

Browse files
committed
api/types: move ExecConfig to api/types/container
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 3d2ee59 commit cd76e3e

16 files changed

Lines changed: 68 additions & 59 deletions

File tree

api/server/router/container/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
// execBackend includes functions to implement to provide exec functionality.
1616
type execBackend interface {
17-
ContainerExecCreate(name string, config *types.ExecConfig) (string, error)
17+
ContainerExecCreate(name string, options *container.ExecOptions) (string, error)
1818
ContainerExecInspect(id string) (*backend.ExecInspect, error)
1919
ContainerExecResize(name string, height, width int) error
2020
ContainerExecStart(ctx context.Context, name string, options container.ExecStartOptions) error

api/server/router/container/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (s *containerRouter) postContainerExecCreate(ctx context.Context, w http.Re
3838
return err
3939
}
4040

41-
execConfig := &types.ExecConfig{}
41+
execConfig := &container.ExecOptions{}
4242
if err := httputils.ReadJSON(r, execConfig); err != nil {
4343
return err
4444
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package types // import "github.com/docker/docker/api/types"
1+
package container
22

3-
// ExecConfig is a small subset of the Config struct that holds the configuration
3+
// ExecOptions is a small subset of the Config struct that holds the configuration
44
// for the exec feature of docker.
5-
type ExecConfig struct {
5+
type ExecOptions struct {
66
User string // User that will run the command
77
Privileged bool // Is the container in privileged mode
88
Tty bool // Attach standard streams to a tty.

api/types/types_deprecated.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package types
22

33
import (
4+
"github.com/docker/docker/api/types/container"
45
"github.com/docker/docker/api/types/network"
56
)
67

@@ -54,3 +55,9 @@ type NetworkResource = network.Inspect
5455
//
5556
// Deprecated: use [network.PruneReport].
5657
type NetworksPruneReport = network.PruneReport
58+
59+
// ExecConfig is a small subset of the Config struct that holds the configuration
60+
// for the exec feature of docker.
61+
//
62+
// Deprecated: use [container.ExecOptions].
63+
type ExecConfig = container.ExecOptions

client/container_exec.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"net/http"
77

88
"github.com/docker/docker/api/types"
9+
"github.com/docker/docker/api/types/container"
910
"github.com/docker/docker/api/types/versions"
1011
)
1112

1213
// ContainerExecCreate creates a new exec configuration to run an exec process.
13-
func (cli *Client) ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error) {
14+
func (cli *Client) ContainerExecCreate(ctx context.Context, container string, options container.ExecOptions) (types.IDResponse, error) {
1415
var response types.IDResponse
1516

1617
// Make sure we negotiated (if the client is configured to do so),
@@ -22,14 +23,14 @@ func (cli *Client) ContainerExecCreate(ctx context.Context, container string, co
2223
return response, err
2324
}
2425

25-
if err := cli.NewVersionError(ctx, "1.25", "env"); len(config.Env) != 0 && err != nil {
26+
if err := cli.NewVersionError(ctx, "1.25", "env"); len(options.Env) != 0 && err != nil {
2627
return response, err
2728
}
2829
if versions.LessThan(cli.ClientVersion(), "1.42") {
29-
config.ConsoleSize = nil
30+
options.ConsoleSize = nil
3031
}
3132

32-
resp, err := cli.post(ctx, "/containers/"+container+"/exec", nil, config, nil)
33+
resp, err := cli.post(ctx, "/containers/"+container+"/exec", nil, options, nil)
3334
defer ensureReaderClosed(resp)
3435
if err != nil {
3536
return response, err

client/container_exec_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"github.com/docker/docker/api/types"
14+
"github.com/docker/docker/api/types/container"
1415
"github.com/docker/docker/errdefs"
1516
"gotest.tools/v3/assert"
1617
is "gotest.tools/v3/assert/cmp"
@@ -20,7 +21,7 @@ func TestContainerExecCreateError(t *testing.T) {
2021
client := &Client{
2122
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
2223
}
23-
_, err := client.ContainerExecCreate(context.Background(), "container_id", types.ExecConfig{})
24+
_, err := client.ContainerExecCreate(context.Background(), "container_id", container.ExecOptions{})
2425
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
2526
}
2627

@@ -32,7 +33,7 @@ func TestContainerExecCreateConnectionError(t *testing.T) {
3233
client, err := NewClientWithOpts(WithAPIVersionNegotiation(), WithHost("tcp://no-such-host.invalid"))
3334
assert.NilError(t, err)
3435

35-
_, err = client.ContainerExecCreate(context.Background(), "", types.ExecConfig{})
36+
_, err = client.ContainerExecCreate(context.Background(), "", container.ExecOptions{})
3637
assert.Check(t, is.ErrorType(err, IsErrConnectionFailed))
3738
}
3839

@@ -50,7 +51,7 @@ func TestContainerExecCreate(t *testing.T) {
5051
if err := req.ParseForm(); err != nil {
5152
return nil, err
5253
}
53-
execConfig := &types.ExecConfig{}
54+
execConfig := &container.ExecOptions{}
5455
if err := json.NewDecoder(req.Body).Decode(execConfig); err != nil {
5556
return nil, err
5657
}
@@ -70,7 +71,7 @@ func TestContainerExecCreate(t *testing.T) {
7071
}),
7172
}
7273

73-
r, err := client.ContainerExecCreate(context.Background(), "container_id", types.ExecConfig{
74+
r, err := client.ContainerExecCreate(context.Background(), "container_id", container.ExecOptions{
7475
User: "user",
7576
})
7677
if err != nil {

client/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type ContainerAPIClient interface {
5151
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *ocispec.Platform, containerName string) (container.CreateResponse, error)
5252
ContainerDiff(ctx context.Context, container string) ([]container.FilesystemChange, error)
5353
ContainerExecAttach(ctx context.Context, execID string, config types.ExecStartCheck) (types.HijackedResponse, error)
54-
ContainerExecCreate(ctx context.Context, container string, config types.ExecConfig) (types.IDResponse, error)
54+
ContainerExecCreate(ctx context.Context, container string, options container.ExecOptions) (types.IDResponse, error)
5555
ContainerExecInspect(ctx context.Context, execID string) (types.ContainerExecInspect, error)
5656
ContainerExecResize(ctx context.Context, execID string, options container.ResizeOptions) error
5757
ContainerExecStart(ctx context.Context, execID string, config types.ExecStartCheck) error

daemon/exec.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/containerd/containerd"
1313
"github.com/containerd/log"
14-
"github.com/docker/docker/api/types"
1514
containertypes "github.com/docker/docker/api/types/container"
1615
"github.com/docker/docker/api/types/events"
1716
"github.com/docker/docker/api/types/strslice"
@@ -94,42 +93,42 @@ func (daemon *Daemon) getActiveContainer(name string) (*container.Container, err
9493
}
9594

9695
// ContainerExecCreate sets up an exec in a running container.
97-
func (daemon *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (string, error) {
96+
func (daemon *Daemon) ContainerExecCreate(name string, options *containertypes.ExecOptions) (string, error) {
9897
cntr, err := daemon.getActiveContainer(name)
9998
if err != nil {
10099
return "", err
101100
}
102101

103-
cmd := strslice.StrSlice(config.Cmd)
102+
cmd := strslice.StrSlice(options.Cmd)
104103
entrypoint, args := daemon.getEntrypointAndArgs(strslice.StrSlice{}, cmd)
105104

106105
keys := []byte{}
107-
if config.DetachKeys != "" {
108-
keys, err = term.ToBytes(config.DetachKeys)
106+
if options.DetachKeys != "" {
107+
keys, err = term.ToBytes(options.DetachKeys)
109108
if err != nil {
110-
err = fmt.Errorf("Invalid escape keys (%s) provided", config.DetachKeys)
109+
err = fmt.Errorf("Invalid escape keys (%s) provided", options.DetachKeys)
111110
return "", err
112111
}
113112
}
114113

115114
execConfig := container.NewExecConfig(cntr)
116-
execConfig.OpenStdin = config.AttachStdin
117-
execConfig.OpenStdout = config.AttachStdout
118-
execConfig.OpenStderr = config.AttachStderr
115+
execConfig.OpenStdin = options.AttachStdin
116+
execConfig.OpenStdout = options.AttachStdout
117+
execConfig.OpenStderr = options.AttachStderr
119118
execConfig.DetachKeys = keys
120119
execConfig.Entrypoint = entrypoint
121120
execConfig.Args = args
122-
execConfig.Tty = config.Tty
123-
execConfig.ConsoleSize = config.ConsoleSize
124-
execConfig.Privileged = config.Privileged
125-
execConfig.User = config.User
126-
execConfig.WorkingDir = config.WorkingDir
121+
execConfig.Tty = options.Tty
122+
execConfig.ConsoleSize = options.ConsoleSize
123+
execConfig.Privileged = options.Privileged
124+
execConfig.User = options.User
125+
execConfig.WorkingDir = options.WorkingDir
127126

128127
linkedEnv, err := daemon.setupLinkedContainers(cntr)
129128
if err != nil {
130129
return "", err
131130
}
132-
execConfig.Env = container.ReplaceOrAppendEnvValues(cntr.CreateDaemonEnvironment(config.Tty, linkedEnv), config.Env)
131+
execConfig.Env = container.ReplaceOrAppendEnvValues(cntr.CreateDaemonEnvironment(options.Tty, linkedEnv), options.Env)
133132
if len(execConfig.User) == 0 {
134133
execConfig.User = cntr.Config.User
135134
}

integration-cli/docker_api_exec_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"testing"
1313
"time"
1414

15-
"github.com/docker/docker/api/types"
15+
"github.com/docker/docker/api/types/container"
1616
"github.com/docker/docker/client"
1717
"github.com/docker/docker/integration-cli/checker"
1818
"github.com/docker/docker/integration-cli/cli"
@@ -65,10 +65,9 @@ func (s *DockerAPISuite) TestExecAPICreateContainerPaused(c *testing.T) {
6565
assert.NilError(c, err)
6666
defer apiClient.Close()
6767

68-
config := types.ExecConfig{
68+
_, err = apiClient.ContainerExecCreate(testutil.GetContext(c), name, container.ExecOptions{
6969
Cmd: []string{"true"},
70-
}
71-
_, err = apiClient.ContainerExecCreate(testutil.GetContext(c), name, config)
70+
})
7271
assert.ErrorContains(c, err, "Container "+name+" is paused, unpause the container before exec", "Expected message when creating exec command with Container %s is paused", name)
7372
}
7473

@@ -126,16 +125,14 @@ func (s *DockerAPISuite) TestExecAPIStartWithDetach(c *testing.T) {
126125

127126
ctx := testutil.GetContext(c)
128127

129-
config := types.ExecConfig{
130-
Cmd: []string{"true"},
131-
AttachStderr: true,
132-
}
133-
134128
apiClient, err := client.NewClientWithOpts(client.FromEnv)
135129
assert.NilError(c, err)
136130
defer apiClient.Close()
137131

138-
createResp, err := apiClient.ContainerExecCreate(ctx, name, config)
132+
createResp, err := apiClient.ContainerExecCreate(ctx, name, container.ExecOptions{
133+
Cmd: []string{"true"},
134+
AttachStderr: true,
135+
})
139136
assert.NilError(c, err)
140137

141138
_, body, err := request.Post(ctx, fmt.Sprintf("/exec/%s/start", createResp.ID), request.RawString(`{"Detach": true}`), request.JSON)

integration/config/config_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010

1111
"github.com/docker/docker/api/types"
12+
"github.com/docker/docker/api/types/container"
1213
"github.com/docker/docker/api/types/filters"
1314
swarmtypes "github.com/docker/docker/api/types/swarm"
1415
"github.com/docker/docker/client"
@@ -313,7 +314,7 @@ func TestTemplatedConfig(t *testing.T) {
313314
tasks := swarm.GetRunningTasks(ctx, t, c, serviceID)
314315
assert.Assert(t, len(tasks) > 0, "no running tasks found for service %s", serviceID)
315316

316-
attach := swarm.ExecTask(ctx, t, d, tasks[0], types.ExecConfig{
317+
attach := swarm.ExecTask(ctx, t, d, tasks[0], container.ExecOptions{
317318
Cmd: []string{"/bin/cat", "/templated_config"},
318319
AttachStdout: true,
319320
AttachStderr: true,
@@ -324,7 +325,7 @@ func TestTemplatedConfig(t *testing.T) {
324325
"this is a config\n"
325326
assertAttachedStream(t, attach, expect)
326327

327-
attach = swarm.ExecTask(ctx, t, d, tasks[0], types.ExecConfig{
328+
attach = swarm.ExecTask(ctx, t, d, tasks[0], container.ExecOptions{
328329
Cmd: []string{"mount"},
329330
AttachStdout: true,
330331
AttachStderr: true,

0 commit comments

Comments
 (0)