func getStacks( ctx context.Context, apiclient client.APIClient, ) ([]*stack, error) { services, err := apiclient.ServiceList( ctx, types.ServiceListOptions{Filters: getAllStacksFilter()}) if err != nil { return nil, err } m := make(map[string]*stack, 0) for _, service := range services { labels := service.Spec.Labels name, ok := labels[convert.LabelNamespace] if !ok { return nil, fmt.Errorf("cannot get label %s for service %s", convert.LabelNamespace, service.ID) } ztack, ok := m[name] if !ok { m[name] = &stack{ Name: name, Services: 1, } } else { ztack.Services++ } } var stacks []*stack for _, stack := range m { stacks = append(stacks, stack) } return stacks, nil }
func getServices( ctx context.Context, apiclient client.APIClient, namespace string, ) ([]swarm.Service, error) { return apiclient.ServiceList( ctx, types.ServiceListOptions{Filter: getStackFilter(namespace)}) }