Skip to content

Commit 2a05951

Browse files
committed
cli/command/stack: remove deprecated RunServices and swarm.GetServices
These were deprecated in f0e5a0d, 036d3a6, and d16c560 and were only used internally. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent c4df0d1 commit 2a05951

File tree

4 files changed

+37
-50
lines changed

4 files changed

+37
-50
lines changed

cli/command/stack/common.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import (
44
"fmt"
55
"strings"
66
"unicode"
7+
8+
"github.com/docker/cli/cli/compose/convert"
9+
"github.com/docker/cli/opts"
10+
"github.com/moby/moby/api/types/filters"
711
)
812

913
// validateStackName checks if the provided string is a valid stack name (namespace).
@@ -29,3 +33,9 @@ func validateStackNames(namespaces []string) error {
2933
func quotesOrWhitespace(r rune) bool {
3034
return unicode.IsSpace(r) || r == '"' || r == '\''
3135
}
36+
37+
func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
38+
filter := opt.Value()
39+
filter.Add("label", convert.LabelNamespace+"="+namespace)
40+
return filter
41+
}

cli/command/stack/options/opts.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,3 @@ type Remove struct {
4242
Namespaces []string
4343
Detach bool
4444
}
45-
46-
// Services holds docker stack services options
47-
//
48-
// Deprecated: this type was for internal use and will be removed in the next release.
49-
type Services struct {
50-
Quiet bool
51-
Format string
52-
Filter opts.FilterOpt
53-
Namespace string
54-
}

cli/command/stack/services.go

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,33 @@ import (
77

88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
10+
"github.com/docker/cli/cli/command/formatter"
1011
"github.com/docker/cli/cli/command/service"
11-
"github.com/docker/cli/cli/command/stack/formatter"
12-
"github.com/docker/cli/cli/command/stack/options"
13-
"github.com/docker/cli/cli/command/stack/swarm"
1412
flagsHelper "github.com/docker/cli/cli/flags"
1513
cliopts "github.com/docker/cli/opts"
1614
"github.com/fvbommel/sortorder"
17-
swarmtypes "github.com/moby/moby/api/types/swarm"
15+
"github.com/moby/moby/api/types/swarm"
1816
"github.com/spf13/cobra"
1917
)
2018

21-
// servicesOptions holds docker stack services options
22-
type servicesOptions = options.Services
19+
// serviceListOptions holds docker stack services options
20+
type serviceListOptions = struct {
21+
quiet bool
22+
format string
23+
filter cliopts.FilterOpt
24+
namespace string
25+
}
2326

2427
func newServicesCommand(dockerCLI command.Cli) *cobra.Command {
25-
opts := servicesOptions{Filter: cliopts.NewFilterOpt()}
28+
opts := serviceListOptions{filter: cliopts.NewFilterOpt()}
2629

2730
cmd := &cobra.Command{
2831
Use: "services [OPTIONS] STACK",
2932
Short: "List the services in the stack",
3033
Args: cli.ExactArgs(1),
3134
RunE: func(cmd *cobra.Command, args []string) error {
32-
opts.Namespace = args[0]
33-
if err := validateStackName(opts.Namespace); err != nil {
35+
opts.namespace = args[0]
36+
if err := validateStackName(opts.namespace); err != nil {
3437
return err
3538
}
3639
return runServices(cmd.Context(), dockerCLI, opts)
@@ -40,41 +43,34 @@ func newServicesCommand(dockerCLI command.Cli) *cobra.Command {
4043
},
4144
}
4245
flags := cmd.Flags()
43-
flags.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs")
44-
flags.StringVar(&opts.Format, "format", "", flagsHelper.FormatHelp)
45-
flags.VarP(&opts.Filter, "filter", "f", "Filter output based on conditions provided")
46+
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
47+
flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp)
48+
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
4649
return cmd
4750
}
4851

49-
// RunServices performs a stack services against the specified swarm cluster
50-
//
51-
// Deprecated: this function was for internal use and will be removed in the next release.
52-
func RunServices(ctx context.Context, dockerCLI command.Cli, opts options.Services) error {
53-
return runServices(ctx, dockerCLI, opts)
54-
}
55-
5652
// runServices performs a stack services against the specified swarm cluster
57-
func runServices(ctx context.Context, dockerCLI command.Cli, opts servicesOptions) error {
58-
services, err := swarm.GetServices(ctx, dockerCLI, opts)
53+
func runServices(ctx context.Context, dockerCLI command.Cli, opts serviceListOptions) error {
54+
services, err := getServices(ctx, dockerCLI.Client(), opts)
5955
if err != nil {
6056
return err
6157
}
6258
return formatWrite(dockerCLI, services, opts)
6359
}
6460

65-
func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts servicesOptions) error {
61+
func formatWrite(dockerCLI command.Cli, services []swarm.Service, opts serviceListOptions) error {
6662
// if no services in the stack, print message and exit 0
6763
if len(services) == 0 {
68-
_, _ = fmt.Fprintln(dockerCLI.Err(), "Nothing found in stack:", opts.Namespace)
64+
_, _ = fmt.Fprintln(dockerCLI.Err(), "Nothing found in stack:", opts.namespace)
6965
return nil
7066
}
7167
sort.Slice(services, func(i, j int) bool {
7268
return sortorder.NaturalLess(services[i].Spec.Name, services[j].Spec.Name)
7369
})
7470

75-
f := opts.Format
71+
f := opts.format
7672
if len(f) == 0 {
77-
if len(dockerCLI.ConfigFile().ServicesFormat) > 0 && !opts.Quiet {
73+
if len(dockerCLI.ConfigFile().ServicesFormat) > 0 && !opts.quiet {
7874
f = dockerCLI.ConfigFile().ServicesFormat
7975
} else {
8076
f = formatter.TableFormatKey
@@ -83,7 +79,7 @@ func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts serv
8379

8480
servicesCtx := formatter.Context{
8581
Output: dockerCLI.Out(),
86-
Format: service.NewListFormat(f, opts.Quiet),
82+
Format: service.NewListFormat(f, opts.quiet),
8783
}
8884
return service.ListFormatWrite(servicesCtx, services)
8985
}
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
1-
package swarm
1+
package stack
22

33
import (
44
"context"
55

6-
"github.com/docker/cli/cli/command"
76
"github.com/docker/cli/cli/command/service"
8-
"github.com/docker/cli/cli/command/stack/options"
97
"github.com/moby/moby/api/types/swarm"
108
"github.com/moby/moby/client"
119
)
1210

13-
// GetServices is the swarm implementation of listing stack services
14-
//
15-
// Deprecated: this function was for internal use and will be removed in the next release.
16-
func GetServices(ctx context.Context, dockerCLI command.Cli, opts options.Services) ([]swarm.Service, error) {
17-
var (
18-
err error
19-
apiClient = dockerCLI.Client()
20-
)
21-
11+
// getServices is the swarm implementation of listing stack services
12+
func getServices(ctx context.Context, apiClient client.APIClient, opts serviceListOptions) ([]swarm.Service, error) {
2213
listOpts := client.ServiceListOptions{
23-
Filters: getStackFilterFromOpt(opts.Namespace, opts.Filter),
14+
Filters: getStackFilterFromOpt(opts.namespace, opts.filter),
2415
// When not running "quiet", also get service status (number of running
2516
// and desired tasks). Note that this is only supported on API v1.41 and
2617
// up; older API versions ignore this option, and we will have to collect
2718
// the information manually below.
28-
Status: !opts.Quiet,
19+
Status: !opts.quiet,
2920
}
3021

3122
services, err := apiClient.ServiceList(ctx, listOpts)

0 commit comments

Comments
 (0)