github.com/kunnos/engine@v1.13.1/cli/command/stack/common.go (about)

     1  package stack
     2  
     3  import (
     4  	"golang.org/x/net/context"
     5  
     6  	"github.com/docker/docker/api/types"
     7  	"github.com/docker/docker/api/types/filters"
     8  	"github.com/docker/docker/api/types/swarm"
     9  	"github.com/docker/docker/cli/compose/convert"
    10  	"github.com/docker/docker/client"
    11  	"github.com/docker/docker/opts"
    12  )
    13  
    14  func getStackFilter(namespace string) filters.Args {
    15  	filter := filters.NewArgs()
    16  	filter.Add("label", convert.LabelNamespace+"="+namespace)
    17  	return filter
    18  }
    19  
    20  func getStackFilterFromOpt(namespace string, opt opts.FilterOpt) filters.Args {
    21  	filter := opt.Value()
    22  	filter.Add("label", convert.LabelNamespace+"="+namespace)
    23  	return filter
    24  }
    25  
    26  func getAllStacksFilter() filters.Args {
    27  	filter := filters.NewArgs()
    28  	filter.Add("label", convert.LabelNamespace)
    29  	return filter
    30  }
    31  
    32  func getServices(
    33  	ctx context.Context,
    34  	apiclient client.APIClient,
    35  	namespace string,
    36  ) ([]swarm.Service, error) {
    37  	return apiclient.ServiceList(
    38  		ctx,
    39  		types.ServiceListOptions{Filters: getStackFilter(namespace)})
    40  }
    41  
    42  func getStackNetworks(
    43  	ctx context.Context,
    44  	apiclient client.APIClient,
    45  	namespace string,
    46  ) ([]types.NetworkResource, error) {
    47  	return apiclient.NetworkList(
    48  		ctx,
    49  		types.NetworkListOptions{Filters: getStackFilter(namespace)})
    50  }
    51  
    52  func getStackSecrets(
    53  	ctx context.Context,
    54  	apiclient client.APIClient,
    55  	namespace string,
    56  ) ([]swarm.Secret, error) {
    57  	return apiclient.SecretList(
    58  		ctx,
    59  		types.SecretListOptions{Filters: getStackFilter(namespace)})
    60  }