mirror of
https://github.com/kubernetes-sigs/kind.git
synced 2025-12-01 07:26:05 +07:00
add node roles to pkg/cluster/constants
This commit is contained in:
@@ -23,5 +23,34 @@ const DefaultClusterName = "kind"
|
||||
// ClusterLabelKey is applied to each "node" docker container for identification
|
||||
const ClusterLabelKey = "io.k8s.sigs.kind.cluster"
|
||||
|
||||
// ClusterRoleKey is applied to each "node" docker container for categorization of nodes by role
|
||||
const ClusterRoleKey = "io.k8s.sigs.kind.role"
|
||||
// NodeRoleKey is applied to each "node" docker container for categorization
|
||||
// of nodes by role
|
||||
const NodeRoleKey = "io.k8s.sigs.kind.role"
|
||||
|
||||
/* node role value constants */
|
||||
const (
|
||||
// ControlPlaneNodeRoleValue identifies a node that hosts a Kubernetes
|
||||
// control-plane.
|
||||
//
|
||||
// NOTE: in single node clusters, control-plane nodes act as worker nodes
|
||||
ControlPlaneNodeRoleValue string = "control-plane"
|
||||
|
||||
// WorkerNodeRoleValue identifies a node that hosts a Kubernetes worker
|
||||
WorkerNodeRoleValue string = "worker"
|
||||
|
||||
// ExternalLoadBalancerNodeRoleValue identifies a node that hosts an
|
||||
// external load balancer for the API server in HA configurations.
|
||||
//
|
||||
// Please note that `kind` nodes hosting external load balancer are not
|
||||
// kubernetes nodes
|
||||
ExternalLoadBalancerNodeRoleValue string = "external-load-balancer"
|
||||
|
||||
// ExternalEtcdNodeRoleValue identifies a node that hosts an external-etcd
|
||||
// instance.
|
||||
//
|
||||
// WARNING: this node type is not yet implemented!
|
||||
//
|
||||
// Please note that `kind` nodes hosting external etcd are not
|
||||
// kubernetes nodes
|
||||
ExternalEtcdNodeRoleValue string = "external-etcd"
|
||||
)
|
||||
|
||||
@@ -22,6 +22,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"sigs.k8s.io/kind/pkg/cluster/constants"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
@@ -140,12 +142,13 @@ func (cc *Context) ProvisionNodes() (nodeList map[string]*nodes.Node, err error)
|
||||
var name = fmt.Sprintf("%s-%s", cc.Name(), configNode.Name)
|
||||
var node *nodes.Node
|
||||
|
||||
switch configNode.Role {
|
||||
case config.ExternalLoadBalancerRole:
|
||||
// TODO(bentheelder): decouple from config objects further
|
||||
switch string(configNode.Role) {
|
||||
case constants.ExternalLoadBalancerNodeRoleValue:
|
||||
node, err = nodes.CreateExternalLoadBalancerNode(name, configNode.Image, cc.ClusterLabel())
|
||||
case config.ControlPlaneRole:
|
||||
case constants.ControlPlaneNodeRoleValue:
|
||||
node, err = nodes.CreateControlPlaneNode(name, configNode.Image, cc.ClusterLabel(), configNode.ExtraMounts)
|
||||
case config.WorkerRole:
|
||||
case constants.WorkerNodeRoleValue:
|
||||
node, err = nodes.CreateWorkerNode(name, configNode.Image, cc.ClusterLabel(), configNode.ExtraMounts)
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -130,7 +130,7 @@ func createNode(name, image, clusterLabel string, role config.NodeRole, mounts [
|
||||
// label the node with the cluster ID
|
||||
"--label", clusterLabel,
|
||||
// label the node with the role ID
|
||||
"--label", fmt.Sprintf("%s=%s", constants.ClusterRoleKey, role),
|
||||
"--label", fmt.Sprintf("%s=%s", constants.NodeRoleKey, role),
|
||||
// explicitly set the entrypoint
|
||||
"--entrypoint=/usr/local/bin/entrypoint",
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/version"
|
||||
"sigs.k8s.io/kind/pkg/cluster/config"
|
||||
"sigs.k8s.io/kind/pkg/cluster/constants"
|
||||
|
||||
"sigs.k8s.io/kind/pkg/container/docker"
|
||||
@@ -72,7 +71,7 @@ type nodeCache struct {
|
||||
kubernetesVersion string
|
||||
ip string
|
||||
ports map[int]int
|
||||
role config.NodeRole
|
||||
role string
|
||||
containerCmder exec.Cmder
|
||||
}
|
||||
|
||||
@@ -264,20 +263,20 @@ func (n *Node) Ports(containerPort int) (hostPort int, err error) {
|
||||
}
|
||||
|
||||
// Role returns the role of the node
|
||||
func (n *Node) Role() (role config.NodeRole, err error) {
|
||||
func (n *Node) Role() (role string, err error) {
|
||||
// use the cached version first
|
||||
if n.nodeCache.role != "" {
|
||||
return n.nodeCache.role, nil
|
||||
}
|
||||
// retrive the role the node using docker inspect
|
||||
lines, err := docker.Inspect(n.nameOrID, fmt.Sprintf("{{index .Config.Labels %q}}", constants.ClusterRoleKey))
|
||||
lines, err := docker.Inspect(n.nameOrID, fmt.Sprintf("{{index .Config.Labels %q}}", constants.NodeRoleKey))
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "failed to get %q label", constants.ClusterRoleKey)
|
||||
return "", errors.Wrapf(err, "failed to get %q label", constants.NodeRoleKey)
|
||||
}
|
||||
if len(lines) != 1 {
|
||||
return "", errors.Errorf("%q label should only be one line, got %d lines", constants.ClusterRoleKey, len(lines))
|
||||
return "", errors.Errorf("%q label should only be one line, got %d lines", constants.NodeRoleKey, len(lines))
|
||||
}
|
||||
n.nodeCache.role = config.NodeRole(strings.Trim(lines[0], "'"))
|
||||
n.nodeCache.role = strings.Trim(lines[0], "'")
|
||||
return n.nodeCache.role, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user