Skip to content

Commit b5d8820

Browse files
authored
Merge pull request #8564 from sbueringer/pr-improve-kcp-error-log
🌱 KCP: improve error log on scale up when Machine doesn't have a nodeRef
2 parents a25723c + d547a74 commit b5d8820

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

controlplane/kubeadm/internal/controllers/controller_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2321,6 +2321,10 @@ func createMachineNodePair(name string, cluster *clusterv1.Cluster, kcp *control
23212321
}
23222322

23232323
func setMachineHealthy(m *clusterv1.Machine) {
2324+
m.Status.NodeRef = &corev1.ObjectReference{
2325+
Kind: "Node",
2326+
Name: "node-1",
2327+
}
23242328
conditions.MarkTrue(m, controlplanev1.MachineAPIServerPodHealthyCondition)
23252329
conditions.MarkTrue(m, controlplanev1.MachineControllerManagerPodHealthyCondition)
23262330
conditions.MarkTrue(m, controlplanev1.MachineSchedulerPodHealthyCondition)

controlplane/kubeadm/internal/controllers/scale.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,17 @@ loopmachines:
200200
}
201201
}
202202

203-
for _, condition := range allMachineHealthConditions {
204-
if err := preflightCheckCondition("machine", machine, condition); err != nil {
205-
machineErrors = append(machineErrors, err)
203+
if machine.Status.NodeRef == nil {
204+
// The conditions will only ever be set on a Machine if we're able to correlate a Machine to a Node.
205+
// Correlating Machines to Nodes requires the nodeRef to be set.
206+
// Instead of confusing users with errors about that the conditions are not set, let's point them
207+
// towards the unset nodeRef (which is the root cause of the conditions not being there).
208+
machineErrors = append(machineErrors, errors.Errorf("Machine %s does not have a corresponding Node yet (Machine.status.nodeRef not set)", machine.Name))
209+
} else {
210+
for _, condition := range allMachineHealthConditions {
211+
if err := preflightCheckCondition("Machine", machine, condition); err != nil {
212+
machineErrors = append(machineErrors, err)
213+
}
206214
}
207215
}
208216
}

controlplane/kubeadm/internal/controllers/scale_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,28 @@ func TestPreflightChecks(t *testing.T) {
492492
},
493493
expectResult: ctrl.Result{RequeueAfter: deleteRequeueAfter},
494494
},
495+
{
496+
name: "control plane without a nodeRef should requeue",
497+
kcp: &controlplanev1.KubeadmControlPlane{},
498+
machines: []*clusterv1.Machine{
499+
{
500+
Status: clusterv1.MachineStatus{
501+
NodeRef: nil,
502+
},
503+
},
504+
},
505+
expectResult: ctrl.Result{RequeueAfter: preflightFailedRequeueAfter},
506+
},
495507
{
496508
name: "control plane with an unhealthy machine condition should requeue",
497509
kcp: &controlplanev1.KubeadmControlPlane{},
498510
machines: []*clusterv1.Machine{
499511
{
500512
Status: clusterv1.MachineStatus{
513+
NodeRef: &corev1.ObjectReference{
514+
Kind: "Node",
515+
Name: "node-1",
516+
},
501517
Conditions: clusterv1.Conditions{
502518
*conditions.FalseCondition(controlplanev1.MachineAPIServerPodHealthyCondition, "fooReason", clusterv1.ConditionSeverityError, ""),
503519
*conditions.TrueCondition(controlplanev1.MachineControllerManagerPodHealthyCondition),
@@ -523,6 +539,10 @@ func TestPreflightChecks(t *testing.T) {
523539
machines: []*clusterv1.Machine{
524540
{
525541
Status: clusterv1.MachineStatus{
542+
NodeRef: &corev1.ObjectReference{
543+
Kind: "Node",
544+
Name: "node-1",
545+
},
526546
Conditions: clusterv1.Conditions{
527547
*conditions.TrueCondition(controlplanev1.MachineAPIServerPodHealthyCondition),
528548
*conditions.TrueCondition(controlplanev1.MachineControllerManagerPodHealthyCondition),

0 commit comments

Comments
 (0)