MCPcopy Index your code
hub / github.com/docker/cli / runRemove

Function runRemove

cli/command/stack/remove.go:48–97  ·  view source on GitHub ↗

runRemove is the swarm implementation of docker stack remove.

(ctx context.Context, dockerCli command.Cli, opts removeOptions)

Source from the content-addressed store, hash-verified

46
47// runRemove is the swarm implementation of docker stack remove.
48func runRemove(ctx context.Context, dockerCli command.Cli, opts removeOptions) error {
49 apiClient := dockerCli.Client()
50
51 var errs []error
52 for _, namespace := range opts.namespaces {
53 services, err := getStackServices(ctx, apiClient, namespace)
54 if err != nil {
55 return err
56 }
57
58 networks, err := getStackNetworks(ctx, apiClient, namespace)
59 if err != nil {
60 return err
61 }
62
63 secrets, err := getStackSecrets(ctx, apiClient, namespace)
64 if err != nil {
65 return err
66 }
67
68 configs, err := getStackConfigs(ctx, apiClient, namespace)
69 if err != nil {
70 return err
71 }
72
73 if len(services.Items)+len(networks.Items)+len(secrets.Items)+len(configs.Items) == 0 {
74 _, _ = fmt.Fprintln(dockerCli.Err(), "Nothing found in stack:", namespace)
75 continue
76 }
77
78 // TODO(thaJeztah): change this "hasError" boolean to return a (multi-)error for each of these functions instead.
79 hasError := removeServices(ctx, dockerCli, services.Items)
80 hasError = removeSecrets(ctx, dockerCli, secrets.Items) || hasError
81 hasError = removeConfigs(ctx, dockerCli, configs.Items) || hasError
82 hasError = removeNetworks(ctx, dockerCli, networks.Items) || hasError
83
84 if hasError {
85 errs = append(errs, errors.New("failed to remove some resources from stack: "+namespace))
86 continue
87 }
88
89 if !opts.detach {
90 err = waitOnTasks(ctx, apiClient, namespace)
91 if err != nil {
92 errs = append(errs, fmt.Errorf("failed to wait on tasks of stack: %s: %w", namespace, err))
93 }
94 }
95 }
96 return errors.Join(errs...)
97}
98
99func sortServiceByName(services []swarm.Service) func(i, j int) bool {
100 return func(i, j int) bool {

Callers 1

newRemoveCommandFunction · 0.70

Calls 11

getStackServicesFunction · 0.85
getStackNetworksFunction · 0.85
getStackSecretsFunction · 0.85
getStackConfigsFunction · 0.85
removeServicesFunction · 0.85
removeSecretsFunction · 0.85
removeNetworksFunction · 0.85
waitOnTasksFunction · 0.85
removeConfigsFunction · 0.70
ClientMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…