From 0a65a7c11da7a12e7772c1385bbc5d4349876fa0 Mon Sep 17 00:00:00 2001 From: Aaron Lehmann Date: Thu, 30 Mar 2017 17:15:54 -0700 Subject: [PATCH] Change "service inspect" to show defaults in place of empty fields This adds a new parameter insertDefaults to /services/{id}. When this is set, an empty field (such as UpdateConfig) will be populated with default values in the API response. Make "service inspect" use this, so that empty fields do not result in missing information when inspecting a service. Signed-off-by: Aaron Lehmann Upstream-commit: e62ea2e54d36cf41016909cd776aaa52a7c4d5fc Component: cli --- components/cli/command/idresolver/client_test.go | 3 ++- components/cli/command/idresolver/idresolver.go | 3 ++- components/cli/command/service/inspect.go | 4 +++- components/cli/command/service/logs.go | 2 +- components/cli/command/service/progress/progress.go | 2 +- components/cli/command/service/scale.go | 2 +- components/cli/command/service/update.go | 2 +- components/cli/command/system/inspect.go | 4 +++- 8 files changed, 14 insertions(+), 8 deletions(-) diff --git a/components/cli/command/idresolver/client_test.go b/components/cli/command/idresolver/client_test.go index 8c02d7ebcf..f84683b907 100644 --- a/components/cli/command/idresolver/client_test.go +++ b/components/cli/command/idresolver/client_test.go @@ -1,6 +1,7 @@ package idresolver import ( + "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "golang.org/x/net/context" @@ -19,7 +20,7 @@ func (cli *fakeClient) NodeInspectWithRaw(ctx context.Context, nodeID string) (s return swarm.Node{}, []byte{}, nil } -func (cli *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string) (swarm.Service, []byte, error) { +func (cli *fakeClient) ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error) { if cli.serviceInspectFunc != nil { return cli.serviceInspectFunc(serviceID) } diff --git a/components/cli/command/idresolver/idresolver.go b/components/cli/command/idresolver/idresolver.go index 25c51a27eb..6088b64b59 100644 --- a/components/cli/command/idresolver/idresolver.go +++ b/components/cli/command/idresolver/idresolver.go @@ -3,6 +3,7 @@ package idresolver import ( "golang.org/x/net/context" + "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/pkg/errors" @@ -39,7 +40,7 @@ func (r *IDResolver) get(ctx context.Context, t interface{}, id string) (string, } return id, nil case swarm.Service: - service, _, err := r.client.ServiceInspectWithRaw(ctx, id) + service, _, err := r.client.ServiceInspectWithRaw(ctx, id, types.ServiceInspectOptions{}) if err != nil { return id, nil } diff --git a/components/cli/command/service/inspect.go b/components/cli/command/service/inspect.go index 8a8b51cd0e..fae24eeaf1 100644 --- a/components/cli/command/service/inspect.go +++ b/components/cli/command/service/inspect.go @@ -5,6 +5,7 @@ import ( "golang.org/x/net/context" + "github.com/docker/docker/api/types" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/formatter" @@ -51,7 +52,8 @@ func runInspect(dockerCli *command.DockerCli, opts inspectOptions) error { } getRef := func(ref string) (interface{}, []byte, error) { - service, _, err := client.ServiceInspectWithRaw(ctx, ref) + // Service inspect shows defaults values in empty fields. + service, _, err := client.ServiceInspectWithRaw(ctx, ref, types.ServiceInspectOptions{InsertDefaults: true}) if err == nil || !apiclient.IsErrServiceNotFound(err) { return service, nil, err } diff --git a/components/cli/command/service/logs.go b/components/cli/command/service/logs.go index cfcb7ed105..6dcaa118cf 100644 --- a/components/cli/command/service/logs.go +++ b/components/cli/command/service/logs.go @@ -84,7 +84,7 @@ func runLogs(dockerCli *command.DockerCli, opts *logsOptions) error { tty bool ) - service, _, err := cli.ServiceInspectWithRaw(ctx, opts.target) + service, _, err := cli.ServiceInspectWithRaw(ctx, opts.target, types.ServiceInspectOptions{}) if err != nil { // if it's any error other than service not found, it's Real if !client.IsErrServiceNotFound(err) { diff --git a/components/cli/command/service/progress/progress.go b/components/cli/command/service/progress/progress.go index ccc7e60cfc..bfeaa314a4 100644 --- a/components/cli/command/service/progress/progress.go +++ b/components/cli/command/service/progress/progress.go @@ -85,7 +85,7 @@ func ServiceProgress(ctx context.Context, client client.APIClient, serviceID str ) for { - service, _, err := client.ServiceInspectWithRaw(ctx, serviceID) + service, _, err := client.ServiceInspectWithRaw(ctx, serviceID, types.ServiceInspectOptions{}) if err != nil { return err } diff --git a/components/cli/command/service/scale.go b/components/cli/command/service/scale.go index ed76c862fe..98163c87c9 100644 --- a/components/cli/command/service/scale.go +++ b/components/cli/command/service/scale.go @@ -71,7 +71,7 @@ func runServiceScale(dockerCli *command.DockerCli, serviceID string, scale uint6 client := dockerCli.Client() ctx := context.Background() - service, _, err := client.ServiceInspectWithRaw(ctx, serviceID) + service, _, err := client.ServiceInspectWithRaw(ctx, serviceID, types.ServiceInspectOptions{}) if err != nil { return err } diff --git a/components/cli/command/service/update.go b/components/cli/command/service/update.go index b59f163829..3a6bc58d0e 100644 --- a/components/cli/command/service/update.go +++ b/components/cli/command/service/update.go @@ -101,7 +101,7 @@ func runUpdate(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *service apiClient := dockerCli.Client() ctx := context.Background() - service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID) + service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID, types.ServiceInspectOptions{}) if err != nil { return err } diff --git a/components/cli/command/system/inspect.go b/components/cli/command/system/inspect.go index 361902a9e7..ad23d35a09 100644 --- a/components/cli/command/system/inspect.go +++ b/components/cli/command/system/inspect.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/docker/docker/api/types" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/inspect" @@ -79,7 +80,8 @@ func inspectNode(ctx context.Context, dockerCli *command.DockerCli) inspect.GetR func inspectService(ctx context.Context, dockerCli *command.DockerCli) inspect.GetRefFunc { return func(ref string) (interface{}, []byte, error) { - return dockerCli.Client().ServiceInspectWithRaw(ctx, ref) + // Service inspect shows defaults values in empty fields. + return dockerCli.Client().ServiceInspectWithRaw(ctx, ref, types.ServiceInspectOptions{InsertDefaults: true}) } }