From 2128b3f11208197c8d0340ac22cd4ff9d36b96cc Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Mon, 12 Jun 2017 22:14:05 +0200 Subject: [PATCH] Do not call the config endpoint if API is lower than 1.30 Signed-off-by: Vincent Demeester --- cli/command/stack/client_test.go | 8 ++++++++ cli/command/stack/remove.go | 13 ++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cli/command/stack/client_test.go b/cli/command/stack/client_test.go index d4c373ce12..22be9dc06a 100644 --- a/cli/command/stack/client_test.go +++ b/cli/command/stack/client_test.go @@ -4,6 +4,7 @@ import ( "strings" "github.com/docker/cli/cli/compose/convert" + "github.com/docker/docker/api" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/swarm" @@ -34,6 +35,13 @@ type fakeClient struct { configRemoveFunc func(configID string) error } +func (cli *fakeClient) ServerVersion(ctx context.Context) (types.Version, error) { + return types.Version{ + Version: "docker-dev", + APIVersion: api.DefaultVersion, + }, nil +} + func (cli *fakeClient) ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error) { if cli.serviceListFunc != nil { return cli.serviceListFunc(options) diff --git a/cli/command/stack/remove.go b/cli/command/stack/remove.go index 09431dad70..b63c385a7e 100644 --- a/cli/command/stack/remove.go +++ b/cli/command/stack/remove.go @@ -8,6 +8,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" + "github.com/docker/docker/api/types/versions" "github.com/pkg/errors" "github.com/spf13/cobra" "golang.org/x/net/context" @@ -55,10 +56,20 @@ func runRemove(dockerCli command.Cli, opts removeOptions) error { return err } - configs, err := getStackConfigs(ctx, client, namespace) + var configs []swarm.Config + + version, err := client.ServerVersion(ctx) if err != nil { return err } + if versions.LessThan(version.APIVersion, "1.30") { + fmt.Fprintf(dockerCli.Err(), `WARNING: ignoring "configs" (requires API version 1.30, but the Docker daemon API version is %s)`, version.APIVersion) + } else { + configs, err = getStackConfigs(ctx, client, namespace) + if err != nil { + return err + } + } if len(services)+len(networks)+len(secrets)+len(configs) == 0 { fmt.Fprintf(dockerCli.Out(), "Nothing found in stack: %s\n", namespace)