mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
kubeadm: delete the old "master" label during upgrade
- Rename the function in postupgrade.go to better reflect what is being done. - During "upgrade apply" find all nodes with the old label and remove it by calling PatchNode. - Update health check for CP nodes to not track "master" labeled nodes. At this point all CP nodes should have "control-plane" and we can use that selector only.
This commit is contained in:
parent
7dd03c8326
commit
c0871b4433
@ -64,7 +64,7 @@ var (
|
|||||||
|
|
||||||
* Certificate signing request was sent to apiserver and approval was received.
|
* Certificate signing request was sent to apiserver and approval was received.
|
||||||
* The Kubelet was informed of the new secure connection details.
|
* The Kubelet was informed of the new secure connection details.
|
||||||
* Control plane (master) label and taint were applied to the new node.
|
* Control plane label and taint were applied to the new node.
|
||||||
* The Kubernetes control plane instances scaled up.
|
* The Kubernetes control plane instances scaled up.
|
||||||
{{.etcdMessage}}
|
{{.etcdMessage}}
|
||||||
|
|
||||||
|
@ -157,9 +157,10 @@ func runApply(flags *applyFlags, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2200
|
// TODO: https://github.com/kubernetes/kubeadm/issues/2200
|
||||||
fmt.Printf("[upgrade/postupgrade] Applying label %s='' to Nodes with label %s='' (deprecated)\n",
|
fmt.Printf("[upgrade/postupgrade] Removing the deprecated label %s='' from all control plane Nodes. "+
|
||||||
kubeadmconstants.LabelNodeRoleControlPlane, kubeadmconstants.LabelNodeRoleOldControlPlane)
|
"After this step only the label %s='' will be present on control plane Nodes.\n",
|
||||||
if err := upgrade.LabelOldControlPlaneNodes(client); err != nil {
|
kubeadmconstants.LabelNodeRoleOldControlPlane, kubeadmconstants.LabelNodeRoleControlPlane)
|
||||||
|
if err := upgrade.RemoveOldControlPlaneLabel(client); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,34 +212,17 @@ func deleteHealthCheckJob(client clientset.Interface, ns, jobName string) error
|
|||||||
|
|
||||||
// controlPlaneNodesReady checks whether all control-plane Nodes in the cluster are in the Running state
|
// controlPlaneNodesReady checks whether all control-plane Nodes in the cluster are in the Running state
|
||||||
func controlPlaneNodesReady(client clientset.Interface, _ *kubeadmapi.ClusterConfiguration) error {
|
func controlPlaneNodesReady(client clientset.Interface, _ *kubeadmapi.ClusterConfiguration) error {
|
||||||
// list nodes labeled with a "master" node-role
|
|
||||||
selectorOldControlPlane := labels.SelectorFromSet(labels.Set(map[string]string{
|
|
||||||
constants.LabelNodeRoleOldControlPlane: "",
|
|
||||||
}))
|
|
||||||
nodesWithOldLabel, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
|
|
||||||
LabelSelector: selectorOldControlPlane.String(),
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(err, "could not list nodes labeled with %q", constants.LabelNodeRoleOldControlPlane)
|
|
||||||
}
|
|
||||||
|
|
||||||
// list nodes labeled with a "control-plane" node-role
|
|
||||||
selectorControlPlane := labels.SelectorFromSet(labels.Set(map[string]string{
|
selectorControlPlane := labels.SelectorFromSet(labels.Set(map[string]string{
|
||||||
constants.LabelNodeRoleControlPlane: "",
|
constants.LabelNodeRoleControlPlane: "",
|
||||||
}))
|
}))
|
||||||
nodesControlPlane, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
|
nodes, err := client.CoreV1().Nodes().List(context.TODO(), metav1.ListOptions{
|
||||||
LabelSelector: selectorControlPlane.String(),
|
LabelSelector: selectorControlPlane.String(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "could not list nodes labeled with %q", constants.LabelNodeRoleControlPlane)
|
return errors.Wrapf(err, "could not list nodes labeled with %q", constants.LabelNodeRoleControlPlane)
|
||||||
}
|
}
|
||||||
|
|
||||||
nodes := append(nodesWithOldLabel.Items, nodesControlPlane.Items...)
|
notReadyControlPlanes := getNotReadyNodes(nodes.Items)
|
||||||
if len(nodes) == 0 {
|
|
||||||
return errors.New("failed to find any nodes with a control-plane role")
|
|
||||||
}
|
|
||||||
|
|
||||||
notReadyControlPlanes := getNotReadyNodes(nodes)
|
|
||||||
if len(notReadyControlPlanes) != 0 {
|
if len(notReadyControlPlanes) != 0 {
|
||||||
return errors.Errorf("there are NotReady control-planes in the cluster: %v", notReadyControlPlanes)
|
return errors.Errorf("there are NotReady control-planes in the cluster: %v", notReadyControlPlanes)
|
||||||
}
|
}
|
||||||
|
@ -215,10 +215,9 @@ func rollbackFiles(files map[string]string, originalErr error) error {
|
|||||||
return errors.Errorf("couldn't move these files: %v. Got errors: %v", files, errorsutil.NewAggregate(errs))
|
return errors.Errorf("couldn't move these files: %v. Got errors: %v", files, errorsutil.NewAggregate(errs))
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelOldControlPlaneNodes finds all nodes with the legacy node-role label and also applies
|
// RemoveOldControlPlaneLabel finds all nodes with the legacy node-role label and removes it
|
||||||
// the "control-plane" node-role label to them.
|
|
||||||
// TODO: https://github.com/kubernetes/kubeadm/issues/2200
|
// TODO: https://github.com/kubernetes/kubeadm/issues/2200
|
||||||
func LabelOldControlPlaneNodes(client clientset.Interface) error {
|
func RemoveOldControlPlaneLabel(client clientset.Interface) error {
|
||||||
selectorOldControlPlane := labels.SelectorFromSet(labels.Set(map[string]string{
|
selectorOldControlPlane := labels.SelectorFromSet(labels.Set(map[string]string{
|
||||||
kubeadmconstants.LabelNodeRoleOldControlPlane: "",
|
kubeadmconstants.LabelNodeRoleOldControlPlane: "",
|
||||||
}))
|
}))
|
||||||
@ -230,11 +229,8 @@ func LabelOldControlPlaneNodes(client clientset.Interface) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, n := range nodesWithOldLabel.Items {
|
for _, n := range nodesWithOldLabel.Items {
|
||||||
if _, hasNewLabel := n.ObjectMeta.Labels[kubeadmconstants.LabelNodeRoleControlPlane]; hasNewLabel {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
err = apiclient.PatchNode(client, n.Name, func(n *v1.Node) {
|
err = apiclient.PatchNode(client, n.Name, func(n *v1.Node) {
|
||||||
n.ObjectMeta.Labels[kubeadmconstants.LabelNodeRoleControlPlane] = ""
|
delete(n.ObjectMeta.Labels, kubeadmconstants.LabelNodeRoleOldControlPlane)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user