Skip to content

Commit a08d5ec

Browse files
Merge pull request #5147 from rphillips/add_label
OCPBUGS-58180: Add control-plane label for master nodes on legacy clusters
2 parents 36a1298 + db096c0 commit a08d5ec

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

pkg/controller/node/node_controller.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ import (
5555
const (
5656
// WorkerLabel defines the label associated with worker node.
5757
WorkerLabel = "node-role.kubernetes.io/worker"
58+
// ControlPlaneLabel defines the label associated with master/control-plane node.
59+
ControlPlaneLabel = "node-role.kubernetes.io/control-plane"
5860

5961
// maxRetries is the number of times a machineconfig pool will be retried before it is dropped out of the queue.
6062
// With the current rate-limiter in use (5ms*2^(maxRetries-1)) the following numbers represent the times
@@ -321,7 +323,21 @@ func (ctrl *Controller) makeMastersUnSchedulable(currentMasters []*corev1.Node)
321323
}
322324
}
323325
return errs
326+
}
324327

328+
// updateMasterNodeControlPlaneLabel ensures the control-plane label is on a node
329+
func (ctrl *Controller) updateMasterNodeControlPlaneLabel(node *corev1.Node) error {
330+
// If the control plane label is already set then no-op.
331+
if _, hasControlPlaneLabel := node.Labels[ControlPlaneLabel]; hasControlPlaneLabel {
332+
return nil
333+
}
334+
_, err := internal.UpdateNodeRetry(ctrl.kubeClient.CoreV1().Nodes(), ctrl.nodeLister, node.Name, func(node *corev1.Node) {
335+
node.Labels[ControlPlaneLabel] = ""
336+
})
337+
if err != nil {
338+
return err
339+
}
340+
return nil
325341
}
326342

327343
// makeMasterNodeUnSchedulable makes master node unschedulable by removing worker label and adding `NoSchedule`
@@ -503,8 +519,16 @@ func (ctrl *Controller) isMaster(node *corev1.Node) bool {
503519
return master
504520
}
505521

506-
// Given a master Node, ensure it reflects the current mastersSchedulable setting
522+
// Given a master Node, ensure it reflects the current mastersSchedulable
523+
// setting and make sure the control-plane label is set.
507524
func (ctrl *Controller) reconcileMaster(node *corev1.Node) {
525+
err := ctrl.updateMasterNodeControlPlaneLabel(node)
526+
if err != nil {
527+
err = fmt.Errorf("failed adding the control-plane label to master Node: %w", err)
528+
klog.Error(err)
529+
return
530+
}
531+
508532
mastersSchedulable, err := ctrl.getMastersSchedulable()
509533
if err != nil {
510534
err = fmt.Errorf("getting scheduler config failed: %w", err)

0 commit comments

Comments
 (0)