Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support optional infra cluster via feature flag #147

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/control-plane-components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13477,7 +13477,7 @@ spec:
containers:
- args:
- --leader-elect
- --feature-gates=ExternalClusterReference=${CACPPK_EXTERNAL_CLUSTER_REFERENCE:=false},ExternalClusterReferenceCrossNamespace=${CACPPK_EXTERNAL_CLUSTER_REFERENCE_CROSS_NAMESPACE:=false}
- --feature-gates=ExternalClusterReference=${CACPPK_EXTERNAL_CLUSTER_REFERENCE:=false},ExternalClusterReferenceCrossNamespace=${CACPPK_EXTERNAL_CLUSTER_REFERENCE_CROSS_NAMESPACE:=false},SkipInfraClusterPatch=${CACPPK_SKIP_INFRA_CLUSTER_PATCH:=false}
command:
- /manager
image: docker.io/clastix/cluster-api-control-plane-provider-kamaji:v0.12.0
Expand Down
2 changes: 1 addition & 1 deletion config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ spec:
- /manager
args:
- --leader-elect
- "--feature-gates=ExternalClusterReference=${CACPPK_EXTERNAL_CLUSTER_REFERENCE:=false},ExternalClusterReferenceCrossNamespace=${CACPPK_EXTERNAL_CLUSTER_REFERENCE_CROSS_NAMESPACE:=false}"
- "--feature-gates=ExternalClusterReference=${CACPPK_EXTERNAL_CLUSTER_REFERENCE:=false},ExternalClusterReferenceCrossNamespace=${CACPPK_EXTERNAL_CLUSTER_REFERENCE_CROSS_NAMESPACE:=false},SkipInfraClusterPatch=${CACPPK_SKIP_INFRA_CLUSTER_PATCH:=false}"
image: controller:latest
name: manager
securityContext:
Expand Down
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"
)
Loading