Merge pull request #110095 from neolit123/1.25-update-master-label-taint
kubeadm: cleanup the "master" taint on CP nodes during upgrade
This commit is contained in:
@@ -156,20 +156,13 @@ func runApply(flags *applyFlags, args []string) error {
|
||||
return errors.Wrap(err, "[upgrade/apply] FATAL")
|
||||
}
|
||||
|
||||
// Clean this up in 1.26
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2200
|
||||
fmt.Printf("[upgrade/postupgrade] Removing the deprecated label %s='' from all control plane Nodes. "+
|
||||
"After this step only the label %s='' will be present on control plane Nodes.\n",
|
||||
kubeadmconstants.LabelNodeRoleOldControlPlane, kubeadmconstants.LabelNodeRoleControlPlane)
|
||||
if err := upgrade.RemoveOldControlPlaneLabel(client); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2200
|
||||
fmt.Printf("[upgrade/postupgrade] Adding the new taint %s to all control plane Nodes. "+
|
||||
"After this step both taints %s and %s should be present on control plane Nodes.\n",
|
||||
kubeadmconstants.ControlPlaneTaint.String(), kubeadmconstants.ControlPlaneTaint.String(),
|
||||
kubeadmconstants.OldControlPlaneTaint.String())
|
||||
if err := upgrade.AddNewControlPlaneTaint(client); err != nil {
|
||||
fmt.Printf("[upgrade/postupgrade] Removing the old taint %s from all control plane Nodes. "+
|
||||
"After this step only the %s taint will be present on control plane Nodes.\n",
|
||||
kubeadmconstants.OldControlPlaneTaint.String(),
|
||||
kubeadmconstants.ControlPlaneTaint.String())
|
||||
if err := upgrade.RemoveOldControlPlaneTaint(client); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -231,10 +231,10 @@ func RemoveOldControlPlaneLabel(client clientset.Interface) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddNewControlPlaneTaint finds all nodes with the new "control-plane" node-role label
|
||||
// and adds the new "control-plane" taint to them.
|
||||
// RemoveOldControlPlaneTaint finds all nodes with the new "control-plane" node-role label
|
||||
// and removes the old "control-plane" taint to them.
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2200
|
||||
func AddNewControlPlaneTaint(client clientset.Interface) error {
|
||||
func RemoveOldControlPlaneTaint(client clientset.Interface) error {
|
||||
selectorControlPlane := labels.SelectorFromSet(labels.Set(map[string]string{
|
||||
kubeadmconstants.LabelNodeRoleControlPlane: "",
|
||||
}))
|
||||
@@ -246,22 +246,21 @@ func AddNewControlPlaneTaint(client clientset.Interface) error {
|
||||
}
|
||||
|
||||
for _, n := range nodes.Items {
|
||||
// Check if the node has the old / new taints
|
||||
// Check if the node has the old taint
|
||||
hasOldTaint := false
|
||||
hasNewTaint := false
|
||||
taints := []v1.Taint{}
|
||||
for _, t := range n.Spec.Taints {
|
||||
switch t.String() {
|
||||
case kubeadmconstants.OldControlPlaneTaint.String():
|
||||
if t.String() == kubeadmconstants.OldControlPlaneTaint.String() {
|
||||
hasOldTaint = true
|
||||
case kubeadmconstants.ControlPlaneTaint.String():
|
||||
hasNewTaint = true
|
||||
continue
|
||||
}
|
||||
// Collect all other taints
|
||||
taints = append(taints, t)
|
||||
}
|
||||
// If the old taint is present and the new taint is missing, patch the node with the new taint.
|
||||
// When the old taint is missing, assume the user has manually untainted the node and take no action.
|
||||
if !hasNewTaint && hasOldTaint {
|
||||
// If the old taint is present remove it
|
||||
if hasOldTaint {
|
||||
err = apiclient.PatchNode(client, n.Name, func(n *v1.Node) {
|
||||
n.Spec.Taints = append(n.Spec.Taints, kubeadmconstants.ControlPlaneTaint)
|
||||
n.Spec.Taints = taints
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@@ -105,8 +105,7 @@ func SetNodeRegistrationDynamicDefaults(cfg *kubeadmapi.NodeRegistrationOptions,
|
||||
|
||||
// Only if the slice is nil, we should append the control-plane taint. This allows the user to specify an empty slice for no default control-plane taint
|
||||
if controlPlaneTaint && cfg.Taints == nil {
|
||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2200
|
||||
cfg.Taints = []v1.Taint{kubeadmconstants.OldControlPlaneTaint, kubeadmconstants.ControlPlaneTaint}
|
||||
cfg.Taints = []v1.Taint{kubeadmconstants.ControlPlaneTaint}
|
||||
}
|
||||
|
||||
if cfg.CRISocket == "" {
|
||||
|
@@ -122,7 +122,7 @@ func TestDefaultTaintsMarshaling(t *testing.T) {
|
||||
Kind: constants.InitConfigurationKind,
|
||||
},
|
||||
},
|
||||
expectedTaintCnt: 2,
|
||||
expectedTaintCnt: 1,
|
||||
},
|
||||
{
|
||||
desc: "Uninitialized taints field produces expected taints",
|
||||
@@ -133,7 +133,7 @@ func TestDefaultTaintsMarshaling(t *testing.T) {
|
||||
},
|
||||
NodeRegistration: kubeadmapiv1.NodeRegistrationOptions{},
|
||||
},
|
||||
expectedTaintCnt: 2,
|
||||
expectedTaintCnt: 1,
|
||||
},
|
||||
{
|
||||
desc: "Forsing taints to an empty slice produces no taints",
|
||||
|
Reference in New Issue
Block a user