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

Function pruneServices

cli/command/stack/deploy.go:113–128  ·  view source on GitHub ↗

pruneServices removes services that are no longer referenced in the source

(ctx context.Context, dockerCLI command.Cli, namespace convert.Namespace, services map[string]struct{})

Source from the content-addressed store, hash-verified

111
112// pruneServices removes services that are no longer referenced in the source
113func pruneServices(ctx context.Context, dockerCLI command.Cli, namespace convert.Namespace, services map[string]struct{}) {
114 apiClient := dockerCLI.Client()
115
116 oldServices, err := getStackServices(ctx, apiClient, namespace.Name())
117 if err != nil {
118 _, _ = fmt.Fprintln(dockerCLI.Err(), "Failed to list services:", err)
119 }
120
121 toRemove := make([]swarm.Service, 0, len(oldServices.Items))
122 for _, service := range oldServices.Items {
123 if _, exists := services[namespace.Descope(service.Spec.Name)]; !exists {
124 toRemove = append(toRemove, service)
125 }
126 }
127 removeServices(ctx, dockerCLI, toRemove)
128}

Callers 2

deployComposeFunction · 0.85
TestPruneServicesFunction · 0.85

Calls 6

getStackServicesFunction · 0.85
removeServicesFunction · 0.85
DescopeMethod · 0.80
ClientMethod · 0.65
ErrMethod · 0.65
NameMethod · 0.45

Tested by 1

TestPruneServicesFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…