@@ -53,7 +53,6 @@ type CloudStackMachineReconciliationRunner struct {
5353 ReconciliationSubject * infrav1.CloudStackMachine
5454 CAPIMachine * capiv1.Machine
5555 StateChecker * infrav1.CloudStackMachineStateChecker
56- CSUser cloud.Client
5756 Zones * infrav1.CloudStackZoneList
5857 FailureDomain * infrav1.CloudStackZone
5958 IsoNet * infrav1.CloudStackIsolatedNetwork
@@ -122,7 +121,7 @@ func (r *CloudStackMachineReconciliationRunner) ConsiderAffinity() (ctrl.Result,
122121 return res , err
123122 }
124123 if ! r .AffinityGroup .Status .Ready {
125- return r .RequeueWithMessage ("Required afinity group not ready." )
124+ return r .RequeueWithMessage ("Required affinity group not ready." )
126125 }
127126 return ctrl.Result {}, nil
128127}
@@ -191,7 +190,7 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateVMInstance() (retRes
191190 return ctrl.Result {}, errors .New ("bootstrap secret data not yet set" )
192191 }
193192
194- err := r .CSClient .GetOrCreateVMInstance (r .ReconciliationSubject , r .CAPIMachine , r .CSCluster , & machineZone , r .AffinityGroup , string (data ))
193+ err := r .CSUser .GetOrCreateVMInstance (r .ReconciliationSubject , r .CAPIMachine , r .CSCluster , & machineZone , r .AffinityGroup , string (data ))
195194
196195 if err == nil && ! controllerutil .ContainsFinalizer (r .ReconciliationSubject , infrav1 .MachineFinalizer ) { // Fetched or Created?
197196 r .Log .Info ("CloudStack instance Created" , "instanceStatus" , r .ReconciliationSubject .Status )
@@ -225,7 +224,7 @@ func (r *CloudStackMachineReconciliationRunner) AddToLBIfNeeded() (retRes ctrl.R
225224 if r .IsoNet .Spec .Name == "" {
226225 return r .RequeueWithMessage ("Could not get required Isolated Network for VM, requeueing." )
227226 }
228- err := r .CSClient .AssignVMToLoadBalancerRule (r .IsoNet , * r .ReconciliationSubject .Spec .InstanceID )
227+ err := r .CSUser .AssignVMToLoadBalancerRule (r .IsoNet , * r .ReconciliationSubject .Spec .InstanceID )
229228 if err != nil {
230229 return ctrl.Result {}, err
231230 }
@@ -251,6 +250,9 @@ func (r *CloudStackMachineReconciliationRunner) GetOrCreateMachineStateChecker()
251250
252251func (r * CloudStackMachineReconciliationRunner ) ReconcileDelete () (retRes ctrl.Result , reterr error ) {
253252 r .Log .Info ("Deleting instance" , "instance-id" , r .ReconciliationSubject .Spec .InstanceID )
253+ // Use CSClient instead of CSUser here to expunge as admin.
254+ // The CloudStack-Go API does not return an error, but the VM won't delete with Expunge set if requested by
255+ // non-domain admin user.
254256 if err := r .CSClient .DestroyVMInstance (r .ReconciliationSubject ); err != nil {
255257 if err .Error () == "VM deletion in progress" {
256258 r .Log .Info (err .Error ())
0 commit comments