Skip to content

Commit 4f11f52

Browse files
authored
Merge pull request #126 from rejoshed/fixup/requeue-if-no-zones
Fixup for Zones Panic
2 parents b9dc417 + 2786179 commit 4f11f52

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

controllers/cloudstackmachine_controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ func (r *CloudStackMachineReconciliationRunner) SetFailureDomainOnCSMachine() (r
148148
return ctrl.Result{}, errors.Errorf("could not find zone by zoneName: %s", r.ReconciliationSubject.Spec.ZoneName)
149149
}
150150
} else { // No Zone Specified, pick a Random Zone.
151+
// TODO: Add an additional controller test for this once controller test upgrades are merged.
152+
if len(r.Zones.Items) < 1 { // Double check that zones are present.
153+
return r.RequeueWithMessage("no zones found, requeueing")
154+
}
151155
randNum := (rand.Int() % len(r.Zones.Items)) // #nosec G404 -- weak crypt rand doesn't matter here.
152156
r.ReconciliationSubject.Status.ZoneID = r.Zones.Items[randNum].Spec.ID
153157
}

controllers/utils/zones.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ func (r *ReconciliationRunner) GetZones(zones *infrav1.CloudStackZoneList) Cloud
7575
client.MatchingLabels(capiClusterLabel),
7676
); err != nil {
7777
return ctrl.Result{}, errors.Wrap(err, "failed to list zones")
78+
} else if len(zones.Items) < 1 {
79+
return r.RequeueWithMessage("no zones found, requeueing")
7880
}
7981
return ctrl.Result{}, nil
8082
}

0 commit comments

Comments
 (0)