Skip to content

Commit 19b86ef

Browse files
authored
Merge pull request #6391 from thaJeztah/28.x_backport_deprecate_stack_commands
[28.x backport] cli/command/stack/*: deprecate exported functions and types
2 parents 88d6197 + e636ed2 commit 19b86ef

File tree

11 files changed

+84
-19
lines changed

11 files changed

+84
-19
lines changed

.golangci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ linters:
222222
linters:
223223
- staticcheck
224224

225+
# Ignore deprecation linting for cli/command/stack/*.
226+
#
227+
# FIXME(thaJeztah): remove exception once these functions are un-exported or internal; see https://github.com/docker/cli/pull/6389
228+
- text: '^(SA1019): '
229+
path: "cli/command/stack"
230+
linters:
231+
- staticcheck
232+
225233
# Log a warning if an exclusion rule is unused.
226234
# Default: false
227235
warn-unused: true

cli/command/stack/formatter/formatter.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,31 @@ import (
88

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

1315
stackServicesHeader = "SERVICES"
1416

1517
// TableFormatKey is an alias for formatter.TableFormatKey
18+
//
19+
// Deprecated: this type was for internal use and will be removed in the next release.
1620
TableFormatKey = formatter.TableFormatKey
1721
)
1822

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

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

2533
// Stack contains deployed stack information.
34+
//
35+
// Deprecated: this type was for internal use and will be removed in the next release.
2636
type Stack struct {
2737
// Name is the name of the stack
2838
Name string
@@ -31,6 +41,8 @@ type Stack struct {
3141
}
3242

3343
// StackWrite writes formatted stacks using the Context
44+
//
45+
// Deprecated: this function was for internal use and will be removed in the next release.
3446
func StackWrite(ctx formatter.Context, stacks []*Stack) error {
3547
render := func(format func(subContext formatter.SubContext) error) error {
3648
for _, stack := range stacks {

cli/command/stack/list.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ import (
1616
"github.com/spf13/cobra"
1717
)
1818

19+
type listOptions = options.List
20+
1921
func newListCommand(dockerCli command.Cli) *cobra.Command {
20-
opts := options.List{}
22+
opts := listOptions{}
2123

2224
cmd := &cobra.Command{
2325
Use: "ls [OPTIONS]",
2426
Aliases: []string{"list"},
2527
Short: "List stacks",
2628
Args: cli.NoArgs,
2729
RunE: func(cmd *cobra.Command, args []string) error {
28-
return RunList(cmd.Context(), dockerCli, opts)
30+
return runList(cmd.Context(), dockerCli, opts)
2931
},
3032
ValidArgsFunction: completion.NoComplete,
3133
}
@@ -36,17 +38,24 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
3638
}
3739

3840
// RunList performs a stack list against the specified swarm cluster
39-
func RunList(ctx context.Context, dockerCli command.Cli, opts options.List) error {
40-
ss, err := swarm.GetStacks(ctx, dockerCli.Client())
41+
//
42+
// Deprecated: this function was for internal use and will be removed in the next release.
43+
func RunList(ctx context.Context, dockerCLI command.Cli, opts options.List) error {
44+
return runList(ctx, dockerCLI, opts)
45+
}
46+
47+
// runList performs a stack list against the specified swarm cluster
48+
func runList(ctx context.Context, dockerCLI command.Cli, opts listOptions) error {
49+
ss, err := swarm.GetStacks(ctx, dockerCLI.Client())
4150
if err != nil {
4251
return err
4352
}
4453
stacks := make([]*formatter.Stack, 0, len(ss))
4554
stacks = append(stacks, ss...)
46-
return format(dockerCli.Out(), opts, stacks)
55+
return format(dockerCLI.Out(), opts, stacks)
4756
}
4857

49-
func format(out io.Writer, opts options.List, stacks []*formatter.Stack) error {
58+
func format(out io.Writer, opts listOptions, stacks []*formatter.Stack) error {
5059
fmt := formatter.Format(opts.Format)
5160
if fmt == "" || fmt == formatter.TableFormatKey {
5261
fmt = formatter.SwarmStackTableFormat

cli/command/stack/loader/loader.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
)
2323

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

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

cli/command/stack/options/opts.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package options
33
import "github.com/docker/cli/opts"
44

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

1618
// Config holds docker stack config options
19+
//
20+
// Deprecated: this type was for internal use and will be removed in the next release.
1721
type Config struct {
1822
Composefiles []string
1923
SkipInterpolation bool
2024
}
2125

2226
// List holds docker stack ls options
27+
//
28+
// Deprecated: this type was for internal use and will be removed in the next release.
2329
type List struct {
2430
Format string
2531
AllNamespaces bool
2632
}
2733

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

3846
// Remove holds docker stack remove options
47+
//
48+
// Deprecated: this type was for internal use and will be removed in the next release.
3949
type Remove struct {
4050
Namespaces []string
4151
Detach bool
4252
}
4353

4454
// Services holds docker stack services options
55+
//
56+
// Deprecated: this type was for internal use and will be removed in the next release.
4557
type Services struct {
4658
Quiet bool
4759
Format string

cli/command/stack/services.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ import (
1818
"github.com/spf13/cobra"
1919
)
2020

21-
func newServicesCommand(dockerCli command.Cli) *cobra.Command {
22-
opts := options.Services{Filter: cliopts.NewFilterOpt()}
21+
// servicesOptions holds docker stack services options
22+
type servicesOptions = options.Services
23+
24+
func newServicesCommand(dockerCLI command.Cli) *cobra.Command {
25+
opts := servicesOptions{Filter: cliopts.NewFilterOpt()}
2326

2427
cmd := &cobra.Command{
2528
Use: "services [OPTIONS] STACK",
@@ -30,10 +33,10 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command {
3033
if err := validateStackName(opts.Namespace); err != nil {
3134
return err
3235
}
33-
return RunServices(cmd.Context(), dockerCli, opts)
36+
return runServices(cmd.Context(), dockerCLI, opts)
3437
},
3538
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
36-
return completeNames(dockerCli)(cmd, args, toComplete)
39+
return completeNames(dockerCLI)(cmd, args, toComplete)
3740
},
3841
}
3942
flags := cmd.Flags()
@@ -44,15 +47,22 @@ func newServicesCommand(dockerCli command.Cli) *cobra.Command {
4447
}
4548

4649
// RunServices performs a stack services against the specified swarm cluster
47-
func RunServices(ctx context.Context, dockerCli command.Cli, opts options.Services) error {
48-
services, err := swarm.GetServices(ctx, dockerCli, opts)
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+
56+
// 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)
4959
if err != nil {
5060
return err
5161
}
52-
return formatWrite(dockerCli, services, opts)
62+
return formatWrite(dockerCLI, services, opts)
5363
}
5464

55-
func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts options.Services) error {
65+
func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts servicesOptions) error {
5666
// if no services in the stack, print message and exit 0
5767
if len(services) == 0 {
5868
_, _ = fmt.Fprintln(dockerCLI.Err(), "Nothing found in stack:", opts.Namespace)

cli/command/stack/swarm/deploy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const (
2323
)
2424

2525
// RunDeploy is the swarm implementation of docker stack deploy
26+
//
27+
// Deprecated: this function was for internal use and will be removed in the next release.
2628
func RunDeploy(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet, opts *options.Deploy, cfg *composetypes.Config) error {
2729
if err := validateResolveImageFlag(opts); err != nil {
2830
return err

cli/command/stack/swarm/list.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
)
1212

1313
// GetStacks lists the swarm stacks.
14+
//
15+
// Deprecated: this function was for internal use and will be removed in the next release.
1416
func GetStacks(ctx context.Context, apiClient client.ServiceAPIClient) ([]*formatter.Stack, error) {
1517
services, err := apiClient.ServiceList(
1618
ctx,

cli/command/stack/swarm/ps.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
)
1313

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

cli/command/stack/swarm/remove.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import (
1515
)
1616

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

0 commit comments

Comments
 (0)