@@ -6,6 +6,7 @@ package controllers
6
6
import (
7
7
"context"
8
8
"fmt"
9
+ "github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/features"
9
10
"time"
10
11
11
12
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
@@ -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
0 commit comments