Skip to content

Commit

Permalink
feat: support optional infra cluster via feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
phoban01 committed Nov 7, 2024
1 parent 5dc7d2b commit a51d259
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
40 changes: 30 additions & 10 deletions controllers/kamajicontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

kcpv1alpha1 "github.com/clastix/cluster-api-control-plane-provider-kamaji/api/v1alpha1"
"github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/externalclusterreference"
"github.com/clastix/cluster-api-control-plane-provider-kamaji/pkg/features"
)

// KamajiControlPlaneReconciler reconciles a KamajiControlPlane object.
Expand Down Expand Up @@ -179,19 +180,39 @@ func (r *KamajiControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R

return ctrl.Result{}, err
}
// Patching the Infrastructure Cluster:
// this will be removed on the upcoming Kamaji Control Plane versions.
TrackConditionType(&conditions, kcpv1alpha1.InfrastructureClusterPatchedConditionType, kcp.Generation, func() error {
err = r.patchCluster(ctx, cluster, &kcp, tcp.Status.ControlPlaneEndpoint)

return err
})
// We need to fetch the updated cluster resource here because otherwise the cluster.spec.controlPlaneEndpoint.Host
// check that happens latter will never succeed.
if err = r.client.Get(ctx, types.NamespacedName{Name: cluster.Name, Namespace: cluster.Namespace}, &cluster); err != nil {
if errors.IsNotFound(err) {
log.Info("capiv1beta1.Cluster resource may have been deleted, withdrawing reconciliation")

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

return ctrl.Result{}, err
log.Error(err, "unable to get capiv1beta1.Cluster")

return ctrl.Result{}, err //nolint:wrapcheck
}

// The following code path will be skipped when the InfraClusterOptional=true. This enables
// the use of a KamajiControlPlane without an infrastructure cluster.
if !r.FeatureGates.Enabled(features.SkipInfraClusterPatch) {
// Patching the Infrastructure Cluster:
// this will be removed on the upcoming Kamaji Control Plane versions.
TrackConditionType(&conditions, kcpv1alpha1.InfrastructureClusterPatchedConditionType, kcp.Generation, func() error {
err = r.patchCluster(ctx, cluster, &kcp, tcp.Status.ControlPlaneEndpoint)

return err
})

if err != nil {
log.Error(err, "cannot patch capiv1beta1.Cluster")

return ctrl.Result{}, err
}
}

// Before continuing, the Cluster object needs some validation, such as:
// 1. an assigned Control Plane endpoint
// 2. a ready infrastructure
Expand Down Expand Up @@ -288,7 +309,6 @@ func (r *KamajiControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R
err = r.updateKamajiControlPlaneStatus(ctx, &kcp, func() {
kcp.Status.Ready = *tcp.Status.Kubernetes.Version.Status == kamajiv1alpha1.VersionReady || *tcp.Status.Kubernetes.Version.Status == kamajiv1alpha1.VersionUpgrading
})

if err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func main() {
LockToDefault: false,
PreRelease: featuregate.Alpha,
},
features.SkipInfraClusterPatch: {
Default: false,
LockToDefault: false,
PreRelease: featuregate.Alpha,
},
}); err != nil {
setupLog.Error(err, "unable to add feature gates")
os.Exit(1)
Expand Down
3 changes: 3 additions & 0 deletions pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ const (
// ExternalClusterReferenceCrossNamespace allows deploying Tenant Control Plane pods to a different cluster from the Management one.
// It supports referencing a kubeconfig available in a different Namespace than the KamajiControlPlane.
ExternalClusterReferenceCrossNamespace = "ExternalClusterReferenceCrossNamespace"

// SkipInfraClusterPatch bypasses patching the InfraCluster with the control-plane endpoint.
SkipInfraClusterPatch = "SkipInfraClusterPatch"
)

0 comments on commit a51d259

Please sign in to comment.