Functions and types in this package were exported as part of the "compose on kubernetes" feature, which was deprecated and removed. These functions are meant for internal use, and will be removed in the next release. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package swarm
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/docker/cli/cli/command/stack/formatter"
|
|
"github.com/docker/cli/cli/compose/convert"
|
|
"github.com/moby/moby/client"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// GetStacks lists the swarm stacks.
|
|
//
|
|
// Deprecated: this function was for internal use and will be removed in the next release.
|
|
func GetStacks(ctx context.Context, apiClient client.ServiceAPIClient) ([]*formatter.Stack, error) {
|
|
services, err := apiClient.ServiceList(
|
|
ctx,
|
|
client.ServiceListOptions{Filters: getAllStacksFilter()})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
m := make(map[string]*formatter.Stack)
|
|
for _, service := range services {
|
|
labels := service.Spec.Labels
|
|
name, ok := labels[convert.LabelNamespace]
|
|
if !ok {
|
|
return nil, errors.Errorf("cannot get label %s for service %s",
|
|
convert.LabelNamespace, service.ID)
|
|
}
|
|
ztack, ok := m[name]
|
|
if !ok {
|
|
m[name] = &formatter.Stack{
|
|
Name: name,
|
|
Services: 1,
|
|
}
|
|
} else {
|
|
ztack.Services++
|
|
}
|
|
}
|
|
stacks := make([]*formatter.Stack, 0, len(m))
|
|
for _, stack := range m {
|
|
stacks = append(stacks, stack)
|
|
}
|
|
return stacks, nil
|
|
}
|