From 8c6a7fcbc9e4ff54ebaebcc5eada3a5df40f20c3 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 28 Aug 2025 10:13:45 +0200 Subject: [PATCH 1/5] deprecate cli/command/stack/formatter Functions and types in this package were exported as part of the "compose on kubernetes" feature, which was deprecated and removed. These functions are meant for internal use, and will be removed in the next release. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 30774ed1f261493fa94bbdebc448807d4fdd70b6) Signed-off-by: Sebastiaan van Stijn --- .golangci.yml | 8 ++++++++ cli/command/stack/formatter/formatter.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index bf093a63c7ac..1365f9fa3f2b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 diff --git a/cli/command/stack/formatter/formatter.go b/cli/command/stack/formatter/formatter.go index 07b322f0616a..7cfe8a89af0f 100644 --- a/cli/command/stack/formatter/formatter.go +++ b/cli/command/stack/formatter/formatter.go @@ -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 @@ -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 { From 7c6f58affe2b4e45c4ae8c01f56c3772dd20a6f9 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 28 Aug 2025 10:14:50 +0200 Subject: [PATCH 2/5] deprecate cli/command/stack/loader Functions and types in this package were exported as part of the "compose on kubernetes" feature, which was deprecated and removed. These functions are meant for internal use, and will be removed in the next release. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit ad6ab189a642625d54053ac6e7080e8940288d2d) Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/loader/loader.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cli/command/stack/loader/loader.go b/cli/command/stack/loader/loader.go index 75d485b01464..8187efb5a669 100644 --- a/cli/command/stack/loader/loader.go +++ b/cli/command/stack/loader/loader.go @@ -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 { @@ -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 From 91de2a6daee0ddeaecab41097fa286fee1aa278e Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 28 Aug 2025 10:15:13 +0200 Subject: [PATCH 3/5] deprecate cli/command/stack/options Functions and types in this package were exported as part of the "compose on kubernetes" feature, which was deprecated and removed. These functions are meant for internal use, and will be removed in the next release. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit f0e5a0d6545399477660087e2db69ebbf831666d) Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/options/opts.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cli/command/stack/options/opts.go b/cli/command/stack/options/opts.go index 28d4c3262207..bd239e892ffd 100644 --- a/cli/command/stack/options/opts.go +++ b/cli/command/stack/options/opts.go @@ -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 @@ -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 @@ -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 From 19b7dfa1cf44104836af4ab7988087ab6ef59530 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 28 Aug 2025 10:15:33 +0200 Subject: [PATCH 4/5] deprecate cli/command/stack/swarm Functions and types in this package were exported as part of the "compose on kubernetes" feature, which was deprecated and removed. These functions are meant for internal use, and will be removed in the next release. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit 036d3a6bab54fdffd9804ab2367fb9a14e62893b) Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/swarm/deploy.go | 2 ++ cli/command/stack/swarm/list.go | 2 ++ cli/command/stack/swarm/ps.go | 2 ++ cli/command/stack/swarm/remove.go | 2 ++ cli/command/stack/swarm/services.go | 12 +++++++----- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/cli/command/stack/swarm/deploy.go b/cli/command/stack/swarm/deploy.go index bfd71f5f6566..cf3a52418ff3 100644 --- a/cli/command/stack/swarm/deploy.go +++ b/cli/command/stack/swarm/deploy.go @@ -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 diff --git a/cli/command/stack/swarm/list.go b/cli/command/stack/swarm/list.go index ec951d71d395..22b175a1eda0 100644 --- a/cli/command/stack/swarm/list.go +++ b/cli/command/stack/swarm/list.go @@ -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, diff --git a/cli/command/stack/swarm/ps.go b/cli/command/stack/swarm/ps.go index e892fc94c975..fc16b7eb725d 100644 --- a/cli/command/stack/swarm/ps.go +++ b/cli/command/stack/swarm/ps.go @@ -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) diff --git a/cli/command/stack/swarm/remove.go b/cli/command/stack/swarm/remove.go index cd426d5111d5..42812262ab95 100644 --- a/cli/command/stack/swarm/remove.go +++ b/cli/command/stack/swarm/remove.go @@ -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() diff --git a/cli/command/stack/swarm/services.go b/cli/command/stack/swarm/services.go index e75d3ccf8c80..4a2eed34f5c1 100644 --- a/cli/command/stack/swarm/services.go +++ b/cli/command/stack/swarm/services.go @@ -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() ) listOpts := swarm.ServiceListOptions{ @@ -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 } @@ -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 } From e636ed2ae5645ee9b3d6b00f707d6617ed3d5632 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 28 Aug 2025 10:16:39 +0200 Subject: [PATCH 5/5] cli/command/stack: deprecate RunList, RunServices Functions and types in this package were exported as part of the "compose on kubernetes" feature, which was deprecated and removed. These functions are meant for internal use, and will be removed in the next release. Signed-off-by: Sebastiaan van Stijn (cherry picked from commit d16c56066427be5e988c197d40c93475446bcdda) Signed-off-by: Sebastiaan van Stijn --- cli/command/stack/list.go | 21 +++++++++++++++------ cli/command/stack/services.go | 26 ++++++++++++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/cli/command/stack/list.go b/cli/command/stack/list.go index 4ec1b30085d4..1b4831d43a9e 100644 --- a/cli/command/stack/list.go +++ b/cli/command/stack/list.go @@ -16,8 +16,10 @@ 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]", @@ -25,7 +27,7 @@ func newListCommand(dockerCli command.Cli) *cobra.Command { 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, } @@ -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 diff --git a/cli/command/stack/services.go b/cli/command/stack/services.go index f91ba71edfa5..cdeac2a2b9de 100644 --- a/cli/command/stack/services.go +++ b/cli/command/stack/services.go @@ -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", @@ -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() @@ -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)