Skip to content

Commit 1975e6e

Browse files
committed
Fix nil pointer issue while checking bootstrapReadyCondition
We should check if bootstrapReadyCondition is nil or not before checking bootstrapReadyCondition.Status Signed-off-by: Kashif Khan <[email protected]>
1 parent 4c09bcc commit 1975e6e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

baremetal/metal3machine_manager.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ func (m *MachineManager) IsBaremetalHostProvisioned(ctx context.Context) bool {
203203
func (m *MachineManager) IsBootstrapReady() bool {
204204
if m.Machine.Spec.Bootstrap.ConfigRef.IsDefined() {
205205
bootstrapReadyCondition := deprecatedv1beta1conditions.Get(m.Machine, clusterv1.BootstrapReadyV1Beta1Condition)
206+
if bootstrapReadyCondition == nil {
207+
return false
208+
}
206209
return bootstrapReadyCondition.Status == corev1.ConditionTrue
207210
}
208211

baremetal/metal3machine_manager_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,19 @@ var _ = Describe("Metal3Machine manager", func() {
469469
Machine: clusterv1.Machine{},
470470
ExpectTrue: false,
471471
}),
472+
Entry("ConfigRef defined but condition not set", testCaseBootstrapReady{
473+
Machine: clusterv1.Machine{
474+
Spec: clusterv1.MachineSpec{
475+
Bootstrap: clusterv1.Bootstrap{
476+
ConfigRef: clusterv1.ContractVersionedObjectReference{
477+
Name: "abc",
478+
},
479+
},
480+
},
481+
// No Status.Deprecated.V1Beta1.Conditions set - should return nil from Get()
482+
},
483+
ExpectTrue: false,
484+
}),
472485
Entry("ready data secret", testCaseBootstrapReady{
473486
Machine: clusterv1.Machine{
474487
Spec: clusterv1.MachineSpec{

controllers/metal3machine_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (r *Metal3MachineReconciler) Reconcile(ctx context.Context, req ctrl.Reques
144144

145145
// Make sure infrastructure is ready
146146
infrastructureReadyCondition := deprecatedv1beta1conditions.Get(cluster, clusterv1.InfrastructureReadyV1Beta1Condition)
147-
if infrastructureReadyCondition.Status != corev1.ConditionTrue {
147+
if infrastructureReadyCondition == nil || infrastructureReadyCondition.Status != corev1.ConditionTrue {
148148
machineLog.Info("Waiting for Metal3Cluster Controller to create cluster infrastructure")
149149
v1beta1conditions.MarkFalse(capm3Machine, infrav1.AssociateBMHCondition, infrav1.WaitingForClusterInfrastructureReason, clusterv1beta1.ConditionSeverityInfo, "")
150150
v1beta2conditions.Set(capm3Machine, metav1.Condition{

0 commit comments

Comments
 (0)