Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ linters:
linters:
- staticcheck

# Ignore deprecation linting for cli/command/stack/*.
#
# FIXME(thaJeztah): remove exception once these functions are un-exported or internal; see https://github.com/docker/cli/pull/6389
- text: '^(SA1019): '
path: "cli/command/stack"
linters:
- staticcheck

# Log a warning if an exclusion rule is unused.
# Default: false
warn-unused: true
12 changes: 12 additions & 0 deletions cli/command/stack/formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@ import (

const (
// SwarmStackTableFormat is the default Swarm stack format
//
// Deprecated: this type was for internal use and will be removed in the next release.
SwarmStackTableFormat formatter.Format = "table {{.Name}}\t{{.Services}}"

stackServicesHeader = "SERVICES"

// TableFormatKey is an alias for formatter.TableFormatKey
//
// Deprecated: this type was for internal use and will be removed in the next release.
TableFormatKey = formatter.TableFormatKey
)

// Context is an alias for formatter.Context
//
// Deprecated: this type was for internal use and will be removed in the next release.
type Context = formatter.Context

// Format is an alias for formatter.Format
//
// Deprecated: this type was for internal use and will be removed in the next release.
type Format = formatter.Format

// Stack contains deployed stack information.
//
// Deprecated: this type was for internal use and will be removed in the next release.
type Stack struct {
// Name is the name of the stack
Name string
Expand All @@ -31,6 +41,8 @@ type Stack struct {
}

// StackWrite writes formatted stacks using the Context
//
// Deprecated: this function was for internal use and will be removed in the next release.
func StackWrite(ctx formatter.Context, stacks []*Stack) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, stack := range stacks {
Expand Down
21 changes: 15 additions & 6 deletions cli/command/stack/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import (
"github.com/spf13/cobra"
)

type listOptions = options.List

func newListCommand(dockerCli command.Cli) *cobra.Command {
opts := options.List{}
opts := listOptions{}

cmd := &cobra.Command{
Use: "ls [OPTIONS]",
Aliases: []string{"list"},
Short: "List stacks",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return RunList(cmd.Context(), dockerCli, opts)
return runList(cmd.Context(), dockerCli, opts)
},
ValidArgsFunction: completion.NoComplete,
}
Expand All @@ -36,17 +38,24 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
}

// RunList performs a stack list against the specified swarm cluster
func RunList(ctx context.Context, dockerCli command.Cli, opts options.List) error {
ss, err := swarm.GetStacks(ctx, dockerCli.Client())
//
// Deprecated: this function was for internal use and will be removed in the next release.
func RunList(ctx context.Context, dockerCLI command.Cli, opts options.List) error {
return runList(ctx, dockerCLI, opts)
}

// runList performs a stack list against the specified swarm cluster
func runList(ctx context.Context, dockerCLI command.Cli, opts listOptions) error {
ss, err := swarm.GetStacks(ctx, dockerCLI.Client())
if err != nil {
return err
}
stacks := make([]*formatter.Stack, 0, len(ss))
stacks = append(stacks, ss...)
return format(dockerCli.Out(), opts, stacks)
return format(dockerCLI.Out(), opts, stacks)
}

func format(out io.Writer, opts options.List, stacks []*formatter.Stack) error {
func format(out io.Writer, opts listOptions, stacks []*formatter.Stack) error {
fmt := formatter.Format(opts.Format)
if fmt == "" || fmt == formatter.TableFormatKey {
fmt = formatter.SwarmStackTableFormat
Expand Down
4 changes: 4 additions & 0 deletions cli/command/stack/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
)

// LoadComposefile parse the composefile specified in the cli and returns its Config and version.
//
// Deprecated: this function was for internal use and will be removed in the next release.
func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.Config, error) {
configDetails, err := GetConfigDetails(opts.Composefiles, dockerCli.In())
if err != nil {
Expand Down Expand Up @@ -84,6 +86,8 @@ func propertyWarnings(properties map[string]string) string {
}

// GetConfigDetails parse the composefiles specified in the cli and returns their ConfigDetails
//
// Deprecated: this function was for internal use and will be removed in the next release.
func GetConfigDetails(composefiles []string, stdin io.Reader) (composetypes.ConfigDetails, error) {
var details composetypes.ConfigDetails

Expand Down
12 changes: 12 additions & 0 deletions cli/command/stack/options/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package options
import "github.com/docker/cli/opts"

// Deploy holds docker stack deploy options
//
// Deprecated: this type was for internal use and will be removed in the next release.
type Deploy struct {
Composefiles []string
Namespace string
Expand All @@ -14,18 +16,24 @@ type Deploy struct {
}

// Config holds docker stack config options
//
// Deprecated: this type was for internal use and will be removed in the next release.
type Config struct {
Composefiles []string
SkipInterpolation bool
}

// List holds docker stack ls options
//
// Deprecated: this type was for internal use and will be removed in the next release.
type List struct {
Format string
AllNamespaces bool
}

// PS holds docker stack ps options
//
// Deprecated: this type was for internal use and will be removed in the next release.
type PS struct {
Filter opts.FilterOpt
NoTrunc bool
Expand All @@ -36,12 +44,16 @@ type PS struct {
}

// Remove holds docker stack remove options
//
// Deprecated: this type was for internal use and will be removed in the next release.
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
Expand Down
26 changes: 18 additions & 8 deletions cli/command/stack/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import (
"github.com/spf13/cobra"
)

func newServicesCommand(dockerCli command.Cli) *cobra.Command {
opts := options.Services{Filter: cliopts.NewFilterOpt()}
// servicesOptions holds docker stack services options
type servicesOptions = options.Services

func newServicesCommand(dockerCLI command.Cli) *cobra.Command {
opts := servicesOptions{Filter: cliopts.NewFilterOpt()}

cmd := &cobra.Command{
Use: "services [OPTIONS] STACK",
Expand All @@ -30,10 +33,10 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command {
if err := validateStackName(opts.Namespace); err != nil {
return err
}
return RunServices(cmd.Context(), dockerCli, opts)
return runServices(cmd.Context(), dockerCLI, opts)
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completeNames(dockerCli)(cmd, args, toComplete)
return completeNames(dockerCLI)(cmd, args, toComplete)
},
}
flags := cmd.Flags()
Expand All @@ -44,15 +47,22 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command {
}

// RunServices performs a stack services against the specified swarm cluster
func RunServices(ctx context.Context, dockerCli command.Cli, opts options.Services) error {
services, err := swarm.GetServices(ctx, dockerCli, opts)
//
// 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)
if err != nil {
return err
}
return formatWrite(dockerCli, services, opts)
return formatWrite(dockerCLI, services, opts)
}

func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts options.Services) error {
func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts servicesOptions) 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)
Expand Down
2 changes: 2 additions & 0 deletions cli/command/stack/swarm/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
)

// RunDeploy is the swarm implementation of docker stack deploy
//
// Deprecated: this function was for internal use and will be removed in the next release.
func RunDeploy(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts *options.Deploy, cfg *composetypes.Config) error {
if err := validateResolveImageFlag(opts); err != nil {
return err
Expand Down
2 changes: 2 additions & 0 deletions cli/command/stack/swarm/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
)

// GetStacks lists the swarm stacks.
//
// Deprecated: this function was for internal use and will be removed in the next release.
func GetStacks(ctx context.Context, apiClient client.ServiceAPIClient) ([]*formatter.Stack, error) {
services, err := apiClient.ServiceList(
ctx,
Expand Down
2 changes: 2 additions & 0 deletions cli/command/stack/swarm/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

// RunPS is the swarm implementation of docker stack ps
//
// Deprecated: this function was for internal use and will be removed in the next release.
func RunPS(ctx context.Context, dockerCLI command.Cli, opts options.PS) error {
filter := getStackFilterFromOpt(opts.Namespace, opts.Filter)

Expand Down
2 changes: 2 additions & 0 deletions cli/command/stack/swarm/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
)

// RunRemove is the swarm implementation of docker stack remove
//
// Deprecated: this function was for internal use and will be removed in the next release.
func RunRemove(ctx context.Context, dockerCli command.Cli, opts options.Remove) error {
apiClient := dockerCli.Client()

Expand Down
12 changes: 7 additions & 5 deletions cli/command/stack/swarm/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
)

// GetServices is the swarm implementation of listing stack services
func GetServices(ctx context.Context, dockerCli command.Cli, opts options.Services) ([]swarm.Service, error) {
//
// 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
client = dockerCli.Client()
err error
apiClient = dockerCLI.Client()
Comment on lines +13 to +18
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor conflict here, because these vars were renamed in 7118f1f, which isn't in this branch; I chose to just apply the same renames as part of this cherry-pick.

)

listOpts := swarm.ServiceListOptions{
Expand All @@ -25,7 +27,7 @@ func GetServices(ctx context.Context, dockerCli command.Cli, opts options.Servic
Status: !opts.Quiet,
}

services, err := client.ServiceList(ctx, listOpts)
services, err := apiClient.ServiceList(ctx, listOpts)
if err != nil {
return nil, err
}
Expand All @@ -43,7 +45,7 @@ func GetServices(ctx context.Context, dockerCli command.Cli, opts options.Servic
// situations where the client uses the "default" version. To account for
// these situations, we do a quick check for services that do not have
// a ServiceStatus set, and perform a lookup for those.
services, err = service.AppendServiceStatus(ctx, client, services)
services, err = service.AppendServiceStatus(ctx, apiClient, services)
if err != nil {
return nil, err
}
Expand Down
Loading