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

Function getStacks

cli/command/stack/list_utils.go:12–36  ·  view source on GitHub ↗

getStacks lists the swarm stacks with the number of services they contain.

(ctx context.Context, apiClient client.ServiceAPIClient)

Source from the content-addressed store, hash-verified

10
11// getStacks lists the swarm stacks with the number of services they contain.
12func getStacks(ctx context.Context, apiClient client.ServiceAPIClient) ([]stackSummary, error) {
13 res, err := apiClient.ServiceList(ctx, client.ServiceListOptions{
14 Filters: getAllStacksFilter(),
15 })
16 if err != nil {
17 return nil, err
18 }
19
20 idx := make(map[string]int, len(res.Items))
21 out := make([]stackSummary, 0, len(res.Items))
22
23 for _, svc := range res.Items {
24 name, ok := svc.Spec.Labels[convert.LabelNamespace]
25 if !ok {
26 return nil, errors.New("cannot get label " + convert.LabelNamespace + " for service " + svc.ID)
27 }
28 if i, ok := idx[name]; ok {
29 out[i].Services++
30 continue
31 }
32 idx[name] = len(out)
33 out = append(out, stackSummary{Name: name, Services: 1})
34 }
35 return out, nil
36}

Callers 2

completeNamesFunction · 0.85
runListFunction · 0.85

Calls 2

getAllStacksFilterFunction · 0.85
ServiceListMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…