getStacks lists the swarm stacks with the number of services they contain.
(ctx context.Context, apiClient client.ServiceAPIClient)
| 10 | |
| 11 | // getStacks lists the swarm stacks with the number of services they contain. |
| 12 | func 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 | } |
no test coverage detected
searching dependent graphs…