Skip to content

Commit 6860b32

Browse files
author
Joshua Reed
committed
Machine state checker and machines work now.
1 parent 917c205 commit 6860b32

15 files changed

+175
-129
lines changed

api/v1beta2/cloudstackmachine_types.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ type CloudStackMachineSpec struct {
8080
ProviderID *string `json:"providerID,omitempty"`
8181

8282
// FailureDomain -- the FailureDomain the machine is placed in.
83-
FailureDomain CloudStackFailureDomainSpec `json:"failureDomain"`
83+
// +optional
84+
FailureDomain CloudStackFailureDomainSpec `json:"failureDomain,omitempty"`
8485

8586
// IdentityRef is a reference to a identity to be used when reconciling this cluster
8687
// +optional

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackmachines.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ spec:
494494
type: string
495495
type: object
496496
required:
497-
- failureDomain
498497
- offering
499498
- template
500499
type: object

config/crd/bases/infrastructure.cluster.x-k8s.io_cloudstackmachinetemplates.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,6 @@ spec:
449449
type: string
450450
type: object
451451
required:
452-
- failureDomain
453452
- offering
454453
- template
455454
type: object

controllers/cloudstackaffinitygroup_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewCSAGReconciliationRunner() *CloudStackAGReconciliationRunner {
4949
// Set concrete type and init pointers.
5050
r := &CloudStackAGReconciliationRunner{ReconciliationSubject: &infrav1.CloudStackAffinityGroup{}}
5151
// Setup the base runner. Initializes pointers and links reconciliation methods.
52-
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject)
52+
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject, "CloudStackAffinityGroup")
5353
return r
5454
}
5555

controllers/cloudstackcluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func NewCSClusterReconciliationRunner() *CloudStackClusterReconciliationRunner {
6666
r := &CloudStackClusterReconciliationRunner{ReconciliationSubject: &infrav1.CloudStackCluster{}}
6767
r.FailureDomains = &infrav1.CloudStackFailureDomainList{}
6868
// Setup the base runner. Initializes pointers and links reconciliation methods.
69-
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject)
69+
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject, "CloudStackCluster")
7070
// For the CloudStackCluster, the ReconciliationSubject is the CSCluster
7171
// Have to do after or the setup method will overwrite the link.
7272
r.CSCluster = r.ReconciliationSubject

controllers/cloudstackfailuredomain_controller.go

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ type CloudStackFailureDomainReconciler struct {
4242
type CloudStackFailureDomainReconciliationRunner struct {
4343
csCtrlrUtils.ReconciliationRunner
4444
ReconciliationSubject *infrav1.CloudStackFailureDomain
45+
IsoNet *infrav1.CloudStackIsolatedNetwork
4546
}
4647

4748
// Initialize a new CloudStackFailureDomain reconciliation runner with concrete types and initialized member fields.
4849
func NewCSFailureDomainReconciliationRunner() *CloudStackFailureDomainReconciliationRunner {
4950
// Set concrete type and init pointers.
5051
r := &CloudStackFailureDomainReconciliationRunner{ReconciliationSubject: &infrav1.CloudStackFailureDomain{}}
52+
r.IsoNet = &infrav1.CloudStackIsolatedNetwork{}
5153
// Setup the base runner. Initializes pointers and links reconciliation methods.
52-
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject)
54+
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject, "CloudStackFailureDomain")
5355

5456
return r
5557
}
@@ -65,7 +67,7 @@ func (reconciler *CloudStackFailureDomainReconciler) Reconcile(ctx context.Conte
6567

6668
// Reconcile on the ReconciliationRunner actually attempts to modify or create the reconciliation subject.
6769
func (r *CloudStackFailureDomainReconciliationRunner) Reconcile() (retRes ctrl.Result, retErr error) {
68-
res, err := r.AsFailureDomainUser(r.ReconciliationSubject.Spec)()
70+
res, err := r.AsFailureDomainUser(&r.ReconciliationSubject.Spec)()
6971
if r.ShouldReturn(res, err) {
7072
return res, err
7173
}
@@ -81,31 +83,43 @@ func (r *CloudStackFailureDomainReconciliationRunner) Reconcile() (retRes ctrl.R
8183
return ctrl.Result{}, errors.Wrap(err, "resolving Cloudstack network information")
8284
}
8385

84-
// TODO: Address Isolated Networks.
85-
// // Check if the passed network was an isolated network or the network was missing. In either case, create a
86-
// // CloudStackIsolatedNetwork to manage the many intricacies and wait until CloudStackIsolatedNetwork is ready.
87-
// if r.ReconciliationSubject.Spec.Network.ID == "" || r.ReconciliationSubject.Spec.Network.Type == infrav1.NetworkTypeIsolated {
88-
// netName := r.ReconciliationSubject.Spec.Network.Name
89-
// if res, err := r.GenerateIsolatedNetwork(netName)(); r.ShouldReturn(res, err) {
90-
// return res, err
91-
// } else if res, err := r.GetObjectByName(r.IsoNetMetaName(netName), r.IsoNet)(); r.ShouldReturn(res, err) {
92-
// return res, err
93-
// }
94-
// if r.IsoNet.Name == "" {
95-
// return r.RequeueWithMessage("Couldn't find isolated network.")
96-
// }
97-
// if !r.IsoNet.Status.Ready {
98-
// return r.RequeueWithMessage("Isolated network dependency not ready.")
99-
// }
100-
// }
86+
// Check if the passed network was an isolated network or the network was missing. In either case, create a
87+
// CloudStackIsolatedNetwork to manage the many intricacies and wait until CloudStackIsolatedNetwork is ready.
88+
if r.ReconciliationSubject.Spec.Zone.Network.ID == "" ||
89+
r.ReconciliationSubject.Spec.Zone.Network.Type == infrav1.NetworkTypeIsolated {
90+
netName := r.ReconciliationSubject.Spec.Zone.Network.Name
91+
if res, err := r.GenerateIsolatedNetwork(netName)(); r.ShouldReturn(res, err) {
92+
return res, err
93+
} else if res, err := r.GetObjectByName(r.IsoNetMetaName(netName), r.IsoNet)(); r.ShouldReturn(res, err) {
94+
return res, err
95+
}
96+
if r.IsoNet.Name == "" {
97+
return r.RequeueWithMessage("Couldn't find isolated network.")
98+
}
99+
if !r.IsoNet.Status.Ready {
100+
return r.RequeueWithMessage("Isolated network dependency not ready.")
101+
}
102+
}
101103
r.ReconciliationSubject.Status.Ready = true
102104
return ctrl.Result{}, nil
103105
}
104106

105107
// ReconcileDelete on the ReconciliationRunner actually attempts to delete the reconciliation subject.
106108
func (r *CloudStackFailureDomainReconciliationRunner) ReconcileDelete() (retRes ctrl.Result, retErr error) {
107-
// TODO: Consider owned resources.
108-
// Allow deletion.
109+
r.Log.Info("Deleting CloudStackZone")
110+
// Address Isolated Networks.
111+
if r.ReconciliationSubject.Spec.Zone.Network.Type == infrav1.NetworkTypeIsolated {
112+
netName := r.ReconciliationSubject.Spec.Zone.Network.Name
113+
if res, err := r.GetObjectByName(r.IsoNetMetaName(netName), r.IsoNet)(); r.ShouldReturn(res, err) {
114+
return res, err
115+
}
116+
if r.IsoNet.Name != "" {
117+
if err := r.K8sClient.Delete(r.RequestCtx, r.IsoNet); err != nil {
118+
return ctrl.Result{}, err
119+
}
120+
return r.RequeueWithMessage("Child IsolatedNetwork still present, requeueing.")
121+
}
122+
}
109123
controllerutil.RemoveFinalizer(r.ReconciliationSubject, infrav1.FailureDomainFinalizer)
110124
return ctrl.Result{}, nil
111125
}

controllers/cloudstackisolatednetwork_controller.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ type CloudStackIsoNetReconciler struct {
4242
// CloudStackZoneReconciliationRunner is a ReconciliationRunner with extensions specific to CloudStack isolated network reconciliation.
4343
type CloudStackIsoNetReconciliationRunner struct {
4444
csCtrlrUtils.ReconciliationRunner
45-
Zone *infrav1.CloudStackZone
45+
FailureDomain *infrav1.CloudStackFailureDomain
4646
ReconciliationSubject *infrav1.CloudStackIsolatedNetwork
4747
}
4848

4949
// Initialize a new CloudStackIsoNet reconciliation runner with concrete types and initialized member fields.
5050
func NewCSIsoNetReconciliationRunner() *CloudStackIsoNetReconciliationRunner {
5151
// Set concrete type and init pointers.
5252
r := &CloudStackIsoNetReconciliationRunner{ReconciliationSubject: &infrav1.CloudStackIsolatedNetwork{}}
53-
r.Zone = &infrav1.CloudStackZone{}
53+
r.FailureDomain = &infrav1.CloudStackFailureDomain{}
5454
// Setup the base runner. Initializes pointers and links reconciliation methods.
55-
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject)
55+
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject, "CloudStackIsolatedNetwork")
5656
return r
5757
}
5858

@@ -65,10 +65,17 @@ func (reconciler *CloudStackIsoNetReconciler) Reconcile(ctx context.Context, req
6565
}
6666

6767
func (r *CloudStackIsoNetReconciliationRunner) Reconcile() (retRes ctrl.Result, retErr error) {
68-
if res, err := r.RequeueIfMissingBaseCRs(); r.ShouldReturn(res, err) {
68+
if res, err := r.GetParent(r.ReconciliationSubject, r.FailureDomain)(); r.ShouldReturn(res, err) {
6969
return res, err
7070
}
71-
if res, err := r.GetParent(r.ReconciliationSubject, r.Zone)(); r.ShouldReturn(res, err) {
71+
if r.FailureDomain.Spec.Name == "" {
72+
return ctrl.Result{}, errors.New("couldn't get parent Failure Domain for placement")
73+
}
74+
res, err := r.AsFailureDomainUser(&r.FailureDomain.Spec)()
75+
if r.ShouldReturn(res, err) {
76+
return res, err
77+
}
78+
if res, err := r.RequeueIfMissingBaseCRs(); r.ShouldReturn(res, err) {
7279
return res, err
7380
}
7481
controllerutil.AddFinalizer(r.ReconciliationSubject, infrav1.IsolatedNetworkFinalizer)
@@ -79,7 +86,7 @@ func (r *CloudStackIsoNetReconciliationRunner) Reconcile() (retRes ctrl.Result,
7986
if err != nil {
8087
return r.ReturnWrappedError(retErr, "setting up CloudStackCluster patcher")
8188
}
82-
if err := r.CSUser.GetOrCreateIsolatedNetwork(r.Zone, r.ReconciliationSubject, r.CSCluster); err != nil {
89+
if err := r.CSUser.GetOrCreateIsolatedNetwork(r.FailureDomain, r.ReconciliationSubject, r.CSCluster); err != nil {
8390
return ctrl.Result{}, err
8491
}
8592
// Tag the created network.
@@ -95,8 +102,18 @@ func (r *CloudStackIsoNetReconciliationRunner) Reconcile() (retRes ctrl.Result,
95102
}
96103

97104
func (r *CloudStackIsoNetReconciliationRunner) ReconcileDelete() (retRes ctrl.Result, retErr error) {
105+
if res, err := r.GetParent(r.ReconciliationSubject, r.FailureDomain)(); r.ShouldReturn(res, err) {
106+
return res, err
107+
}
108+
if r.FailureDomain.Spec.Name == "" {
109+
return ctrl.Result{}, errors.New("couldn't get parent Failure Domain for placement")
110+
}
111+
res, err := r.AsFailureDomainUser(&r.FailureDomain.Spec)()
112+
if r.ShouldReturn(res, err) {
113+
return res, err
114+
}
98115
r.Log.Info("Deleting IsolatedNetwork.")
99-
if err := r.CSUser.DisposeIsoNetResources(r.Zone, r.ReconciliationSubject, r.CSCluster); err != nil {
116+
if err := r.CSUser.DisposeIsoNetResources(r.FailureDomain, r.ReconciliationSubject, r.CSCluster); err != nil {
100117
if !strings.Contains(strings.ToLower(err.Error()), "no match found") {
101118
return ctrl.Result{}, err
102119
}

controllers/cloudstackmachine_controller.go

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ package controllers
1919
import (
2020
"context"
2121
"fmt"
22+
"math/rand"
2223
"reflect"
2324

24-
2525
"github.com/pkg/errors"
2626
corev1 "k8s.io/api/core/v1"
2727
"k8s.io/apimachinery/pkg/types"
2828
"sigs.k8s.io/cluster-api/util"
2929
ctrl "sigs.k8s.io/controller-runtime"
30+
"sigs.k8s.io/controller-runtime/pkg/client"
3031
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3132
"sigs.k8s.io/controller-runtime/pkg/event"
3233
"sigs.k8s.io/controller-runtime/pkg/handler"
@@ -74,7 +75,7 @@ func NewCSMachineReconciliationRunner() *CloudStackMachineReconciliationRunner {
7475
r.AffinityGroup = &infrav1.CloudStackAffinityGroup{}
7576
r.FailureDomain = &infrav1.CloudStackFailureDomain{}
7677
// Setup the base runner. Initializes pointers and links reconciliation methods.
77-
r.ReconciliationRunner = utils.NewRunner(r, r.ReconciliationSubject)
78+
r.ReconciliationRunner = utils.NewRunner(r, r.ReconciliationSubject, "CloudStackMachine")
7879
return r
7980
}
8081

@@ -90,13 +91,18 @@ func (reconciler *CloudStackMachineReconciler) Reconcile(ctx context.Context, re
9091

9192
func (r *CloudStackMachineReconciliationRunner) Reconcile() (retRes ctrl.Result, reterr error) {
9293
return r.RunReconciliationStages(
93-
r.AsFailureDomainUser(r.ReconciliationSubject.Spec.FailureDomain),
94-
r.GetZonesAndRequeueIfMissing(r.Zones),
9594
r.GetParent(r.ReconciliationSubject, r.CAPIMachine),
9695
r.RequeueIfCloudStackClusterNotReady,
97-
r.ConsiderAffinity,
9896
r.SetFailureDomainOnCSMachine,
99-
r.GetObjectByName("placeholder", r.IsoNet, func() string { return r.IsoNetMetaName(r.FailureDomain.Spec.Zone.Network.Name) }),
97+
r.GetObjectByName("placeholder", r.FailureDomain,
98+
func() string { return r.ReconciliationSubject.Spec.FailureDomain.Name }),
99+
r.CheckPresent(map[string]client.Object{"CloudStackFailureDomain": r.FailureDomain}),
100+
r.AsFailureDomainUser(&r.FailureDomain.Spec),
101+
r.GetObjectByName("placeholder", r.IsoNet,
102+
func() string { return r.IsoNetMetaName(r.FailureDomain.Spec.Zone.Network.Name) }),
103+
r.RunIf(func() bool { return r.FailureDomain.Spec.Zone.Network.Type == cloud.NetworkTypeIsolated },
104+
r.CheckPresent(map[string]client.Object{"CloudStackIsolatedNetwork": r.IsoNet})),
105+
r.ConsiderAffinity,
100106
r.GetOrCreateVMInstance,
101107
r.RequeueIfInstanceNotRunning,
102108
r.AddToLBIfNeeded,
@@ -128,40 +134,14 @@ func (r *CloudStackMachineReconciliationRunner) ConsiderAffinity() (ctrl.Result,
128134

129135
// SetFailureDomainOnCSMachine sets the failure domain the machine should launch in.
130136
func (r *CloudStackMachineReconciliationRunner) SetFailureDomainOnCSMachine() (retRes ctrl.Result, reterr error) {
131-
// // Set ZoneID on csMachine.
132-
// if util.IsControlPlaneMachine(r.CAPIMachine) { // Use failure domain zone.
133-
// r.ReconciliationSubject.Status.ZoneID = *r.CAPIMachine.Spec.FailureDomain
134-
// } else { // Specified by Machine Template or Random zone.
135-
// if r.ReconciliationSubject.Spec.FailureDomain.Name != "" {
136-
// if zone, foundZone := r.CSCluster.Status.Zones[r.ReconciliationSubject.Spec.ZoneID]; foundZone { // ZoneID Specified.
137-
// r.ReconciliationSubject.Status.ZoneID = zone.ID
138-
// } else {
139-
// return ctrl.Result{}, errors.Errorf("could not find zone by zoneID: %s", r.ReconciliationSubject.Spec.ZoneID)
140-
// }
141-
// } else if r.ReconciliationSubject.Spec.ZoneName != "" {
142-
// for _, zone := range r.Zones.Items {
143-
// if zone.Spec.Name == r.ReconciliationSubject.Spec.ZoneName {
144-
// r.ReconciliationSubject.Status.ZoneID = zone.Spec.ID
145-
// break
146-
// }
147-
// }
148-
// if r.ReconciliationSubject.Status.ZoneID == "" {
149-
// return ctrl.Result{}, errors.Errorf("could not find zone by zoneName: %s", r.ReconciliationSubject.Spec.ZoneName)
150-
// }
151-
// } else { // No Zone Specified, pick a Random Zone.
152-
// if len(r.Zones.Items) < 1 { // Double check that zones are present.
153-
// return r.RequeueWithMessage("no zones found, requeueing")
154-
// }
155-
// randNum := (rand.Int() % len(r.Zones.Items)) // #nosec G404 -- weak crypt rand doesn't matter here.
156-
// r.ReconciliationSubject.Status.ZoneID = r.Zones.Items[randNum].Spec.ID
157-
// }
158-
// }
159-
// for idx, zone := range r.Zones.Items {
160-
// if zone.Spec.ID == r.ReconciliationSubject.Status.ZoneID {
161-
// r.FailureDomain = &r.Zones.Items[idx]
162-
// break
163-
// }
164-
// }
137+
if r.ReconciliationSubject.Spec.FailureDomain.Name == "" { // Needs random FD, but not yet set.
138+
if util.IsControlPlaneMachine(r.CAPIMachine) { // Is control plane machine -- CAPI will specify.
139+
r.ReconciliationSubject.Spec.FailureDomain.Name = *r.CAPIMachine.Spec.FailureDomain
140+
} else { // Not a control plane machine. Place randomly.
141+
randNum := (rand.Int() % len(r.CSCluster.Spec.FailureDomains)) // #nosec G404 -- weak crypt rand doesn't matter here.
142+
r.ReconciliationSubject.Spec.FailureDomain.Name = r.CSCluster.Spec.FailureDomains[randNum].Name
143+
}
144+
}
165145
return ctrl.Result{}, nil
166146
}
167147

@@ -173,15 +153,6 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateVMInstance() (retRes
173153
}
174154
r.Log.Info("Got Bootstrap DataSecretName.")
175155

176-
// Get the CloudStackZone for the Machine.
177-
var machineZone infrav1.CloudStackZone
178-
for _, zone := range r.Zones.Items {
179-
machineZone = zone
180-
if zone.Spec.ID == r.ReconciliationSubject.Status.ZoneID {
181-
break
182-
}
183-
}
184-
185156
// Get the kubeadm bootstrap secret for this machine.
186157
secret := &corev1.Secret{}
187158
key := types.NamespacedName{Namespace: r.CAPIMachine.Namespace, Name: *r.CAPIMachine.Spec.Bootstrap.DataSecretName}
@@ -193,7 +164,7 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateVMInstance() (retRes
193164
return ctrl.Result{}, errors.New("bootstrap secret data not yet set")
194165
}
195166

196-
err := r.CSUser.GetOrCreateVMInstance(r.ReconciliationSubject, r.CAPIMachine, r.CSCluster, &machineZone, r.AffinityGroup, string(data))
167+
err := r.CSUser.GetOrCreateVMInstance(r.ReconciliationSubject, r.CAPIMachine, r.CSCluster, r.FailureDomain, r.AffinityGroup, string(data))
197168

198169
if err == nil && !controllerutil.ContainsFinalizer(r.ReconciliationSubject, infrav1.MachineFinalizer) { // Fetched or Created?
199170
r.Log.Info("CloudStack instance Created", "instanceStatus", r.ReconciliationSubject.Status)
@@ -253,7 +224,7 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateMachineStateChecker()
253224
}
254225

255226
func (r *CloudStackMachineReconciliationRunner) ReconcileDelete() (retRes ctrl.Result, reterr error) {
256-
if res, err := r.AsFailureDomainUser(r.ReconciliationSubject.Spec.FailureDomain)(); r.ShouldReturn(res, err) {
227+
if res, err := r.AsFailureDomainUser(&r.ReconciliationSubject.Spec.FailureDomain)(); r.ShouldReturn(res, err) {
257228
return res, err
258229
}
259230
if r.ReconciliationSubject.Spec.InstanceID != nil {

controllers/cloudstackmachinestatechecker_controller.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
ctrl "sigs.k8s.io/controller-runtime"
25+
"sigs.k8s.io/controller-runtime/pkg/client"
2526

2627
infrav1 "sigs.k8s.io/cluster-api-provider-cloudstack/api/v1beta2"
2728
csCtrlrUtils "sigs.k8s.io/cluster-api-provider-cloudstack/controllers/utils"
@@ -38,6 +39,7 @@ type CloudStackMachineStateCheckerReconciliationRunner struct {
3839
csCtrlrUtils.ReconciliationRunner
3940
MachineStateCheckers *infrav1.CloudStackMachineStateCheckerList
4041
ReconciliationSubject *infrav1.CloudStackMachineStateChecker
42+
FailureDomain *infrav1.CloudStackFailureDomain
4143
CAPIMachine *clusterv1.Machine
4244
CSMachine *infrav1.CloudStackMachine
4345
}
@@ -53,8 +55,9 @@ func NewCSMachineStateCheckerReconciliationRunner() *CloudStackMachineStateCheck
5355
runner := &CloudStackMachineStateCheckerReconciliationRunner{ReconciliationSubject: &infrav1.CloudStackMachineStateChecker{}}
5456
runner.CAPIMachine = &clusterv1.Machine{}
5557
runner.CSMachine = &infrav1.CloudStackMachine{}
58+
runner.FailureDomain = &infrav1.CloudStackFailureDomain{}
5659
// Setup the base runner. Initializes pointers and links reconciliation methods.
57-
runner.ReconciliationRunner = csCtrlrUtils.NewRunner(runner, runner.ReconciliationSubject)
60+
runner.ReconciliationRunner = csCtrlrUtils.NewRunner(runner, runner.ReconciliationSubject, "CloudStackMachineStateChecker")
5861
return runner
5962
}
6063

@@ -67,11 +70,16 @@ func (r *CloudStackMachineStateCheckerReconciler) Reconcile(ctx context.Context,
6770
}
6871

6972
func (r *CloudStackMachineStateCheckerReconciliationRunner) Reconcile() (ctrl.Result, error) {
70-
if res, err := r.GetParent(r.ReconciliationSubject, r.CSMachine)(); r.ShouldReturn(res, err) {
71-
return res, err
72-
}
73-
74-
if res, err := r.GetParent(r.CSMachine, r.CAPIMachine)(); r.ShouldReturn(res, err) {
73+
if res, err := r.RunReconciliationStages(
74+
r.GetParent(r.ReconciliationSubject, r.CSMachine),
75+
r.GetParent(r.CSMachine, r.CAPIMachine),
76+
r.CheckPresent(map[string]client.Object{"CloudStackMachine": r.CSMachine, "Machine": r.CAPIMachine}),
77+
r.GetObjectByName(r.CSMachine.Spec.FailureDomain.Name, r.FailureDomain),
78+
r.GetObjectByName("placeholder", r.FailureDomain,
79+
func() string { return r.CSMachine.Spec.FailureDomain.Name }),
80+
r.CheckPresent(map[string]client.Object{"CloudStackFailureDomain": r.FailureDomain}),
81+
r.AsFailureDomainUser(&r.FailureDomain.Spec),
82+
); r.ShouldReturn(res, err) {
7583
return res, err
7684
}
7785

controllers/cloudstackzone_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewCSZoneReconciliationRunner() *CloudStackZoneReconciliationRunner {
5050
r.Zones = &infrav1.CloudStackZoneList{}
5151
r.IsoNet = &infrav1.CloudStackIsolatedNetwork{}
5252
// Setup the base r. Initializes pointers and links reconciliation methods.
53-
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject)
53+
r.ReconciliationRunner = csCtrlrUtils.NewRunner(r, r.ReconciliationSubject, "CloudStackZone")
5454
return r
5555
}
5656

0 commit comments

Comments
 (0)