Skip to content

Commit f4dd029

Browse files
committed
WIP
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent e80ccf2 commit f4dd029

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+607
-507
lines changed

cli/command/cli.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/docker/cli/cli/version"
2626
dopts "github.com/docker/cli/opts"
2727
"github.com/moby/moby/api/types/build"
28-
"github.com/moby/moby/api/types/swarm"
2928
"github.com/moby/moby/client"
3029
"github.com/spf13/cobra"
3130
)
@@ -378,7 +377,7 @@ func (cli *DockerCli) initializeFromClient() {
378377
ctx, cancel := context.WithTimeout(cli.baseCtx, cli.getInitTimeout())
379378
defer cancel()
380379

381-
ping, err := cli.client.Ping(ctx)
380+
ping, err := cli.client.Ping(ctx, client.PingOptions{})
382381
if err != nil {
383382
// Default to true if we fail to connect to daemon
384383
cli.serverInfo = ServerInfo{HasExperimental: true}
@@ -564,7 +563,7 @@ type ServerInfo struct {
564563
// in the ping response, or if an error occurred, in which case the client
565564
// should use other ways to get the current swarm status, such as the /swarm
566565
// endpoint.
567-
SwarmStatus *swarm.Status
566+
SwarmStatus *client.SwarmStatus
568567
}
569568

570569
// NewDockerCli returns a DockerCli instance with all operators applied on it.

cli/command/completion/functions.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ func ImageNames(dockerCLI APIClientProvider, limit int) cobra.CompletionFunc {
2727
if limit > 0 && len(args) >= limit {
2828
return nil, cobra.ShellCompDirectiveNoFileComp
2929
}
30-
list, err := dockerCLI.Client().ImageList(cmd.Context(), client.ImageListOptions{})
30+
res, err := dockerCLI.Client().ImageList(cmd.Context(), client.ImageListOptions{})
3131
if err != nil {
3232
return nil, cobra.ShellCompDirectiveError
3333
}
3434
var names []string
35-
for _, img := range list {
35+
for _, img := range res.Items {
3636
names = append(names, img.RepoTags...)
3737
}
3838
return names, cobra.ShellCompDirectiveNoFileComp
@@ -47,13 +47,13 @@ func ImageNamesWithBase(dockerCLI APIClientProvider, limit int) cobra.Completion
4747
if limit > 0 && len(args) >= limit {
4848
return nil, cobra.ShellCompDirectiveNoFileComp
4949
}
50-
list, err := dockerCLI.Client().ImageList(cmd.Context(), client.ImageListOptions{})
50+
res, err := dockerCLI.Client().ImageList(cmd.Context(), client.ImageListOptions{})
5151
if err != nil {
5252
return nil, cobra.ShellCompDirectiveError
5353
}
5454
var names []string
5555
baseNameCounts := make(map[string]int)
56-
for _, img := range list {
56+
for _, img := range res.Items {
5757
names = append(names, img.RepoTags...)
5858
for _, tag := range img.RepoTags {
5959
ref, err := reference.ParseNormalizedNamed(tag)
@@ -110,12 +110,12 @@ func ContainerNames(dockerCLI APIClientProvider, all bool, filters ...func(conta
110110
// VolumeNames offers completion for volumes
111111
func VolumeNames(dockerCLI APIClientProvider) cobra.CompletionFunc {
112112
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
113-
list, err := dockerCLI.Client().VolumeList(cmd.Context(), client.VolumeListOptions{})
113+
res, err := dockerCLI.Client().VolumeList(cmd.Context(), client.VolumeListOptions{})
114114
if err != nil {
115115
return nil, cobra.ShellCompDirectiveError
116116
}
117117
var names []string
118-
for _, vol := range list.Volumes {
118+
for _, vol := range res.Items.Volumes {
119119
names = append(names, vol.Name)
120120
}
121121
return names, cobra.ShellCompDirectiveNoFileComp
@@ -125,12 +125,12 @@ func VolumeNames(dockerCLI APIClientProvider) cobra.CompletionFunc {
125125
// NetworkNames offers completion for networks
126126
func NetworkNames(dockerCLI APIClientProvider) cobra.CompletionFunc {
127127
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
128-
list, err := dockerCLI.Client().NetworkList(cmd.Context(), client.NetworkListOptions{})
128+
res, err := dockerCLI.Client().NetworkList(cmd.Context(), client.NetworkListOptions{})
129129
if err != nil {
130130
return nil, cobra.ShellCompDirectiveError
131131
}
132132
var names []string
133-
for _, nw := range list {
133+
for _, nw := range res.Items {
134134
names = append(names, nw.Name)
135135
}
136136
return names, cobra.ShellCompDirectiveNoFileComp

cli/command/config/client_test.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,41 @@ package config
33
import (
44
"context"
55

6-
"github.com/moby/moby/api/types/swarm"
76
"github.com/moby/moby/client"
87
)
98

109
type fakeClient struct {
1110
client.Client
12-
configCreateFunc func(context.Context, swarm.ConfigSpec) (swarm.ConfigCreateResponse, error)
13-
configInspectFunc func(context.Context, string) (swarm.Config, []byte, error)
14-
configListFunc func(context.Context, client.ConfigListOptions) ([]swarm.Config, error)
15-
configRemoveFunc func(string) error
11+
configCreateFunc func(context.Context, client.ConfigCreateOptions) (client.ConfigCreateResult, error)
12+
configInspectFunc func(context.Context, string, client.ConfigInspectOptions) (client.ConfigInspectResult, error)
13+
configListFunc func(context.Context, client.ConfigListOptions) (client.ConfigListResult, error)
14+
configRemoveFunc func(context.Context, string, client.ConfigRemoveOptions) (client.ConfigRemoveResult, error)
1615
}
1716

18-
func (c *fakeClient) ConfigCreate(ctx context.Context, spec swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) {
17+
func (c *fakeClient) ConfigCreate(ctx context.Context, options client.ConfigCreateOptions) (client.ConfigCreateResult, error) {
1918
if c.configCreateFunc != nil {
20-
return c.configCreateFunc(ctx, spec)
19+
return c.configCreateFunc(ctx, options)
2120
}
22-
return swarm.ConfigCreateResponse{}, nil
21+
return client.ConfigCreateResult{}, nil
2322
}
2423

25-
func (c *fakeClient) ConfigInspectWithRaw(ctx context.Context, id string) (swarm.Config, []byte, error) {
24+
func (c *fakeClient) ConfigInspect(ctx context.Context, id string, options client.ConfigInspectOptions) (client.ConfigInspectResult, error) {
2625
if c.configInspectFunc != nil {
27-
return c.configInspectFunc(ctx, id)
26+
return c.configInspectFunc(ctx, id, options)
2827
}
29-
return swarm.Config{}, nil, nil
28+
return client.ConfigInspectResult{}, nil
3029
}
3130

32-
func (c *fakeClient) ConfigList(ctx context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
31+
func (c *fakeClient) ConfigList(ctx context.Context, options client.ConfigListOptions) (client.ConfigListResult, error) {
3332
if c.configListFunc != nil {
3433
return c.configListFunc(ctx, options)
3534
}
36-
return []swarm.Config{}, nil
35+
return client.ConfigListResult{}, nil
3736
}
3837

39-
func (c *fakeClient) ConfigRemove(_ context.Context, name string) error {
38+
func (c *fakeClient) ConfigRemove(ctx context.Context, name string, options client.ConfigRemoveOptions) (client.ConfigRemoveResult, error) {
4039
if c.configRemoveFunc != nil {
41-
return c.configRemoveFunc(name)
40+
return c.configRemoveFunc(ctx, name, options)
4241
}
43-
return nil
42+
return client.ConfigRemoveResult{}, nil
4443
}

cli/command/config/cmd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ func newConfigCommand(dockerCLI command.Cli) *cobra.Command {
3838
// completeNames offers completion for swarm configs
3939
func completeNames(dockerCLI completion.APIClientProvider) cobra.CompletionFunc {
4040
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
41-
list, err := dockerCLI.Client().ConfigList(cmd.Context(), client.ConfigListOptions{})
41+
res, err := dockerCLI.Client().ConfigList(cmd.Context(), client.ConfigListOptions{})
4242
if err != nil {
4343
return nil, cobra.ShellCompDirectiveError
4444
}
4545
var names []string
46-
for _, config := range list {
46+
for _, config := range res.Items {
4747
names = append(names, config.ID)
4848
}
4949
return names, cobra.ShellCompDirectiveNoFileComp

cli/command/config/create.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/docker/cli/cli/command"
1111
"github.com/docker/cli/opts"
1212
"github.com/moby/moby/api/types/swarm"
13+
"github.com/moby/moby/client"
1314
"github.com/moby/sys/sequential"
1415
"github.com/spf13/cobra"
1516
)
@@ -84,7 +85,9 @@ func runCreate(ctx context.Context, dockerCLI command.Cli, options createOptions
8485
Name: options.templateDriver,
8586
}
8687
}
87-
r, err := apiClient.ConfigCreate(ctx, spec)
88+
r, err := apiClient.ConfigCreate(ctx, client.ConfigCreateOptions{
89+
Spec: spec,
90+
})
8891
if err != nil {
8992
return err
9093
}

cli/command/config/create_test.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/docker/cli/internal/test"
1515
"github.com/moby/moby/api/types/swarm"
16+
"github.com/moby/moby/client"
1617
"gotest.tools/v3/assert"
1718
is "gotest.tools/v3/assert/cmp"
1819
"gotest.tools/v3/golden"
@@ -23,7 +24,7 @@ const configDataFile = "config-create-with-name.golden"
2324
func TestConfigCreateErrors(t *testing.T) {
2425
testCases := []struct {
2526
args []string
26-
configCreateFunc func(context.Context, swarm.ConfigSpec) (swarm.ConfigCreateResponse, error)
27+
configCreateFunc func(context.Context, client.ConfigCreateOptions) (client.ConfigCreateResult, error)
2728
expectedError string
2829
}{
2930
{
@@ -36,8 +37,8 @@ func TestConfigCreateErrors(t *testing.T) {
3637
},
3738
{
3839
args: []string{"name", filepath.Join("testdata", configDataFile)},
39-
configCreateFunc: func(_ context.Context, configSpec swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) {
40-
return swarm.ConfigCreateResponse{}, errors.New("error creating config")
40+
configCreateFunc: func(_ context.Context, options client.ConfigCreateOptions) (client.ConfigCreateResult, error) {
41+
return client.ConfigCreateResult{}, errors.New("error creating config")
4142
},
4243
expectedError: "error creating config",
4344
},
@@ -61,15 +62,15 @@ func TestConfigCreateWithName(t *testing.T) {
6162
const name = "config-with-name"
6263
var actual []byte
6364
cli := test.NewFakeCli(&fakeClient{
64-
configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) {
65-
if spec.Name != name {
66-
return swarm.ConfigCreateResponse{}, fmt.Errorf("expected name %q, got %q", name, spec.Name)
65+
configCreateFunc: func(_ context.Context, options client.ConfigCreateOptions) (client.ConfigCreateResult, error) {
66+
if options.Spec.Name != name {
67+
return client.ConfigCreateResult{}, fmt.Errorf("expected name %q, got %q", name, options.Spec.Name)
6768
}
6869

69-
actual = spec.Data
70+
actual = options.Spec.Data
7071

71-
return swarm.ConfigCreateResponse{
72-
ID: "ID-" + spec.Name,
72+
return client.ConfigCreateResult{
73+
ID: "ID-" + options.Spec.Name,
7374
}, nil
7475
},
7576
})
@@ -100,13 +101,13 @@ func TestConfigCreateWithLabels(t *testing.T) {
100101
}
101102

102103
cli := test.NewFakeCli(&fakeClient{
103-
configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) {
104-
if !reflect.DeepEqual(spec, expected) {
105-
return swarm.ConfigCreateResponse{}, fmt.Errorf("expected %+v, got %+v", expected, spec)
104+
configCreateFunc: func(_ context.Context, options client.ConfigCreateOptions) (client.ConfigCreateResult, error) {
105+
if !reflect.DeepEqual(options.Spec, expected) {
106+
return client.ConfigCreateResult{}, fmt.Errorf("expected %+v, got %+v", expected, options.Spec)
106107
}
107108

108-
return swarm.ConfigCreateResponse{
109-
ID: "ID-" + spec.Name,
109+
return client.ConfigCreateResult{
110+
ID: "ID-" + options.Spec.Name,
110111
}, nil
111112
},
112113
})
@@ -126,17 +127,17 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) {
126127
const name = "config-with-template-driver"
127128

128129
cli := test.NewFakeCli(&fakeClient{
129-
configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) {
130-
if spec.Name != name {
131-
return swarm.ConfigCreateResponse{}, fmt.Errorf("expected name %q, got %q", name, spec.Name)
130+
configCreateFunc: func(_ context.Context, options client.ConfigCreateOptions) (client.ConfigCreateResult, error) {
131+
if options.Spec.Name != name {
132+
return client.ConfigCreateResult{}, fmt.Errorf("expected name %q, got %q", name, options.Spec.Name)
132133
}
133134

134-
if spec.Templating.Name != expectedDriver.Name {
135-
return swarm.ConfigCreateResponse{}, fmt.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels)
135+
if options.Spec.Templating.Name != expectedDriver.Name {
136+
return client.ConfigCreateResult{}, fmt.Errorf("expected driver %v, got %v", expectedDriver, options.Spec.Labels)
136137
}
137138

138-
return swarm.ConfigCreateResponse{
139-
ID: "ID-" + spec.Name,
139+
return client.ConfigCreateResult{
140+
ID: "ID-" + options.Spec.Name,
140141
}, nil
141142
},
142143
})

cli/command/config/formatter.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/docker/cli/cli/command/inspect"
1010
"github.com/docker/go-units"
1111
"github.com/moby/moby/api/types/swarm"
12+
"github.com/moby/moby/client"
1213
)
1314

1415
const (
@@ -44,7 +45,7 @@ func newFormat(source string, quiet bool) formatter.Format {
4445
}
4546

4647
// formatWrite writes the context
47-
func formatWrite(fmtCtx formatter.Context, configs []swarm.Config) error {
48+
func formatWrite(fmtCtx formatter.Context, configs client.ConfigListResult) error {
4849
cCtx := &configContext{
4950
HeaderContext: formatter.HeaderContext{
5051
Header: formatter.SubHeaderContext{
@@ -57,7 +58,7 @@ func formatWrite(fmtCtx formatter.Context, configs []swarm.Config) error {
5758
},
5859
}
5960
return fmtCtx.Write(cCtx, func(format func(subContext formatter.SubContext) error) error {
60-
for _, config := range configs {
61+
for _, config := range configs.Items {
6162
configCtx := &configContext{c: config}
6263
if err := format(configCtx); err != nil {
6364
return err

cli/command/config/formatter_test.go

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

88
"github.com/docker/cli/cli/command/formatter"
99
"github.com/moby/moby/api/types/swarm"
10+
"github.com/moby/moby/client"
1011
"gotest.tools/v3/assert"
1112
)
1213

@@ -48,23 +49,25 @@ id_rsa
4849
},
4950
}
5051

51-
configs := []swarm.Config{
52-
{
53-
ID: "1",
54-
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
55-
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "passwords"}},
56-
},
57-
{
58-
ID: "2",
59-
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
60-
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "id_rsa"}},
52+
res := client.ConfigListResult{
53+
Items: []swarm.Config{
54+
{
55+
ID: "1",
56+
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
57+
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "passwords"}},
58+
},
59+
{
60+
ID: "2",
61+
Meta: swarm.Meta{CreatedAt: time.Now(), UpdatedAt: time.Now()},
62+
Spec: swarm.ConfigSpec{Annotations: swarm.Annotations{Name: "id_rsa"}},
63+
},
6164
},
6265
}
6366
for _, tc := range cases {
6467
t.Run(string(tc.context.Format), func(t *testing.T) {
6568
var out bytes.Buffer
6669
tc.context.Output = &out
67-
if err := formatWrite(tc.context, configs); err != nil {
70+
if err := formatWrite(tc.context, res); err != nil {
6871
assert.ErrorContains(t, err, tc.expected)
6972
} else {
7073
assert.Equal(t, out.String(), tc.expected)

cli/command/config/inspect.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/docker/cli/cli/command"
1313
"github.com/docker/cli/cli/command/formatter"
1414
flagsHelper "github.com/docker/cli/cli/flags"
15+
"github.com/moby/moby/client"
1516
"github.com/spf13/cobra"
1617
)
1718

@@ -50,7 +51,8 @@ func runInspect(ctx context.Context, dockerCLI command.Cli, opts inspectOptions)
5051
}
5152

5253
getRef := func(id string) (any, []byte, error) {
53-
return apiClient.ConfigInspectWithRaw(ctx, id)
54+
res, err := apiClient.ConfigInspect(ctx, id, client.ConfigInspectOptions{})
55+
return res.Config, res.Raw, err
5456
}
5557

5658
// check if the user is trying to apply a template to the pretty format, which

0 commit comments

Comments
 (0)