Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli-plugins/examples/helloworld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/docker/cli/cli-plugins/metadata"
"github.com/docker/cli/cli-plugins/plugin"
"github.com/docker/cli/cli/command"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)

Expand All @@ -25,7 +26,7 @@ func main() {
Short: "Print the API version of the server",
RunE: func(_ *cobra.Command, _ []string) error {
apiClient := dockerCLI.Client()
ping, err := apiClient.Ping(context.Background())
ping, err := apiClient.Ping(context.Background(), client.PingOptions{})
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/docker/cli/cli/version"
dopts "github.com/docker/cli/opts"
"github.com/moby/moby/api/types/build"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -378,7 +377,7 @@ func (cli *DockerCli) initializeFromClient() {
ctx, cancel := context.WithTimeout(cli.baseCtx, cli.getInitTimeout())
defer cancel()

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

// NewDockerCli returns a DockerCli instance with all operators applied on it.
Expand Down
29 changes: 14 additions & 15 deletions cli/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/docker/cli/cli/config/configfile"
"github.com/docker/cli/cli/context/store"
"github.com/docker/cli/cli/flags"
"github.com/moby/moby/api/types"
"github.com/moby/moby/client"
"gotest.tools/v3/assert"
)
Expand Down Expand Up @@ -80,7 +79,7 @@ func TestNewAPIClientFromFlagsWithCustomHeaders(t *testing.T) {
"My-Header": "Custom-Value",
"User-Agent": UserAgent(),
}
_, err = apiClient.Ping(context.Background())
_, err = apiClient.Ping(context.TODO(), client.PingOptions{})
assert.NilError(t, err)
assert.DeepEqual(t, received, expectedHeaders)
}
Expand Down Expand Up @@ -115,7 +114,7 @@ func TestNewAPIClientFromFlagsWithCustomHeadersFromEnv(t *testing.T) {
"Four": []string{"four-value-override"},
"User-Agent": []string{UserAgent()},
}
_, err = apiClient.Ping(context.Background())
_, err = apiClient.Ping(context.TODO(), client.PingOptions{})
assert.NilError(t, err)
assert.DeepEqual(t, received, expectedHeaders)
}
Expand All @@ -135,20 +134,20 @@ func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {

type fakeClient struct {
client.Client
pingFunc func() (types.Ping, error)
pingFunc func() (client.PingResult, error)
version string
negotiated bool
}

func (c *fakeClient) Ping(_ context.Context) (types.Ping, error) {
func (c *fakeClient) Ping(_ context.Context, _ client.PingOptions) (client.PingResult, error) {
return c.pingFunc()
}

func (c *fakeClient) ClientVersion() string {
return c.version
}

func (c *fakeClient) NegotiateAPIVersionPing(types.Ping) {
func (c *fakeClient) NegotiateAPIVersionPing(client.PingResult) {
c.negotiated = true
}

Expand All @@ -157,29 +156,29 @@ func TestInitializeFromClient(t *testing.T) {

testcases := []struct {
doc string
pingFunc func() (types.Ping, error)
pingFunc func() (client.PingResult, error)
expectedServer ServerInfo
negotiated bool
}{
{
doc: "successful ping",
pingFunc: func() (types.Ping, error) {
return types.Ping{Experimental: true, OSType: "linux", APIVersion: "v1.44"}, nil
pingFunc: func() (client.PingResult, error) {
return client.PingResult{Experimental: true, OSType: "linux", APIVersion: "v1.44"}, nil
},
expectedServer: ServerInfo{HasExperimental: true, OSType: "linux"},
negotiated: true,
},
{
doc: "failed ping, no API version",
pingFunc: func() (types.Ping, error) {
return types.Ping{}, errors.New("failed")
pingFunc: func() (client.PingResult, error) {
return client.PingResult{}, errors.New("failed")
},
expectedServer: ServerInfo{HasExperimental: true},
},
{
doc: "failed ping, with API version",
pingFunc: func() (types.Ping, error) {
return types.Ping{APIVersion: "v1.44"}, errors.New("failed")
pingFunc: func() (client.PingResult, error) {
return client.PingResult{APIVersion: "v1.44"}, errors.New("failed")
},
expectedServer: ServerInfo{HasExperimental: true},
negotiated: true,
Expand Down Expand Up @@ -211,7 +210,7 @@ func TestInitializeFromClientHangs(t *testing.T) {
assert.NilError(t, err)

receiveReqCh := make(chan bool)
timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Second)
timeoutCtx, cancel := context.WithTimeout(context.TODO(), time.Second)
defer cancel()

// Simulate a server that hangs on connections.
Expand Down Expand Up @@ -385,7 +384,7 @@ func TestNewDockerCliWithCustomUserAgent(t *testing.T) {
cli.options = opts
cli.configFile = &configfile.ConfigFile{}

_, err = cli.Client().Ping(context.Background())
_, err = cli.Client().Ping(context.TODO(), client.PingOptions{})
assert.NilError(t, err)
assert.DeepEqual(t, received, "fake-agent/0.0.1")
}
16 changes: 8 additions & 8 deletions cli/command/completion/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func ImageNames(dockerCLI APIClientProvider, limit int) cobra.CompletionFunc {
if limit > 0 && len(args) >= limit {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, err := dockerCLI.Client().ImageList(cmd.Context(), client.ImageListOptions{})
res, err := dockerCLI.Client().ImageList(cmd.Context(), client.ImageListOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, img := range list {
for _, img := range res.Items {
names = append(names, img.RepoTags...)
}
return names, cobra.ShellCompDirectiveNoFileComp
Expand All @@ -47,13 +47,13 @@ func ImageNamesWithBase(dockerCLI APIClientProvider, limit int) cobra.Completion
if limit > 0 && len(args) >= limit {
return nil, cobra.ShellCompDirectiveNoFileComp
}
list, err := dockerCLI.Client().ImageList(cmd.Context(), client.ImageListOptions{})
res, err := dockerCLI.Client().ImageList(cmd.Context(), client.ImageListOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
baseNameCounts := make(map[string]int)
for _, img := range list {
for _, img := range res.Items {
names = append(names, img.RepoTags...)
for _, tag := range img.RepoTags {
ref, err := reference.ParseNormalizedNamed(tag)
Expand Down Expand Up @@ -110,12 +110,12 @@ func ContainerNames(dockerCLI APIClientProvider, all bool, filters ...func(conta
// VolumeNames offers completion for volumes
func VolumeNames(dockerCLI APIClientProvider) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, err := dockerCLI.Client().VolumeList(cmd.Context(), client.VolumeListOptions{})
res, err := dockerCLI.Client().VolumeList(cmd.Context(), client.VolumeListOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, vol := range list.Volumes {
for _, vol := range res.Items.Volumes {
names = append(names, vol.Name)
}
return names, cobra.ShellCompDirectiveNoFileComp
Expand All @@ -125,12 +125,12 @@ func VolumeNames(dockerCLI APIClientProvider) cobra.CompletionFunc {
// NetworkNames offers completion for networks
func NetworkNames(dockerCLI APIClientProvider) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, err := dockerCLI.Client().NetworkList(cmd.Context(), client.NetworkListOptions{})
res, err := dockerCLI.Client().NetworkList(cmd.Context(), client.NetworkListOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, nw := range list {
for _, nw := range res.Items {
names = append(names, nw.Name)
}
return names, cobra.ShellCompDirectiveNoFileComp
Expand Down
48 changes: 24 additions & 24 deletions cli/command/completion/functions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,38 @@ func (c fakeCLI) Client() client.APIClient {

type fakeClient struct {
client.Client
containerListFunc func(options client.ContainerListOptions) ([]container.Summary, error)
imageListFunc func(options client.ImageListOptions) ([]image.Summary, error)
networkListFunc func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error)
volumeListFunc func(filter client.Filters) (volume.ListResponse, error)
containerListFunc func(context.Context, client.ContainerListOptions) ([]container.Summary, error)
imageListFunc func(context.Context, client.ImageListOptions) (client.ImageListResult, error)
networkListFunc func(context.Context, client.NetworkListOptions) (client.NetworkListResult, error)
volumeListFunc func(context.Context, client.VolumeListOptions) (client.VolumeListResult, error)
}

func (c *fakeClient) ContainerList(_ context.Context, options client.ContainerListOptions) ([]container.Summary, error) {
func (c *fakeClient) ContainerList(ctx context.Context, options client.ContainerListOptions) ([]container.Summary, error) {
if c.containerListFunc != nil {
return c.containerListFunc(options)
return c.containerListFunc(ctx, options)
}
return []container.Summary{}, nil
}

func (c *fakeClient) ImageList(_ context.Context, options client.ImageListOptions) ([]image.Summary, error) {
func (c *fakeClient) ImageList(ctx context.Context, options client.ImageListOptions) (client.ImageListResult, error) {
if c.imageListFunc != nil {
return c.imageListFunc(options)
return c.imageListFunc(ctx, options)
}
return []image.Summary{}, nil
return client.ImageListResult{}, nil
}

func (c *fakeClient) NetworkList(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) {
func (c *fakeClient) NetworkList(ctx context.Context, options client.NetworkListOptions) (client.NetworkListResult, error) {
if c.networkListFunc != nil {
return c.networkListFunc(ctx, options)
}
return []network.Summary{}, nil
return client.NetworkListResult{}, nil
}

func (c *fakeClient) VolumeList(_ context.Context, options client.VolumeListOptions) (volume.ListResponse, error) {
func (c *fakeClient) VolumeList(ctx context.Context, options client.VolumeListOptions) (client.VolumeListResult, error) {
if c.volumeListFunc != nil {
return c.volumeListFunc(options.Filters)
return c.volumeListFunc(ctx, options)
}
return volume.ListResponse{}, nil
return client.VolumeListResult{}, nil
}

func TestCompleteContainerNames(t *testing.T) {
Expand Down Expand Up @@ -153,7 +153,7 @@ func TestCompleteContainerNames(t *testing.T) {
t.Setenv("DOCKER_COMPLETION_SHOW_CONTAINER_IDS", "yes")
}
comp := ContainerNames(fakeCLI{&fakeClient{
containerListFunc: func(opts client.ContainerListOptions) ([]container.Summary, error) {
containerListFunc: func(_ context.Context, opts client.ContainerListOptions) ([]container.Summary, error) {
assert.Check(t, is.DeepEqual(opts, tc.expOpts))
if tc.expDirective == cobra.ShellCompDirectiveError {
return nil, errors.New("some error occurred")
Expand Down Expand Up @@ -226,11 +226,11 @@ func TestCompleteImageNames(t *testing.T) {
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
comp := ImageNames(fakeCLI{&fakeClient{
imageListFunc: func(options client.ImageListOptions) ([]image.Summary, error) {
imageListFunc: func(context.Context, client.ImageListOptions) (client.ImageListResult, error) {
if tc.expDirective == cobra.ShellCompDirectiveError {
return nil, errors.New("some error occurred")
return client.ImageListResult{}, errors.New("some error occurred")
}
return tc.images, nil
return client.ImageListResult{Items: tc.images}, nil
},
}}, -1)

Expand Down Expand Up @@ -286,11 +286,11 @@ func TestCompleteNetworkNames(t *testing.T) {
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
comp := NetworkNames(fakeCLI{&fakeClient{
networkListFunc: func(ctx context.Context, options client.NetworkListOptions) ([]network.Summary, error) {
networkListFunc: func(context.Context, client.NetworkListOptions) (client.NetworkListResult, error) {
if tc.expDirective == cobra.ShellCompDirectiveError {
return nil, errors.New("some error occurred")
return client.NetworkListResult{}, errors.New("some error occurred")
}
return tc.networks, nil
return client.NetworkListResult{Items: tc.networks}, nil
},
}})

Expand Down Expand Up @@ -337,11 +337,11 @@ func TestCompleteVolumeNames(t *testing.T) {
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
comp := VolumeNames(fakeCLI{&fakeClient{
volumeListFunc: func(filter client.Filters) (volume.ListResponse, error) {
volumeListFunc: func(context.Context, client.VolumeListOptions) (client.VolumeListResult, error) {
if tc.expDirective == cobra.ShellCompDirectiveError {
return volume.ListResponse{}, errors.New("some error occurred")
return client.VolumeListResult{}, errors.New("some error occurred")
}
return volume.ListResponse{Volumes: tc.volumes}, nil
return client.VolumeListResult{Items: volume.ListResponse{Volumes: tc.volumes}}, nil
},
}})

Expand Down
31 changes: 15 additions & 16 deletions cli/command/config/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,41 @@ package config
import (
"context"

"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
)

type fakeClient struct {
client.Client
configCreateFunc func(context.Context, swarm.ConfigSpec) (swarm.ConfigCreateResponse, error)
configInspectFunc func(context.Context, string) (swarm.Config, []byte, error)
configListFunc func(context.Context, client.ConfigListOptions) ([]swarm.Config, error)
configRemoveFunc func(string) error
configCreateFunc func(context.Context, client.ConfigCreateOptions) (client.ConfigCreateResult, error)
configInspectFunc func(context.Context, string, client.ConfigInspectOptions) (client.ConfigInspectResult, error)
configListFunc func(context.Context, client.ConfigListOptions) (client.ConfigListResult, error)
configRemoveFunc func(context.Context, string, client.ConfigRemoveOptions) (client.ConfigRemoveResult, error)
}

func (c *fakeClient) ConfigCreate(ctx context.Context, spec swarm.ConfigSpec) (swarm.ConfigCreateResponse, error) {
func (c *fakeClient) ConfigCreate(ctx context.Context, options client.ConfigCreateOptions) (client.ConfigCreateResult, error) {
if c.configCreateFunc != nil {
return c.configCreateFunc(ctx, spec)
return c.configCreateFunc(ctx, options)
}
return swarm.ConfigCreateResponse{}, nil
return client.ConfigCreateResult{}, nil
}

func (c *fakeClient) ConfigInspectWithRaw(ctx context.Context, id string) (swarm.Config, []byte, error) {
func (c *fakeClient) ConfigInspect(ctx context.Context, id string, options client.ConfigInspectOptions) (client.ConfigInspectResult, error) {
if c.configInspectFunc != nil {
return c.configInspectFunc(ctx, id)
return c.configInspectFunc(ctx, id, options)
}
return swarm.Config{}, nil, nil
return client.ConfigInspectResult{}, nil
}

func (c *fakeClient) ConfigList(ctx context.Context, options client.ConfigListOptions) ([]swarm.Config, error) {
func (c *fakeClient) ConfigList(ctx context.Context, options client.ConfigListOptions) (client.ConfigListResult, error) {
if c.configListFunc != nil {
return c.configListFunc(ctx, options)
}
return []swarm.Config{}, nil
return client.ConfigListResult{}, nil
}

func (c *fakeClient) ConfigRemove(_ context.Context, name string) error {
func (c *fakeClient) ConfigRemove(ctx context.Context, name string, options client.ConfigRemoveOptions) (client.ConfigRemoveResult, error) {
if c.configRemoveFunc != nil {
return c.configRemoveFunc(name)
return c.configRemoveFunc(ctx, name, options)
}
return nil
return client.ConfigRemoveResult{}, nil
}
4 changes: 2 additions & 2 deletions cli/command/config/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func newConfigCommand(dockerCLI command.Cli) *cobra.Command {
// completeNames offers completion for swarm configs
func completeNames(dockerCLI completion.APIClientProvider) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
list, err := dockerCLI.Client().ConfigList(cmd.Context(), client.ConfigListOptions{})
res, err := dockerCLI.Client().ConfigList(cmd.Context(), client.ConfigListOptions{})
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, config := range list {
for _, config := range res.Items {
names = append(names, config.ID)
}
return names, cobra.ShellCompDirectiveNoFileComp
Expand Down
Loading
Loading