Skip to content

Commit 7eaf63a

Browse files
committed
feat: support optional infra cluster via feature flag
1 parent 5dc7d2b commit 7eaf63a

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

controllers/kamajicontrolplane_controller.go

+30-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package controllers
66
import (
77
"context"
88
"fmt"
9+
"github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/features"
910
"time"
1011

1112
kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1"
@@ -179,19 +180,39 @@ func (r *KamajiControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
179180

180181
return ctrl.Result{}, err
181182
}
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)
186183

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")
189189

190-
if err != nil {
191-
log.Error(err, "cannot patch capiv1beta1.Cluster")
190+
return ctrl.Result{}, nil
191+
}
192192

193-
return ctrl.Result{}, err
193+
log.Error(err, "unable to get capiv1beta1.Cluster")
194+
195+
return ctrl.Result{}, err //nolint:wrapcheck
194196
}
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+
195216
// Before continuing, the Cluster object needs some validation, such as:
196217
// 1. an assigned Control Plane endpoint
197218
// 2. a ready infrastructure

main.go

+5
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ func main() {
6363
LockToDefault: false,
6464
PreRelease: featuregate.Alpha,
6565
},
66+
features.SkipInfraClusterPatch: {
67+
Default: false,
68+
LockToDefault: false,
69+
PreRelease: featuregate.Alpha,
70+
},
6671
}); err != nil {
6772
setupLog.Error(err, "unable to add feature gates")
6873
os.Exit(1)

pkg/features/features.go

+3
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ const (
1111
// ExternalClusterReferenceCrossNamespace allows deploying Tenant Control Plane pods to a different cluster from the Management one.
1212
// It supports referencing a kubeconfig available in a different Namespace than the KamajiControlPlane.
1313
ExternalClusterReferenceCrossNamespace = "ExternalClusterReferenceCrossNamespace"
14+
15+
// SkipInfraClusterPatch bypasses patching the InfraCluster with the control-plane endpoint.
16+
SkipInfraClusterPatch = "SkipInfraClusterPatch"
1417
)

0 commit comments

Comments
 (0)