Skip to content

Commit c04e33f

Browse files
author
Joshua Reed
committedFeb 28, 2022
Set and use failure domains.
1 parent f4b523f commit c04e33f

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed
 

‎api/v1beta1/cloudstackcluster_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ type CloudStackClusterStatus struct {
9393
// +optional
9494
Zones map[string]Zone `json:"zones,omitempty"`
9595

96+
// CAPI recognizes failure domains as a method to spread machines.
97+
// CAPC sets failure domains per to indicate functionin Zones.
98+
// +optional
99+
FailureDomains clusterv1.FailureDomains `json:"failureDomains,omitempty"`
100+
96101
// Reflects the readiness of the CS cluster.
97102
Ready bool `json:"ready"`
98103

‎controllers/cloudstackmachine_controller.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,7 @@ func (r *CloudStackMachineReconciler) Reconcile(ctx context.Context, req ctrl.Re
136136
}
137137
}
138138

139-
// TODO: get zone from capi machine.
140-
var zone infrav1.Zone
141-
for _, theZone := range csCluster.Status.Zones { // Ugly way to get the only Zone.
142-
zone = theZone
143-
}
144-
if zone.Id == "" {
139+
if capiMachine.Spec.FailureDomain != nil && *capiMachine.Spec.FailureDomain == "" {
145140
log.Info("CloudStackCluster ZoneId not initialized. Likely not ready.")
146141
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
147142
}
@@ -160,6 +155,15 @@ func (r *CloudStackMachineReconciler) reconcile(
160155

161156
log.V(1).Info("reconcile CloudStackMachine")
162157

158+
zoneId := capiMachine.Spec.FailureDomain
159+
zone := infrav1.Zone{}
160+
for _, zoneStatus := range csCluster.Status.Zones {
161+
if zoneId == &zoneStatus.Id {
162+
zone = zoneStatus
163+
break
164+
}
165+
}
166+
163167
// Make sure bootstrap data is available in CAPI machine.
164168
if capiMachine.Spec.Bootstrap.DataSecretName == nil {
165169
log.Info("Bootstrap DataSecretName not yet available.")
@@ -193,7 +197,7 @@ func (r *CloudStackMachineReconciler) reconcile(
193197
csMachine.Status.Ready = true
194198
} else if csMachine.Status.InstanceState == "Error" {
195199
log.Info("CloudStackMachine VM in error state. Deleting associated Machine.", "csMachine", csMachine)
196-
if err := r.Client.Delete(ctx, capiMachine); err != nil {
200+
if err := r.Client.Delete(ctx, csMachine); err != nil {
197201
return ctrl.Result{}, err
198202
}
199203
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
@@ -202,15 +206,11 @@ func (r *CloudStackMachineReconciler) reconcile(
202206
return ctrl.Result{RequeueAfter: requeueTimeout}, nil
203207
}
204208

205-
if len(csCluster.Spec.Zones) == 1 {
206-
for _, zone := range csCluster.Status.Zones { // Ugly way to get the only Zone.
207-
if util.IsControlPlaneMachine(capiMachine) && zone.Network.Type == cloud.NetworkTypeIsolated {
208-
log.Info("Assigning VM to load balancer rule.")
209-
err := r.CS.AssignVMToLoadBalancerRule(csCluster, *csMachine.Spec.InstanceID)
210-
if err != nil {
211-
return ctrl.Result{}, err
212-
}
213-
}
209+
if util.IsControlPlaneMachine(capiMachine) && zone.Network.Type == cloud.NetworkTypeIsolated {
210+
log.Info("Assigning VM to load balancer rule.")
211+
err := r.CS.AssignVMToLoadBalancerRule(csCluster, *csMachine.Spec.InstanceID)
212+
if err != nil {
213+
return ctrl.Result{}, err
214214
}
215215
}
216216

0 commit comments

Comments
 (0)
Please sign in to comment.