From 06a91d315ce00b9c3e8ef43f5c4e0d9ede608e1d Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Fri, 24 Mar 2017 12:26:15 -0400 Subject: [PATCH 1/2] filter services by runtime; default to container Signed-off-by: Evan Hazlett --- command/service/list.go | 4 +++- command/service/ps.go | 4 ++++ command/stack/common.go | 8 +++++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/command/service/list.go b/command/service/list.go index ca3e741fab..67c120da58 100644 --- a/command/service/list.go +++ b/command/service/list.go @@ -45,7 +45,9 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error { ctx := context.Background() client := dockerCli.Client() - services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: opts.filter.Value()}) + serviceFilters := opts.filter.Value() + serviceFilters.Add("runtimes", string(swarm.RuntimeContainer)) + services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: serviceFilters}) if err != nil { return err } diff --git a/command/service/ps.go b/command/service/ps.go index 3a53a545d0..f9720bd3e6 100644 --- a/command/service/ps.go +++ b/command/service/ps.go @@ -7,6 +7,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" + swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli" "github.com/docker/docker/cli/command" "github.com/docker/docker/cli/command/formatter" @@ -58,8 +59,11 @@ func runPS(dockerCli *command.DockerCli, opts psOptions) error { serviceIDFilter := filters.NewArgs() serviceNameFilter := filters.NewArgs() for _, service := range opts.services { + // default to container runtime serviceIDFilter.Add("id", service) + serviceIDFilter.Add("runtimes", string(swarmtypes.RuntimeContainer)) serviceNameFilter.Add("name", service) + serviceNameFilter.Add("runtimes", string(swarmtypes.RuntimeContainer)) } serviceByIDList, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: serviceIDFilter}) if err != nil { diff --git a/command/stack/common.go b/command/stack/common.go index 72719f94fc..90bc19682e 100644 --- a/command/stack/common.go +++ b/command/stack/common.go @@ -17,6 +17,12 @@ func getStackFilter(namespace string) filters.Args { return filter } +func getServiceFilter(namespace string) filters.Args { + filter := getStackFilter(namespace) + filter.Add("runtimes", string(swarm.RuntimeContainer)) + return filter +} + func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args { filter := opt.Value() filter.Add("label", convert.LabelNamespace+"="+namespace) @@ -36,7 +42,7 @@ func getServices( ) ([]swarm.Service, error) { return apiclient.ServiceList( ctx, - types.ServiceListOptions{Filters: getStackFilter(namespace)}) + types.ServiceListOptions{Filters: getServiceFilter(namespace)}) } func getStackNetworks( From 58e69bfd5ab77c4eabd2da3d9e064405d1c85edb Mon Sep 17 00:00:00 2001 From: Evan Hazlett Date: Fri, 24 Mar 2017 15:19:59 -0400 Subject: [PATCH 2/2] updates for review comments - runtimeUrl -> type_url - runtimes -> runtime Signed-off-by: Evan Hazlett --- command/service/list.go | 2 +- command/service/ps.go | 4 ++-- command/stack/common.go | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/command/service/list.go b/command/service/list.go index 67c120da58..1754297316 100644 --- a/command/service/list.go +++ b/command/service/list.go @@ -46,7 +46,7 @@ func runList(dockerCli *command.DockerCli, opts listOptions) error { client := dockerCli.Client() serviceFilters := opts.filter.Value() - serviceFilters.Add("runtimes", string(swarm.RuntimeContainer)) + serviceFilters.Add("runtime", string(swarm.RuntimeContainer)) services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: serviceFilters}) if err != nil { return err diff --git a/command/service/ps.go b/command/service/ps.go index f9720bd3e6..2c633c66d0 100644 --- a/command/service/ps.go +++ b/command/service/ps.go @@ -61,9 +61,9 @@ func runPS(dockerCli *command.DockerCli, opts psOptions) error { for _, service := range opts.services { // default to container runtime serviceIDFilter.Add("id", service) - serviceIDFilter.Add("runtimes", string(swarmtypes.RuntimeContainer)) + serviceIDFilter.Add("runtime", string(swarmtypes.RuntimeContainer)) serviceNameFilter.Add("name", service) - serviceNameFilter.Add("runtimes", string(swarmtypes.RuntimeContainer)) + serviceNameFilter.Add("runtime", string(swarmtypes.RuntimeContainer)) } serviceByIDList, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: serviceIDFilter}) if err != nil { diff --git a/command/stack/common.go b/command/stack/common.go index 90bc19682e..e69e3fa908 100644 --- a/command/stack/common.go +++ b/command/stack/common.go @@ -19,7 +19,7 @@ func getStackFilter(namespace string) filters.Args { func getServiceFilter(namespace string) filters.Args { filter := getStackFilter(namespace) - filter.Add("runtimes", string(swarm.RuntimeContainer)) + filter.Add("runtime", string(swarm.RuntimeContainer)) return filter }