pruneServices removes services that are no longer referenced in the source
(ctx context.Context, dockerCLI command.Cli, namespace convert.Namespace, services map[string]struct{})
| 111 | |
| 112 | // pruneServices removes services that are no longer referenced in the source |
| 113 | func 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 | } |
searching dependent graphs…