integ/kubernetes/kubernetes-1.25.3/debian/deb_folder/patches/Revert-kubeadm-cleanup-the-...

97 lines
4.0 KiB
Diff

From 094f22ddb7c82523c716b6866c7f9135da6119a6 Mon Sep 17 00:00:00 2001
From: Boovan Rajendran <boovan.rajendran@windriver.com>
Date: Wed, 15 Feb 2023 03:28:16 -0500
Subject: [PATCH] Revert "kubeadm: cleanup the "master" taint on CP nodes
during upgrade"
This partially reverts commit ddd046f3dd88186cbc83b57e83144db96eae4af4.
Signed-off-by: Boovan Rajendran <boovan.rajendran@windriver.com>
---
cmd/kubeadm/app/cmd/upgrade/apply.go | 17 ++++++++
cmd/kubeadm/app/phases/upgrade/postupgrade.go | 40 +++++++++++++++++++
2 files changed, 57 insertions(+)
diff --git a/cmd/kubeadm/app/cmd/upgrade/apply.go b/cmd/kubeadm/app/cmd/upgrade/apply.go
index 4687c5bcdd2..03c1bf19f14 100644
--- a/cmd/kubeadm/app/cmd/upgrade/apply.go
+++ b/cmd/kubeadm/app/cmd/upgrade/apply.go
@@ -158,6 +158,23 @@ func runApply(flags *applyFlags, args []string) error {
return errors.Wrap(err, "[upgrade/apply] FATAL")
}
+ // 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 {
+ return err
+ }
+
// Clean this up in 1.26
// TODO: https://github.com/kubernetes/kubeadm/issues/2200
fmt.Printf("[upgrade/postupgrade] Removing the old taint %s from all control plane Nodes. "+
diff --git a/cmd/kubeadm/app/phases/upgrade/postupgrade.go b/cmd/kubeadm/app/phases/upgrade/postupgrade.go
index eb67ccffaf8..95752b609b7 100644
--- a/cmd/kubeadm/app/phases/upgrade/postupgrade.go
+++ b/cmd/kubeadm/app/phases/upgrade/postupgrade.go
@@ -232,6 +232,46 @@ 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.
+// TODO: https://github.com/kubernetes/kubeadm/issues/2200
+func AddNewControlPlaneTaint(client clientset.Interface) error {
+ selectorControlPlane := labels.SelectorFromSet(labels.Set(map[string]string{
+ kubeadmconstants.LabelNodeRoleControlPlane: "",
+ }))
+ nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
+ LabelSelector: selectorControlPlane.String(),
+ })
+ if err != nil {
+ return errors.Wrapf(err, "could not list nodes labeled with %q", kubeadmconstants.LabelNodeRoleControlPlane)
+ }
+
+ for _, n := range nodes.Items {
+ // Check if the node has the old / new taints
+ hasOldTaint := false
+ hasNewTaint := false
+ for _, t := range n.Spec.Taints {
+ switch t.String() {
+ case kubeadmconstants.OldControlPlaneTaint.String():
+ hasOldTaint = true
+ case kubeadmconstants.ControlPlaneTaint.String():
+ hasNewTaint = true
+ }
+ }
+ // 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 {
+ err = apiclient.PatchNode(client, n.Name, func(n *v1.Node) {
+ n.Spec.Taints = append(n.Spec.Taints, kubeadmconstants.ControlPlaneTaint)
+ })
+ if err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+
// 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
--
2.25.1