mirror of https://github.com/docker/cli.git
cli/command/stack: remove deprecated RunServices and swarm.GetServices
These were deprecated inf0e5a0d654
,036d3a6bab
, andd16c560664
and were only used internally. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
c4df0d17bb
commit
2a05951680
|
@ -4,6 +4,10 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/docker/cli/cli/compose/convert"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/moby/moby/api/types/filters"
|
||||
)
|
||||
|
||||
// validateStackName checks if the provided string is a valid stack name (namespace).
|
||||
|
@ -29,3 +33,9 @@ func validateStackNames(namespaces []string) error {
|
|||
func quotesOrWhitespace(r rune) bool {
|
||||
return unicode.IsSpace(r) || r == '"' || r == '\''
|
||||
}
|
||||
|
||||
func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
|
||||
filter := opt.Value()
|
||||
filter.Add("label", convert.LabelNamespace+"="+namespace)
|
||||
return filter
|
||||
}
|
||||
|
|
|
@ -42,13 +42,3 @@ type Remove struct {
|
|||
Namespaces []string
|
||||
Detach bool
|
||||
}
|
||||
|
||||
// Services holds docker stack services options
|
||||
//
|
||||
// Deprecated: this type was for internal use and will be removed in the next release.
|
||||
type Services struct {
|
||||
Quiet bool
|
||||
Format string
|
||||
Filter opts.FilterOpt
|
||||
Namespace string
|
||||
}
|
||||
|
|
|
@ -7,30 +7,33 @@ import (
|
|||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/cli/cli/command/service"
|
||||
"github.com/docker/cli/cli/command/stack/formatter"
|
||||
"github.com/docker/cli/cli/command/stack/options"
|
||||
"github.com/docker/cli/cli/command/stack/swarm"
|
||||
flagsHelper "github.com/docker/cli/cli/flags"
|
||||
cliopts "github.com/docker/cli/opts"
|
||||
"github.com/fvbommel/sortorder"
|
||||
swarmtypes "github.com/moby/moby/api/types/swarm"
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// servicesOptions holds docker stack services options
|
||||
type servicesOptions = options.Services
|
||||
// serviceListOptions holds docker stack services options
|
||||
type serviceListOptions = struct {
|
||||
quiet bool
|
||||
format string
|
||||
filter cliopts.FilterOpt
|
||||
namespace string
|
||||
}
|
||||
|
||||
func newServicesCommand(dockerCLI command.Cli) *cobra.Command {
|
||||
opts := servicesOptions{Filter: cliopts.NewFilterOpt()}
|
||||
opts := serviceListOptions{filter: cliopts.NewFilterOpt()}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "services [OPTIONS] STACK",
|
||||
Short: "List the services in the stack",
|
||||
Args: cli.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
opts.Namespace = args[0]
|
||||
if err := validateStackName(opts.Namespace); err != nil {
|
||||
opts.namespace = args[0]
|
||||
if err := validateStackName(opts.namespace); err != nil {
|
||||
return err
|
||||
}
|
||||
return runServices(cmd.Context(), dockerCLI, opts)
|
||||
|
@ -40,41 +43,34 @@ func newServicesCommand(dockerCLI command.Cli) *cobra.Command {
|
|||
},
|
||||
}
|
||||
flags := cmd.Flags()
|
||||
flags.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs")
|
||||
flags.StringVar(&opts.Format, "format", "", flagsHelper.FormatHelp)
|
||||
flags.VarP(&opts.Filter, "filter", "f", "Filter output based on conditions provided")
|
||||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
|
||||
flags.StringVar(&opts.format, "format", "", flagsHelper.FormatHelp)
|
||||
flags.VarP(&opts.filter, "filter", "f", "Filter output based on conditions provided")
|
||||
return cmd
|
||||
}
|
||||
|
||||
// RunServices performs a stack services against the specified swarm cluster
|
||||
//
|
||||
// Deprecated: this function was for internal use and will be removed in the next release.
|
||||
func RunServices(ctx context.Context, dockerCLI command.Cli, opts options.Services) error {
|
||||
return runServices(ctx, dockerCLI, opts)
|
||||
}
|
||||
|
||||
// runServices performs a stack services against the specified swarm cluster
|
||||
func runServices(ctx context.Context, dockerCLI command.Cli, opts servicesOptions) error {
|
||||
services, err := swarm.GetServices(ctx, dockerCLI, opts)
|
||||
func runServices(ctx context.Context, dockerCLI command.Cli, opts serviceListOptions) error {
|
||||
services, err := getServices(ctx, dockerCLI.Client(), opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return formatWrite(dockerCLI, services, opts)
|
||||
}
|
||||
|
||||
func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts servicesOptions) error {
|
||||
func formatWrite(dockerCLI command.Cli, services []swarm.Service, opts serviceListOptions) error {
|
||||
// if no services in the stack, print message and exit 0
|
||||
if len(services) == 0 {
|
||||
_, _ = fmt.Fprintln(dockerCLI.Err(), "Nothing found in stack:", opts.Namespace)
|
||||
_, _ = fmt.Fprintln(dockerCLI.Err(), "Nothing found in stack:", opts.namespace)
|
||||
return nil
|
||||
}
|
||||
sort.Slice(services, func(i, j int) bool {
|
||||
return sortorder.NaturalLess(services[i].Spec.Name, services[j].Spec.Name)
|
||||
})
|
||||
|
||||
f := opts.Format
|
||||
f := opts.format
|
||||
if len(f) == 0 {
|
||||
if len(dockerCLI.ConfigFile().ServicesFormat) > 0 && !opts.Quiet {
|
||||
if len(dockerCLI.ConfigFile().ServicesFormat) > 0 && !opts.quiet {
|
||||
f = dockerCLI.ConfigFile().ServicesFormat
|
||||
} else {
|
||||
f = formatter.TableFormatKey
|
||||
|
@ -83,7 +79,7 @@ func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts serv
|
|||
|
||||
servicesCtx := formatter.Context{
|
||||
Output: dockerCLI.Out(),
|
||||
Format: service.NewListFormat(f, opts.Quiet),
|
||||
Format: service.NewListFormat(f, opts.quiet),
|
||||
}
|
||||
return service.ListFormatWrite(servicesCtx, services)
|
||||
}
|
||||
|
|
|
@ -1,31 +1,22 @@
|
|||
package swarm
|
||||
package stack
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/service"
|
||||
"github.com/docker/cli/cli/command/stack/options"
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
"github.com/moby/moby/client"
|
||||
)
|
||||
|
||||
// GetServices is the swarm implementation of listing stack services
|
||||
//
|
||||
// Deprecated: this function was for internal use and will be removed in the next release.
|
||||
func GetServices(ctx context.Context, dockerCLI command.Cli, opts options.Services) ([]swarm.Service, error) {
|
||||
var (
|
||||
err error
|
||||
apiClient = dockerCLI.Client()
|
||||
)
|
||||
|
||||
// getServices is the swarm implementation of listing stack services
|
||||
func getServices(ctx context.Context, apiClient client.APIClient, opts serviceListOptions) ([]swarm.Service, error) {
|
||||
listOpts := client.ServiceListOptions{
|
||||
Filters: getStackFilterFromOpt(opts.Namespace, opts.Filter),
|
||||
Filters: getStackFilterFromOpt(opts.namespace, opts.filter),
|
||||
// When not running "quiet", also get service status (number of running
|
||||
// and desired tasks). Note that this is only supported on API v1.41 and
|
||||
// up; older API versions ignore this option, and we will have to collect
|
||||
// the information manually below.
|
||||
Status: !opts.Quiet,
|
||||
Status: !opts.quiet,
|
||||
}
|
||||
|
||||
services, err := apiClient.ServiceList(ctx, listOpts)
|
Loading…
Reference in New Issue