mirror of
https://github.com/kubernetes-sigs/kind.git
synced 2025-11-30 23:16:04 +07:00
add x-k8s.io namespaced node labels
This commit is contained in:
@@ -20,12 +20,24 @@ package constants
|
||||
// DefaultClusterName is the default cluster Context name
|
||||
const DefaultClusterName = "kind"
|
||||
|
||||
// ClusterLabelKey is applied to each "node" docker container for identification
|
||||
const ClusterLabelKey = "io.k8s.sigs.kind.cluster"
|
||||
// TODO: the requirements for labels may vary by provider, these should probably
|
||||
// be per-provider (though commonly the same)
|
||||
|
||||
// NodeRoleKey is applied to each "node" docker container for categorization
|
||||
// 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 NodeRoleKey = "io.k8s.sigs.kind.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 (
|
||||
|
||||
@@ -37,7 +37,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.NodeRoleKey),
|
||||
"--format", fmt.Sprintf(`{{ index .Config.Labels "%s"}}`, constants.DeprecatedNodeRoleLabelKey),
|
||||
n.name,
|
||||
)
|
||||
lines, err := exec.OutputLines(cmd)
|
||||
|
||||
@@ -78,9 +78,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.ClusterLabelKey,
|
||||
"--filter", "label="+constants.DeprecatedClusterLabelKey,
|
||||
// format to include the cluster name
|
||||
"--format", fmt.Sprintf(`{{.Label "%s"}}`, constants.ClusterLabelKey),
|
||||
"--format", fmt.Sprintf(`{{.Label "%s"}}`, constants.DeprecatedClusterLabelKey),
|
||||
)
|
||||
lines, err := exec.OutputLines(cmd)
|
||||
if err != nil {
|
||||
@@ -97,7 +97,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.ClusterLabelKey, cluster),
|
||||
"--filter", fmt.Sprintf("label=%s=%s", constants.DeprecatedClusterLabelKey, cluster),
|
||||
// format to include the cluster name
|
||||
"--format", `{{.Names}}`,
|
||||
)
|
||||
|
||||
@@ -133,6 +133,7 @@ func commonArgs(cluster string, cfg *config.Cluster) ([]string, error) {
|
||||
"--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),
|
||||
}
|
||||
|
||||
// enable IPv6 if necessary
|
||||
@@ -162,7 +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.NodeRoleKey, node.Role),
|
||||
"--label", fmt.Sprintf("%s=%s", constants.NodeRoleLabelKey, node.Role),
|
||||
"--label", fmt.Sprintf("%s=%s", constants.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
|
||||
@@ -199,7 +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.NodeRoleKey, constants.ExternalLoadBalancerNodeRoleValue),
|
||||
"--label", fmt.Sprintf("%s=%s", constants.DeprecatedNodeRoleLabelKey, constants.ExternalLoadBalancerNodeRoleValue),
|
||||
"--label", fmt.Sprintf("%s=%s", constants.NodeRoleLabelKey, constants.ExternalLoadBalancerNodeRoleValue),
|
||||
},
|
||||
args...,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user