mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
4609c728e3
If the network is marked as external, don't use the namespace on
it. Otherwise, it's not found.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
(cherry picked from commit 6fff845409
)
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package stack
|
|
|
|
import (
|
|
"golang.org/x/net/context"
|
|
|
|
"github.com/docker/docker/api/types"
|
|
"github.com/docker/docker/api/types/filters"
|
|
"github.com/docker/docker/api/types/swarm"
|
|
"github.com/docker/docker/client"
|
|
)
|
|
|
|
const (
|
|
labelNamespace = "com.docker.stack.namespace"
|
|
)
|
|
|
|
func getStackLabels(namespace string, labels map[string]string) map[string]string {
|
|
if labels == nil {
|
|
labels = make(map[string]string)
|
|
}
|
|
labels[labelNamespace] = namespace
|
|
return labels
|
|
}
|
|
|
|
func getStackFilter(namespace string) filters.Args {
|
|
filter := filters.NewArgs()
|
|
filter.Add("label", labelNamespace+"="+namespace)
|
|
return filter
|
|
}
|
|
|
|
func getServices(
|
|
ctx context.Context,
|
|
apiclient client.APIClient,
|
|
namespace string,
|
|
) ([]swarm.Service, error) {
|
|
return apiclient.ServiceList(
|
|
ctx,
|
|
types.ServiceListOptions{Filters: getStackFilter(namespace)})
|
|
}
|
|
|
|
func getStackNetworks(
|
|
ctx context.Context,
|
|
apiclient client.APIClient,
|
|
namespace string,
|
|
) ([]types.NetworkResource, error) {
|
|
return apiclient.NetworkList(
|
|
ctx,
|
|
types.NetworkListOptions{Filters: getStackFilter(namespace)})
|
|
}
|
|
|
|
type namespace struct {
|
|
name string
|
|
}
|
|
|
|
func (n namespace) scope(name string) string {
|
|
return n.name + "_" + name
|
|
}
|