mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
deprecate the "node-role.kubernetes.io/master" label / taint
Related to https://github.com/kubernetes/kubernetes/pull/95382 Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
parent
c6950d2cb0
commit
63f2211b31
@ -100,6 +100,9 @@ spec:
|
|||||||
tolerations:
|
tolerations:
|
||||||
- key: "CriticalAddonsOnly"
|
- key: "CriticalAddonsOnly"
|
||||||
operator: "Exists"
|
operator: "Exists"
|
||||||
|
- key: "node-role.kubernetes.io/control-plane"
|
||||||
|
operator: "Exists"
|
||||||
|
effect: "NoSchedule"
|
||||||
- key: "node-role.kubernetes.io/master"
|
- key: "node-role.kubernetes.io/master"
|
||||||
operator: "Exists"
|
operator: "Exists"
|
||||||
effect: "NoSchedule"
|
effect: "NoSchedule"
|
||||||
|
@ -55,6 +55,9 @@ spec:
|
|||||||
tolerations:
|
tolerations:
|
||||||
- key: "CriticalAddonsOnly"
|
- key: "CriticalAddonsOnly"
|
||||||
operator: "Exists"
|
operator: "Exists"
|
||||||
|
- key: "node-role.kubernetes.io/control-plane"
|
||||||
|
operator: "Exists"
|
||||||
|
effect: "NoSchedule"
|
||||||
- key: "node-role.kubernetes.io/master"
|
- key: "node-role.kubernetes.io/master"
|
||||||
operator: "Exists"
|
operator: "Exists"
|
||||||
effect: "NoSchedule"
|
effect: "NoSchedule"
|
||||||
|
@ -27,6 +27,9 @@ spec:
|
|||||||
tolerations:
|
tolerations:
|
||||||
- key: "CriticalAddonsOnly"
|
- key: "CriticalAddonsOnly"
|
||||||
operator: "Exists"
|
operator: "Exists"
|
||||||
|
- key: "node-role.kubernetes.io/control-plane"
|
||||||
|
operator: "Exists"
|
||||||
|
effect: "NoSchedule"
|
||||||
- key: "node-role.kubernetes.io/master"
|
- key: "node-role.kubernetes.io/master"
|
||||||
operator: "Exists"
|
operator: "Exists"
|
||||||
effect: "NoSchedule"
|
effect: "NoSchedule"
|
||||||
|
@ -21,6 +21,9 @@ spec:
|
|||||||
tolerations:
|
tolerations:
|
||||||
- key: "CriticalAddonsOnly"
|
- key: "CriticalAddonsOnly"
|
||||||
operator: "Exists"
|
operator: "Exists"
|
||||||
|
- key: "node-role.kubernetes.io/control-plane"
|
||||||
|
operator: "Exists"
|
||||||
|
effect: "NoSchedule"
|
||||||
- key: "node-role.kubernetes.io/master"
|
- key: "node-role.kubernetes.io/master"
|
||||||
operator: "Exists"
|
operator: "Exists"
|
||||||
effect: "NoSchedule"
|
effect: "NoSchedule"
|
||||||
|
File diff suppressed because one or more lines are too long
@ -11,10 +11,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
nodeID = "etcd.k3s.cattle.io/node-name"
|
nodeID = "etcd.k3s.cattle.io/node-name"
|
||||||
nodeAddress = "etcd.k3s.cattle.io/node-address"
|
nodeAddress = "etcd.k3s.cattle.io/node-address"
|
||||||
master = "node-role.kubernetes.io/master"
|
controlPlane = "node-role.kubernetes.io/control-plane"
|
||||||
etcdRole = "node-role.kubernetes.io/etcd"
|
etcdRole = "node-role.kubernetes.io/etcd"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeControllerGetter func() controllerv1.NodeController
|
type NodeControllerGetter func() controllerv1.NodeController
|
||||||
@ -58,7 +58,7 @@ func (h *handler) handleSelf(node *v1.Node) (*v1.Node, error) {
|
|||||||
if node.Annotations[nodeID] == h.etcd.name &&
|
if node.Annotations[nodeID] == h.etcd.name &&
|
||||||
node.Annotations[nodeAddress] == h.etcd.address &&
|
node.Annotations[nodeAddress] == h.etcd.address &&
|
||||||
node.Labels[etcdRole] == "true" &&
|
node.Labels[etcdRole] == "true" &&
|
||||||
node.Labels[master] == "true" {
|
node.Labels[controlPlane] == "true" {
|
||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ func (h *handler) handleSelf(node *v1.Node) (*v1.Node, error) {
|
|||||||
node.Annotations[nodeID] = h.etcd.name
|
node.Annotations[nodeID] = h.etcd.name
|
||||||
node.Annotations[nodeAddress] = h.etcd.address
|
node.Annotations[nodeAddress] = h.etcd.address
|
||||||
node.Labels[etcdRole] = "true"
|
node.Labels[etcdRole] = "true"
|
||||||
node.Labels[master] = "true"
|
node.Labels[controlPlane] = "true"
|
||||||
|
|
||||||
return h.nodeController.Update(node)
|
return h.nodeController.Update(node)
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,10 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/util/net"
|
"k8s.io/apimachinery/pkg/util/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MasterRoleLabelKey = "node-role.kubernetes.io/master"
|
const (
|
||||||
|
MasterRoleLabelKey = "node-role.kubernetes.io/master"
|
||||||
|
ControlPlaneRoleLabelKey = "node-role.kubernetes.io/control-plane"
|
||||||
|
)
|
||||||
|
|
||||||
func resolveDataDir(dataDir string) (string, error) {
|
func resolveDataDir(dataDir string) (string, error) {
|
||||||
dataDir, err := datadir.Resolve(dataDir)
|
dataDir, err := datadir.Resolve(dataDir)
|
||||||
@ -117,7 +120,7 @@ func runControllers(ctx context.Context, config *Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
start := func(ctx context.Context) {
|
start := func(ctx context.Context) {
|
||||||
if err := masterControllers(ctx, sc, config); err != nil {
|
if err := coreControllers(ctx, sc, config); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
if err := sc.Start(ctx); err != nil {
|
if err := sc.Start(ctx); err != nil {
|
||||||
@ -130,7 +133,7 @@ func runControllers(ctx context.Context, config *Config) error {
|
|||||||
controlConfig.Runtime.Handler = handler
|
controlConfig.Runtime.Handler = handler
|
||||||
}
|
}
|
||||||
if !config.DisableAgent {
|
if !config.DisableAgent {
|
||||||
go setMasterRoleLabel(ctx, sc.Core.Core().V1().Node())
|
go setControlPlaneRoleLabel(ctx, sc.Core.Core().V1().Node())
|
||||||
}
|
}
|
||||||
|
|
||||||
go setClusterDNSConfig(ctx, config, sc.Core.Core().V1().ConfigMap())
|
go setClusterDNSConfig(ctx, config, sc.Core.Core().V1().ConfigMap())
|
||||||
@ -148,7 +151,7 @@ func runControllers(ctx context.Context, config *Config) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func masterControllers(ctx context.Context, sc *Context, config *Config) error {
|
func coreControllers(ctx context.Context, sc *Context, config *Config) error {
|
||||||
if err := nodepassword.MigrateFile(
|
if err := nodepassword.MigrateFile(
|
||||||
sc.Core.Core().V1().Secret(),
|
sc.Core.Core().V1().Secret(),
|
||||||
sc.Core.Core().V1().Node(),
|
sc.Core.Core().V1().Node(),
|
||||||
@ -419,25 +422,26 @@ func isSymlink(config string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func setMasterRoleLabel(ctx context.Context, nodes v1.NodeClient) error {
|
func setControlPlaneRoleLabel(ctx context.Context, nodes v1.NodeClient) error {
|
||||||
for {
|
for {
|
||||||
nodeName := os.Getenv("NODE_NAME")
|
nodeName := os.Getenv("NODE_NAME")
|
||||||
node, err := nodes.Get(nodeName, metav1.GetOptions{})
|
node, err := nodes.Get(nodeName, metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Infof("Waiting for master node %s startup: %v", nodeName, err)
|
logrus.Infof("Waiting for control-plane node %s startup: %v", nodeName, err)
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if v, ok := node.Labels[MasterRoleLabelKey]; ok && v == "true" {
|
if v, ok := node.Labels[ControlPlaneRoleLabelKey]; ok && v == "true" {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if node.Labels == nil {
|
if node.Labels == nil {
|
||||||
node.Labels = make(map[string]string)
|
node.Labels = make(map[string]string)
|
||||||
}
|
}
|
||||||
|
node.Labels[ControlPlaneRoleLabelKey] = "true"
|
||||||
node.Labels[MasterRoleLabelKey] = "true"
|
node.Labels[MasterRoleLabelKey] = "true"
|
||||||
_, err = nodes.Update(node)
|
_, err = nodes.Update(node)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
logrus.Infof("Master role label has been set successfully on node: %s", nodeName)
|
logrus.Infof("Control-plane role label has been set successfully on node: %s", nodeName)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
select {
|
select {
|
||||||
@ -479,7 +483,7 @@ func setClusterDNSConfig(ctx context.Context, controlConfig *Config, configMap v
|
|||||||
logrus.Infof("Cluster dns configmap has been set successfully")
|
logrus.Infof("Cluster dns configmap has been set successfully")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
logrus.Infof("Waiting for master node %s startup: %v", nodeName, err)
|
logrus.Infof("Waiting for control-plane node %s startup: %v", nodeName, err)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
|
@ -362,12 +362,20 @@ func (h *handler) newDaemonSet(svc *core.Service) (*apps.DaemonSet, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add toleration to noderole.kubernetes.io/master=*:NoSchedule
|
// Add toleration to noderole.kubernetes.io/master=*:NoSchedule
|
||||||
noScheduleToleration := core.Toleration{
|
masterToleration := core.Toleration{
|
||||||
Key: "node-role.kubernetes.io/master",
|
Key: "node-role.kubernetes.io/master",
|
||||||
Operator: "Exists",
|
Operator: "Exists",
|
||||||
Effect: "NoSchedule",
|
Effect: "NoSchedule",
|
||||||
}
|
}
|
||||||
ds.Spec.Template.Spec.Tolerations = append(ds.Spec.Template.Spec.Tolerations, noScheduleToleration)
|
ds.Spec.Template.Spec.Tolerations = append(ds.Spec.Template.Spec.Tolerations, masterToleration)
|
||||||
|
|
||||||
|
// Add toleration to noderole.kubernetes.io/control-plane=*:NoSchedule
|
||||||
|
controlPlaneToleration := core.Toleration{
|
||||||
|
Key: "node-role.kubernetes.io/control-plane",
|
||||||
|
Operator: "Exists",
|
||||||
|
Effect: "NoSchedule",
|
||||||
|
}
|
||||||
|
ds.Spec.Template.Spec.Tolerations = append(ds.Spec.Template.Spec.Tolerations, controlPlaneToleration)
|
||||||
|
|
||||||
// Add toleration to CriticalAddonsOnly
|
// Add toleration to CriticalAddonsOnly
|
||||||
criticalAddonsOnlyToleration := core.Toleration{
|
criticalAddonsOnlyToleration := core.Toleration{
|
||||||
|
Loading…
Reference in New Issue
Block a user