mirror of
https://github.com/kubernetes-sigs/kind.git
synced 2025-11-30 23:16:04 +07:00
move label keys into docker provider
This commit is contained in:
@@ -20,25 +20,6 @@ package constants
|
||||
// DefaultClusterName is the default cluster Context name
|
||||
const DefaultClusterName = "kind"
|
||||
|
||||
// TODO: the requirements for labels may vary by provider, these should probably
|
||||
// be per-provider (though commonly the same)
|
||||
|
||||
// ClusterLabelKey is applied to each "node" docker container for identification
|
||||
const ClusterLabelKey = "io.x-k8s.kind.cluster"
|
||||
|
||||
// DeprecatedClusterLabelKey is applied to each "node" docker container for identification
|
||||
// This is the deprecated value of ClusterLabelKey, and will be removed in a future release
|
||||
const DeprecatedClusterLabelKey = "io.k8s.sigs.kind.cluster"
|
||||
|
||||
// NodeRoleLabelKey is applied to each "node" docker container for categorization
|
||||
// of nodes by role
|
||||
const NodeRoleLabelKey = "io.x-k8s.kind.role"
|
||||
|
||||
// DeprecatedNodeRoleLabelKey is applied to each "node" docker container for categorization
|
||||
// of nodes by role.
|
||||
// This is the deprecated value of NodeRoleKey, and will be removed in a future release
|
||||
const DeprecatedNodeRoleLabelKey = "io.k8s.sigs.kind.role"
|
||||
|
||||
/* node role value constants */
|
||||
const (
|
||||
// ControlPlaneNodeRoleValue identifies a node that hosts a Kubernetes
|
||||
|
||||
33
pkg/internal/cluster/providers/docker/constants.go
Normal file
33
pkg/internal/cluster/providers/docker/constants.go
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or impliep.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package docker
|
||||
|
||||
// clusterLabelKey is applied to each "node" docker container for identification
|
||||
const clusterLabelKey = "io.x-k8s.kind.cluster"
|
||||
|
||||
// deprecatedClusterLabelKey is applied to each "node" docker container for identification
|
||||
// This is the deprecated value of ClusterLabelKey, and will be removed in a future release
|
||||
const deprecatedClusterLabelKey = "io.k8s.sigs.kind.cluster"
|
||||
|
||||
// nodeRoleLabelKey is applied to each "node" docker container for categorization
|
||||
// of nodes by role
|
||||
const nodeRoleLabelKey = "io.x-k8s.kind.role"
|
||||
|
||||
// DeprecatedNodeRoleLabelKey is applied to each "node" docker container for categorization
|
||||
// of nodes by role.
|
||||
// This is the deprecated value of NodeRoleKey, and will be removed in a future release
|
||||
const deprecatedNodeRoleLabelKey = "io.k8s.sigs.kind.role"
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kind/pkg/cluster/constants"
|
||||
"sigs.k8s.io/kind/pkg/errors"
|
||||
"sigs.k8s.io/kind/pkg/exec"
|
||||
)
|
||||
@@ -37,7 +36,7 @@ func (n *node) String() string {
|
||||
|
||||
func (n *node) Role() (string, error) {
|
||||
cmd := exec.Command("docker", "inspect",
|
||||
"--format", fmt.Sprintf(`{{ index .Config.Labels "%s"}}`, constants.DeprecatedNodeRoleLabelKey),
|
||||
"--format", fmt.Sprintf(`{{ index .Config.Labels "%s"}}`, deprecatedNodeRoleLabelKey),
|
||||
n.name,
|
||||
)
|
||||
lines, err := exec.OutputLines(cmd)
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
|
||||
"sigs.k8s.io/kind/pkg/cluster/constants"
|
||||
"sigs.k8s.io/kind/pkg/cluster/nodes"
|
||||
"sigs.k8s.io/kind/pkg/errors"
|
||||
"sigs.k8s.io/kind/pkg/exec"
|
||||
@@ -78,9 +77,9 @@ func (p *Provider) ListClusters() ([]string, error) {
|
||||
"-a", // show stopped nodes
|
||||
"--no-trunc", // don't truncate
|
||||
// filter for nodes with the cluster label
|
||||
"--filter", "label="+constants.DeprecatedClusterLabelKey,
|
||||
"--filter", "label="+deprecatedClusterLabelKey,
|
||||
// format to include the cluster name
|
||||
"--format", fmt.Sprintf(`{{.Label "%s"}}`, constants.DeprecatedClusterLabelKey),
|
||||
"--format", fmt.Sprintf(`{{.Label "%s"}}`, deprecatedClusterLabelKey),
|
||||
)
|
||||
lines, err := exec.OutputLines(cmd)
|
||||
if err != nil {
|
||||
@@ -97,7 +96,7 @@ func (p *Provider) ListNodes(cluster string) ([]nodes.Node, error) {
|
||||
"-a", // show stopped nodes
|
||||
"--no-trunc", // don't truncate
|
||||
// filter for nodes with the cluster label
|
||||
"--filter", fmt.Sprintf("label=%s=%s", constants.DeprecatedClusterLabelKey, cluster),
|
||||
"--filter", fmt.Sprintf("label=%s=%s", deprecatedClusterLabelKey, cluster),
|
||||
// format to include the cluster name
|
||||
"--format", `{{.Names}}`,
|
||||
)
|
||||
|
||||
@@ -132,8 +132,8 @@ func commonArgs(cluster string, cfg *config.Cluster) ([]string, error) {
|
||||
"--detach", // run the container detached
|
||||
"--tty", // allocate a tty for entrypoint logs
|
||||
// label the node with the cluster ID
|
||||
"--label", fmt.Sprintf("%s=%s", constants.ClusterLabelKey, cluster),
|
||||
"--label", fmt.Sprintf("%s=%s", constants.DeprecatedClusterLabelKey, cluster),
|
||||
"--label", fmt.Sprintf("%s=%s", clusterLabelKey, cluster),
|
||||
"--label", fmt.Sprintf("%s=%s", deprecatedClusterLabelKey, cluster),
|
||||
}
|
||||
|
||||
// enable IPv6 if necessary
|
||||
@@ -163,8 +163,8 @@ func runArgsForNode(node *config.Node, name string, args []string) []string {
|
||||
"--hostname", name, // make hostname match container name
|
||||
"--name", name, // ... and set the container name
|
||||
// label the node with the role ID
|
||||
"--label", fmt.Sprintf("%s=%s", constants.NodeRoleLabelKey, node.Role),
|
||||
"--label", fmt.Sprintf("%s=%s", constants.DeprecatedNodeRoleLabelKey, node.Role),
|
||||
"--label", fmt.Sprintf("%s=%s", nodeRoleLabelKey, node.Role),
|
||||
"--label", fmt.Sprintf("%s=%s", deprecatedNodeRoleLabelKey, node.Role),
|
||||
// running containers in a container requires privileged
|
||||
// NOTE: we could try to replicate this with --cap-add, and use less
|
||||
// privileges, but this flag also changes some mounts that are necessary
|
||||
@@ -201,8 +201,8 @@ func runArgsForLoadBalancer(cfg *config.Cluster, name string, args []string) ([]
|
||||
"--hostname", name, // make hostname match container name
|
||||
"--name", name, // ... and set the container name
|
||||
// label the node with the role ID
|
||||
"--label", fmt.Sprintf("%s=%s", constants.DeprecatedNodeRoleLabelKey, constants.ExternalLoadBalancerNodeRoleValue),
|
||||
"--label", fmt.Sprintf("%s=%s", constants.NodeRoleLabelKey, constants.ExternalLoadBalancerNodeRoleValue),
|
||||
"--label", fmt.Sprintf("%s=%s", deprecatedNodeRoleLabelKey, constants.ExternalLoadBalancerNodeRoleValue),
|
||||
"--label", fmt.Sprintf("%s=%s", nodeRoleLabelKey, constants.ExternalLoadBalancerNodeRoleValue),
|
||||
},
|
||||
args...,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user