@@ -30,6 +30,7 @@ import (
30
30
31
31
kcpv1alpha1 "github.com/clastix/cluster-api-control-plane-provider-kamaji/api/v1alpha1"
32
32
"github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/externalclusterreference"
33
+ "github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/features"
33
34
)
34
35
35
36
// KamajiControlPlaneReconciler reconciles a KamajiControlPlane object.
@@ -179,19 +180,39 @@ func (r *KamajiControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
179
180
180
181
return ctrl.Result {}, err
181
182
}
182
- // Patching the Infrastructure Cluster:
183
- // this will be removed on the upcoming Kamaji Control Plane versions.
184
- TrackConditionType (& conditions , kcpv1alpha1 .InfrastructureClusterPatchedConditionType , kcp .Generation , func () error {
185
- err = r .patchCluster (ctx , cluster , & kcp , tcp .Status .ControlPlaneEndpoint )
186
183
187
- return err
188
- })
184
+ // We need to fetch the updated cluster resource here because otherwise the cluster.spec.controlPlaneEndpoint.Host
185
+ // check that happens latter will never succeed.
186
+ if err = r .client .Get (ctx , types.NamespacedName {Name : cluster .Name , Namespace : cluster .Namespace }, & cluster ); err != nil {
187
+ if errors .IsNotFound (err ) {
188
+ log .Info ("capiv1beta1.Cluster resource may have been deleted, withdrawing reconciliation" )
189
189
190
- if err != nil {
191
- log . Error ( err , "cannot patch capiv1beta1.Cluster" )
190
+ return ctrl. Result {}, nil
191
+ }
192
192
193
- return ctrl.Result {}, err
193
+ log .Error (err , "unable to get capiv1beta1.Cluster" )
194
+
195
+ return ctrl.Result {}, err //nolint:wrapcheck
194
196
}
197
+
198
+ // The following code path will be skipped when the InfraClusterOptional=true. This enables
199
+ // the use of a KamajiControlPlane without an infrastructure cluster.
200
+ if ! r .FeatureGates .Enabled (features .SkipInfraClusterPatch ) {
201
+ // Patching the Infrastructure Cluster:
202
+ // this will be removed on the upcoming Kamaji Control Plane versions.
203
+ TrackConditionType (& conditions , kcpv1alpha1 .InfrastructureClusterPatchedConditionType , kcp .Generation , func () error {
204
+ err = r .patchCluster (ctx , cluster , & kcp , tcp .Status .ControlPlaneEndpoint )
205
+
206
+ return err
207
+ })
208
+
209
+ if err != nil {
210
+ log .Error (err , "cannot patch capiv1beta1.Cluster" )
211
+
212
+ return ctrl.Result {}, err
213
+ }
214
+ }
215
+
195
216
// Before continuing, the Cluster object needs some validation, such as:
196
217
// 1. an assigned Control Plane endpoint
197
218
// 2. a ready infrastructure
@@ -288,7 +309,6 @@ func (r *KamajiControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
288
309
err = r .updateKamajiControlPlaneStatus (ctx , & kcp , func () {
289
310
kcp .Status .Ready = * tcp .Status .Kubernetes .Version .Status == kamajiv1alpha1 .VersionReady || * tcp .Status .Kubernetes .Version .Status == kamajiv1alpha1 .VersionUpgrading
290
311
})
291
-
292
312
if err != nil {
293
313
return err
294
314
}
0 commit comments