From b866fa77f46dbe70cc87115938d209c3e03bc0e0 Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Mon, 14 Nov 2016 18:08:24 -0800 Subject: [PATCH] Return warnings from service create and service update when digest pinning fails Modify the service update and create APIs to return optional warning messages as part of the response. Populate these messages with an informative reason when digest resolution fails. This is a small API change, but significantly improves the UX. The user can now get immediate feedback when they've specified a nonexistent image or unreachable registry. Signed-off-by: Aaron Lehmann --- command/service/create.go | 4 ++++ command/service/scale.go | 6 +++++- command/service/update.go | 6 +++++- command/stack/deploy.go | 9 +++++++-- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/command/service/create.go b/command/service/create.go index 061a36f06c..96c9f36da1 100644 --- a/command/service/create.go +++ b/command/service/create.go @@ -90,6 +90,10 @@ func runCreate(dockerCli *command.DockerCli, opts *serviceOptions) error { return err } + for _, warning := range response.Warnings { + fmt.Fprintln(dockerCli.Err(), warning) + } + fmt.Fprintf(dockerCli.Out(), "%s\n", response.ID) return nil } diff --git a/command/service/scale.go b/command/service/scale.go index ea30265bd7..cf89e90273 100644 --- a/command/service/scale.go +++ b/command/service/scale.go @@ -82,11 +82,15 @@ func runServiceScale(dockerCli *command.DockerCli, serviceID string, scale uint6 serviceMode.Replicated.Replicas = &scale - err = client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, types.ServiceUpdateOptions{}) + response, err := client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, types.ServiceUpdateOptions{}) if err != nil { return err } + for _, warning := range response.Warnings { + fmt.Fprintln(dockerCli.Err(), warning) + } + fmt.Fprintf(dockerCli.Out(), "%s scaled to %d\n", serviceID, scale) return nil } diff --git a/command/service/update.go b/command/service/update.go index d2639a62db..20a4fc5708 100644 --- a/command/service/update.go +++ b/command/service/update.go @@ -133,11 +133,15 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, serviceID str updateOpts.RegistryAuthFrom = types.RegistryAuthFromSpec } - err = apiClient.ServiceUpdate(ctx, service.ID, service.Version, *spec, updateOpts) + response, err := apiClient.ServiceUpdate(ctx, service.ID, service.Version, *spec, updateOpts) if err != nil { return err } + for _, warning := range response.Warnings { + fmt.Fprintln(dockerCli.Err(), warning) + } + fmt.Fprintf(dockerCli.Out(), "%s\n", serviceID) return nil } diff --git a/command/stack/deploy.go b/command/stack/deploy.go index 683f0cad35..63adeacd62 100644 --- a/command/stack/deploy.go +++ b/command/stack/deploy.go @@ -408,15 +408,20 @@ func deployServices( if sendAuth { updateOpts.EncodedRegistryAuth = encodedAuth } - if err := apiClient.ServiceUpdate( + response, err := apiClient.ServiceUpdate( ctx, service.ID, service.Version, serviceSpec, updateOpts, - ); err != nil { + ) + if err != nil { return err } + + for _, warning := range response.Warnings { + fmt.Fprintln(dockerCli.Err(), warning) + } } else { fmt.Fprintf(out, "Creating service %s\n", name)