Skip to content

Commit b3d2f9c

Browse files
authored
feat: support optional infra cluster via feature flag (#147)
* feat: support optional infra cluster via feature flag * chore: add SkipInfraClusterPatch flag envvar to manager.yaml * chore: update generated config
1 parent 5dc7d2b commit b3d2f9c

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

config/control-plane-components.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13477,7 +13477,7 @@ spec:
1347713477
containers:
1347813478
- args:
1347913479
- --leader-elect
13480-
- --feature-gates=ExternalClusterReference=${CACPPK_EXTERNAL_CLUSTER_REFERENCE:=false},ExternalClusterReferenceCrossNamespace=${CACPPK_EXTERNAL_CLUSTER_REFERENCE_CROSS_NAMESPACE:=false}
13480+
- --feature-gates=ExternalClusterReference=${CACPPK_EXTERNAL_CLUSTER_REFERENCE:=false},ExternalClusterReferenceCrossNamespace=${CACPPK_EXTERNAL_CLUSTER_REFERENCE_CROSS_NAMESPACE:=false},SkipInfraClusterPatch=${CACPPK_SKIP_INFRA_CLUSTER_PATCH:=false}
1348113481
command:
1348213482
- /manager
1348313483
image: docker.io/clastix/cluster-api-control-plane-provider-kamaji:v0.12.0

config/manager/manager.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ spec:
7070
- /manager
7171
args:
7272
- --leader-elect
73-
- "--feature-gates=ExternalClusterReference=${CACPPK_EXTERNAL_CLUSTER_REFERENCE:=false},ExternalClusterReferenceCrossNamespace=${CACPPK_EXTERNAL_CLUSTER_REFERENCE_CROSS_NAMESPACE:=false}"
73+
- "--feature-gates=ExternalClusterReference=${CACPPK_EXTERNAL_CLUSTER_REFERENCE:=false},ExternalClusterReferenceCrossNamespace=${CACPPK_EXTERNAL_CLUSTER_REFERENCE_CROSS_NAMESPACE:=false},SkipInfraClusterPatch=${CACPPK_SKIP_INFRA_CLUSTER_PATCH:=false}"
7474
image: controller:latest
7575
name: manager
7676
securityContext:

controllers/kamajicontrolplane_controller.go

+30-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
kcpv1alpha1 "github.com/clastix/cluster-api-control-plane-provider-kamaji/api/v1alpha1"
3232
"github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/externalclusterreference"
33+
"github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/features"
3334
)
3435

3536
// KamajiControlPlaneReconciler reconciles a KamajiControlPlane object.
@@ -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
@@ -288,7 +309,6 @@ func (r *KamajiControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
288309
err = r.updateKamajiControlPlaneStatus(ctx, &kcp, func() {
289310
kcp.Status.Ready = *tcp.Status.Kubernetes.Version.Status == kamajiv1alpha1.VersionReady || *tcp.Status.Kubernetes.Version.Status == kamajiv1alpha1.VersionUpgrading
290311
})
291-
292312
if err != nil {
293313
return err
294314
}

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)