1
0
mirror of https://github.com/docker/cli.git synced 2025-09-02 10:21:16 +03:00

Move /cli/command/stack/kubernetes/api to /kubernetes

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester
2017-12-04 09:44:06 +01:00
committed by Silvin Lubecki
parent 1ff277ad8f
commit f960d2d5f3
37 changed files with 22 additions and 22 deletions

View File

@@ -0,0 +1,58 @@
package labels
import (
"fmt"
"strings"
)
const (
// ForServiceName is the label for the service name.
ForServiceName = "com.docker.service.name"
// ForStackName is the label for the stack name.
ForStackName = "com.docker.stack.namespace"
// ForServiceID is the label for the service id.
ForServiceID = "com.docker.service.id"
)
// ForService gives the labels to select a given service in a stack.
func ForService(stackName, serviceName string) map[string]string {
labels := map[string]string{}
if serviceName != "" {
labels[ForServiceName] = serviceName
}
if stackName != "" {
labels[ForStackName] = stackName
}
if serviceName != "" && stackName != "" {
labels[ForServiceID] = stackName + "-" + serviceName
}
return labels
}
// Merge merges multiple lists of labels.
func Merge(labelsList ...map[string]string) map[string]string {
merged := map[string]string{}
for _, labels := range labelsList {
for k, v := range labels {
merged[k] = v
}
}
return merged
}
// SelectorForStack gives the labelSelector to use for a given stack.
// Specific service names can be passed to narrow down the selection.
func SelectorForStack(stackName string, serviceNames ...string) string {
switch len(serviceNames) {
case 0:
return fmt.Sprintf("%s=%s", ForStackName, stackName)
case 1:
return fmt.Sprintf("%s=%s,%s=%s", ForStackName, stackName, ForServiceName, serviceNames[0])
default:
return fmt.Sprintf("%s=%s,%s in (%s)", ForStackName, stackName, ForServiceName, strings.Join(serviceNames, ","))
}
}