@@ -19,11 +19,12 @@ package controllers
1919import (
2020 "context"
2121 "fmt"
22- "k8s.io/utils/pointer"
2322 "math/rand"
2423 "reflect"
2524 "regexp"
2625
26+ "k8s.io/utils/pointer"
27+
2728 "github.com/pkg/errors"
2829 corev1 "k8s.io/api/core/v1"
2930 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -105,7 +106,7 @@ func (reconciler *CloudStackMachineReconciler) Reconcile(ctx context.Context, re
105106 r := NewCSMachineReconciliationRunner ()
106107 r .UsingBaseReconciler (reconciler .ReconcilerBase ).ForRequest (req ).WithRequestCtx (ctx )
107108 r .WithAdditionalCommonStages (
108- r .GetParent (r .ReconciliationSubject , r .CAPIMachine ),
109+ r .RunIf ( func () bool { return r . ReconciliationSubject . GetDeletionTimestamp (). IsZero () }, r . GetParent (r .ReconciliationSubject , r .CAPIMachine ) ),
109110 r .RequeueIfCloudStackClusterNotReady ,
110111 r .SetFailureDomainOnCSMachine ,
111112 r .GetFailureDomainByName (func () string { return r .ReconciliationSubject .Spec .FailureDomainName }, r .FailureDomain ),
@@ -158,7 +159,8 @@ func (r *CloudStackMachineReconciliationRunner) ConsiderAffinity() (ctrl.Result,
158159func (r * CloudStackMachineReconciliationRunner ) SetFailureDomainOnCSMachine () (retRes ctrl.Result , reterr error ) {
159160 if r .ReconciliationSubject .Spec .FailureDomainName == "" {
160161 var name string
161- if r .CAPIMachine .Spec .FailureDomain != nil &&
162+ // CAPIMachine is null if it's been deleted but we're still reconciling the CS machine.
163+ if r .CAPIMachine != nil && r .CAPIMachine .Spec .FailureDomain != nil &&
162164 (util .IsControlPlaneMachine (r .CAPIMachine ) || // Is control plane machine -- CAPI will specify.
163165 * r .CAPIMachine .Spec .FailureDomain != "" ) { // Or potentially another machine controller specified.
164166 name = * r .CAPIMachine .Spec .FailureDomain
0 commit comments