Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deprecate propagate labels feature
Browse files Browse the repository at this point in the history
Signed-off-by: Alexandr Demicev <[email protected]>
alexander-demicev committed Jan 22, 2025

Verified

This commit was signed with the committer’s verified signature.
alexander-demicev Alexander Demicev
1 parent f3d320e commit 45533ee
Showing 9 changed files with 63 additions and 152 deletions.
128 changes: 61 additions & 67 deletions charts/rancher-turtles/questions.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,66 @@
namespace: rancher-turtles-system
questions:
- variable: rancherTurtles.features.default
default: "false"
description: "Customize install settings"
label: Customize install settings
type: boolean
show_subquestion_if: true
group: "Rancher Turtles Extra Settings"
subquestions:
- variable: cluster-api-operator.cert-manager.enabled
default: false
- variable: rancherTurtles.features.default
default: "false"
description: "Customize install settings"
label: Customize install settings
type: boolean
description: "Flag to enable or disable installation of cert-manager. If set to false then you will need to install cert-manager manually"
label: "Enable Cert Manager"
- variable: rancherTurtles.features.cluster-api-operator.cleanup
default: true
description: "Specify that the CAPI Operator post-delete cleanup job will be performed"
type: boolean
label: Cleanup CAPI Operator installation
group: "CAPI Operator cleanup settings"
show_subquestion_if: true
group: "Rancher Turtles Extra Settings"
subquestions:
- variable: rancherTurtles.features.cluster-api-operator.kubectlImage
default: "registry.k8s.io/kubernetes/kubectl:v1.30.0"
description: "Specify the image to use when cleaning up the Cluster API Operator manifests"
type: string
label: Cleanup Image
group: "CAPI Operator cleanup settings"
- variable: rancherTurtles.features.rancher-webhook.cleanup
default: true
description: "Specify that the Rancher embedded cluster api webhooks should be removed"
type: boolean
label: Cleanup Rancher Embedded CAPI Webhooks
group: "Rancher webhook cleanup settings"
show_subquestion_if: true
subquestions:
- variable: rancherTurtles.features.rancher-webhook.kubectlImage
default: "registry.k8s.io/kubernetes/kubectl:v1.30.0"
description: "Specify the image to use when cleaning up the webhooks"
type: string
label: Webhook Cleanup Image
group: "Rancher webhook cleanup settings"
- variable: rancherTurtles.features.rancher-kubeconfigs.label
default: false
description: "(Experimental) Specify that the kubeconfigs generated by Rancher should be automatically patched to contain the CAPI expected labels"
type: boolean
label: Label Rancher Kubeconfigs
group: "Rancher Turtles Features Settings"
- variable: cluster-api-operator.cluster-api.rke2.enabled
default: "true"
description: "Flag to enable or disable installation of the RKE2 provider for Cluster API. By default this is enabled."
label: "Enable RKE2 Provider"
type: boolean
- variable: rancherTurtles.features.propagate-labels.enabled
default: false
description: "(Experimental) Specify that the labels from CAPI should be propagated to Rancher"
type: boolean
label: Propagate CAPI Labels
group: "Rancher Turtles Features Settings"
- variable: rancherTurtles.features.addon-provider-fleet.enabled
default: true
description: "Enable Fleet Addon Provider functionality in Rancher Turtles"
type: boolean
label: Seamless integration with Fleet and CAPI
group: "Rancher Turtles Features Settings"
- variable: rancherTurtles.features.agent-tls-mode.enabled
default: false
description: "If enabled Turtles will use the agent-tls-mode setting to determine CA cert trust mode for importing clusters"
type: boolean
label: Enable Agent TLS Mode
group: "Rancher Turtles Features Settings"
- variable: cluster-api-operator.cert-manager.enabled
default: false
type: boolean
description: "Flag to enable or disable installation of cert-manager. If set to false then you will need to install cert-manager manually"
label: "Enable Cert Manager"
- variable: rancherTurtles.features.cluster-api-operator.cleanup
default: true
description: "Specify that the CAPI Operator post-delete cleanup job will be performed"
type: boolean
label: Cleanup CAPI Operator installation
group: "CAPI Operator cleanup settings"
show_subquestion_if: true
subquestions:
- variable: rancherTurtles.features.cluster-api-operator.kubectlImage
default: "registry.k8s.io/kubernetes/kubectl:v1.30.0"
description: "Specify the image to use when cleaning up the Cluster API Operator manifests"
type: string
label: Cleanup Image
group: "CAPI Operator cleanup settings"
- variable: rancherTurtles.features.rancher-webhook.cleanup
default: true
description: "Specify that the Rancher embedded cluster api webhooks should be removed"
type: boolean
label: Cleanup Rancher Embedded CAPI Webhooks
group: "Rancher webhook cleanup settings"
show_subquestion_if: true
subquestions:
- variable: rancherTurtles.features.rancher-webhook.kubectlImage
default: "registry.k8s.io/kubernetes/kubectl:v1.30.0"
description: "Specify the image to use when cleaning up the webhooks"
type: string
label: Webhook Cleanup Image
group: "Rancher webhook cleanup settings"
- variable: rancherTurtles.features.rancher-kubeconfigs.label
default: false
description: "(Experimental) Specify that the kubeconfigs generated by Rancher should be automatically patched to contain the CAPI expected labels"
type: boolean
label: Label Rancher Kubeconfigs
group: "Rancher Turtles Features Settings"
- variable: cluster-api-operator.cluster-api.rke2.enabled
default: "true"
description: "Flag to enable or disable installation of the RKE2 provider for Cluster API. By default this is enabled."
label: "Enable RKE2 Provider"
type: boolean
- variable: rancherTurtles.features.addon-provider-fleet.enabled
default: true
description: "Enable Fleet Addon Provider functionality in Rancher Turtles"
type: boolean
label: Seamless integration with Fleet and CAPI
group: "Rancher Turtles Features Settings"
- variable: rancherTurtles.features.agent-tls-mode.enabled
default: false
description: "If enabled Turtles will use the agent-tls-mode setting to determine CA cert trust mode for importing clusters"
type: boolean
label: Enable Agent TLS Mode
group: "Rancher Turtles Features Settings"
2 changes: 1 addition & 1 deletion charts/rancher-turtles/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ spec:
containers:
- args:
- --leader-elect
- --feature-gates=propagate-labels={{ index .Values "rancherTurtles" "features" "propagate-labels" "enabled"}},rancher-kube-secret-patch={{ index .Values "rancherTurtles" "features" "rancher-kubeconfigs" "label"}},addon-provider-fleet={{ index .Values "rancherTurtles" "features" "addon-provider-fleet" "enabled"}},agent-tls-mode={{ index .Values "rancherTurtles" "features" "agent-tls-mode" "enabled"}}
- --feature-gates=rancher-kube-secret-patch={{ index .Values "rancherTurtles" "features" "rancher-kubeconfigs" "label"}},addon-provider-fleet={{ index .Values "rancherTurtles" "features" "addon-provider-fleet" "enabled"}},agent-tls-mode={{ index .Values "rancherTurtles" "features" "agent-tls-mode" "enabled"}}
{{- range .Values.rancherTurtles.managerArguments }}
- {{ . }}
{{- end }}
2 changes: 0 additions & 2 deletions charts/rancher-turtles/values.yaml
Original file line number Diff line number Diff line change
@@ -17,8 +17,6 @@ rancherTurtles:
kubectlImage: registry.k8s.io/kubernetes/kubectl:v1.30.0
rancher-kubeconfigs:
label: false
propagate-labels:
enabled: false
etcd-snapshot-restore:
enabled: false
image: controller
5 changes: 0 additions & 5 deletions feature/feature.go
Original file line number Diff line number Diff line change
@@ -26,10 +26,6 @@ const (
// secrets so that they can be used with CAPI 1.5.x.
RancherKubeSecretPatch featuregate.Feature = "rancher-kube-secret-patch" //nolint:gosec

// PropagateLabels is used to enable copying the labels from the CAPI cluster
// to the Rancher cluster.
PropagateLabels featuregate.Feature = "propagate-labels"

// ExternalFleet allows to disable in-tree management of the Fleet clusters
// in the imported rancher clusters, by setting "provisioning.cattle.io/externally-managed"
// annotation.
@@ -46,7 +42,6 @@ func init() {

var defaultGates = map[featuregate.Feature]featuregate.FeatureSpec{
RancherKubeSecretPatch: {Default: false, PreRelease: featuregate.Beta},
PropagateLabels: {Default: false, PreRelease: featuregate.Beta},
ExternalFleet: {Default: true, PreRelease: featuregate.Beta},
AgentTLSMode: {Default: false, PreRelease: featuregate.Beta},
}
24 changes: 0 additions & 24 deletions internal/controllers/import_controller.go
Original file line number Diff line number Diff line change
@@ -234,12 +234,6 @@ func (r *CAPIImportReconciler) reconcileNormal(ctx context.Context, capiCluster
},
}

if feature.Gates.Enabled(feature.PropagateLabels) {
for labelKey, labelVal := range capiCluster.Labels {
newCluster.Labels[labelKey] = labelVal
}
}

if err := r.RancherClient.Create(ctx, newCluster); err != nil {
return ctrl.Result{}, fmt.Errorf("error creating rancher cluster: %w", err)
}
@@ -303,24 +297,6 @@ func (r *CAPIImportReconciler) reconcileNormal(ctx context.Context, capiCluster

log.Info("Successfully applied import manifest")

if feature.Gates.Enabled(feature.PropagateLabels) {
patchBase := client.MergeFromWithOptions(rancherCluster.DeepCopy(), client.MergeFromWithOptimisticLock{})

if rancherCluster.Labels == nil {
rancherCluster.Labels = map[string]string{}
}

for labelKey, labelVal := range capiCluster.Labels {
rancherCluster.Labels[labelKey] = labelVal
}

if err := r.Client.Patch(ctx, rancherCluster, patchBase); err != nil {
return ctrl.Result{}, fmt.Errorf("failed to patch Rancher cluster: %w", err)
}

log.Info("Successfully propagated labels to Rancher cluster")
}

return ctrl.Result{}, nil
}

16 changes: 0 additions & 16 deletions internal/controllers/import_controller_test.go
Original file line number Diff line number Diff line change
@@ -42,11 +42,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

var (
testLabelName = "test-label"
testLabelVal = "true"
)

var _ = Describe("reconcile CAPI Cluster", func() {
var (
r *CAPIImportReconciler
@@ -168,7 +163,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
It("should reconcile a CAPI cluster when rancher cluster doesn't exist", func() {
capiCluster.Labels = map[string]string{
importLabelName: "true",
testLabelName: testLabelVal,
}
Expect(cl.Create(ctx, capiCluster)).To(Succeed())
capiCluster.Status.ControlPlaneReady = true
@@ -184,11 +178,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(err).ToNot(HaveOccurred())
g.Expect(res.Requeue).To(BeTrue())
}).Should(Succeed())

Eventually(ctx, func(g Gomega) {
g.Expect(cl.Get(ctx, client.ObjectKeyFromObject(rancherCluster), rancherCluster)).To(Succeed())
g.Expect(rancherCluster.Labels).To(HaveKeyWithValue(testLabelName, testLabelVal))
}).Should(Succeed())
})

It("should reconcile a CAPI cluster when rancher cluster doesn't exist and annotation is set on the namespace", func() {
@@ -217,9 +206,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
}))
defer server.Close()

capiCluster.Labels = map[string]string{
testLabelName: testLabelVal,
}
Expect(cl.Create(ctx, capiCluster)).To(Succeed())
capiCluster.Status.ControlPlaneReady = true
Expect(cl.Status().Update(ctx, capiCluster)).To(Succeed())
@@ -262,8 +248,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
}, unstructuredObj)).To(Succeed())
}

g.Expect(cl.Get(ctx, client.ObjectKeyFromObject(rancherCluster), rancherCluster)).To(Succeed())
g.Expect(rancherCluster.Labels).To(HaveKeyWithValue(testLabelName, testLabelVal))
}, 30*time.Second).Should(Succeed())
})

24 changes: 0 additions & 24 deletions internal/controllers/import_controller_v3.go
Original file line number Diff line number Diff line change
@@ -299,7 +299,6 @@ func (r *CAPIImportManagementV3Reconciler) reconcileNormal(ctx context.Context,

r.optOutOfClusterOwner(ctx, rancherCluster)
r.optOutOfFleetManagement(ctx, rancherCluster)
r.propagateLabels(ctx, capiCluster, rancherCluster)

addedFinalizer := controllerutil.AddFinalizer(rancherCluster, managementv3.CapiClusterFinalizer)
if addedFinalizer {
@@ -572,26 +571,3 @@ func (r *CAPIImportManagementV3Reconciler) optOutOfFleetManagement(ctx context.C
log.Info("Added fleet annotation to Rancher cluster")
}
}

func (r *CAPIImportManagementV3Reconciler) propagateLabels(
ctx context.Context,
capiCluster *clusterv1.Cluster,
rancherCluster *managementv3.Cluster,
) {
log := log.FromContext(ctx)

labels := rancherCluster.GetLabels()
if rancherCluster.Labels == nil {
labels = map[string]string{}
}

if feature.Gates.Enabled(feature.PropagateLabels) {
for labelKey, labelVal := range capiCluster.Labels {
labels[labelKey] = labelVal
}

rancherCluster.SetLabels(labels)

log.V(5).Info("Propagated labels to Rancher cluster")
}
}
11 changes: 0 additions & 11 deletions internal/controllers/import_controller_v3_test.go
Original file line number Diff line number Diff line change
@@ -178,7 +178,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
Expect(cl.Update(ctx, ns)).To(Succeed())
capiCluster.Labels = map[string]string{
importLabelName: "true",
testLabelName: testLabelVal,
}
Expect(cl.Create(ctx, capiCluster)).To(Succeed())
capiCluster.Status.ControlPlaneReady = true
@@ -199,7 +198,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(cl.List(ctx, rancherClusters, selectors...)).ToNot(HaveOccurred())
g.Expect(rancherClusters.Items).To(HaveLen(1))
g.Expect(rancherClusters.Items[0].Name).To(ContainSubstring("c-"))
g.Expect(rancherClusters.Items[0].Labels).To(HaveKeyWithValue(testLabelName, testLabelVal))
g.Expect(rancherClusters.Items[0].Annotations).To(HaveKey(turtlesannotations.NoCreatorRBACAnnotation))
g.Expect(rancherClusters.Items[0].Finalizers).To(ContainElement(managementv3.CapiClusterFinalizer))
}).Should(Succeed())
@@ -253,7 +251,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(cl.List(ctx, rancherClusters, selectors...)).ToNot(HaveOccurred())
g.Expect(rancherClusters.Items).To(HaveLen(1))
}).Should(Succeed())
Expect(rancherClusters.Items[0].Annotations).To(HaveKeyWithValue(externalFleetAnnotation, testLabelVal))
})

It("should reconcile a CAPI cluster when rancher cluster exists, and have finalizers set", func() {
@@ -263,9 +260,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
}))
defer server.Close()

capiCluster.Labels = map[string]string{
testLabelName: testLabelVal,
}
Expect(cl.Create(ctx, capiCluster)).To(Succeed())
capiCluster.Status.ControlPlaneReady = true
Expect(cl.Status().Update(ctx, capiCluster)).To(Succeed())
@@ -324,7 +318,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(cl.List(ctx, rancherClusters, selectors...)).ToNot(HaveOccurred())
g.Expect(rancherClusters.Items).To(HaveLen(1))
g.Expect(rancherClusters.Items[0].Name).To(ContainSubstring("c-"))
g.Expect(rancherClusters.Items[0].Labels).To(HaveKeyWithValue(testLabelName, testLabelVal))
g.Expect(rancherClusters.Items[0].Finalizers).To(ContainElement(managementv3.CapiClusterFinalizer))
}, 10*time.Second).Should(Succeed())
})
@@ -468,7 +461,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {

rancherCluster := cluster.DeepCopy()
g.Expect(cl.Get(ctx, client.ObjectKeyFromObject(&cluster), rancherCluster)).To(Succeed())
g.Expect(rancherCluster.Annotations).To(HaveKeyWithValue(externalFleetAnnotation, testLabelVal))
}, 5*time.Second).Should(Succeed())
})

@@ -551,7 +543,6 @@ var _ = Describe("reconcile CAPI Cluster", func() {
Expect(cl.Update(ctx, ns)).To(Succeed())
capiCluster.Labels = map[string]string{
importLabelName: "true",
testLabelName: testLabelVal,
}
Expect(cl.Create(ctx, capiCluster)).To(Succeed())
capiCluster.Status.ControlPlaneReady = true
@@ -586,15 +577,13 @@ var _ = Describe("reconcile CAPI Cluster", func() {
g.Expect(rancherClusters.Items).To(HaveLen(1))
}).Should(Succeed())
Expect(rancherClusters.Items[0].Name).To(ContainSubstring("c-"))
Expect(rancherClusters.Items[0].Labels).To(HaveKeyWithValue(testLabelName, testLabelVal))
})

It("should reconcile a CAPI Cluster when V1 cluster exists and not migrated", func() {
ns.Labels = map[string]string{}
Expect(cl.Update(ctx, ns)).To(Succeed())
capiCluster.Labels = map[string]string{
importLabelName: "true",
testLabelName: testLabelVal,
}
Expect(cl.Create(ctx, capiCluster)).To(Succeed())
capiCluster.Status.ControlPlaneReady = true
3 changes: 1 addition & 2 deletions internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
@@ -53,8 +53,7 @@ var (

func init() {
utilruntime.Must(feature.MutableGates.SetFromMap(map[string]bool{
string(feature.PropagateLabels): true,
string(feature.ExternalFleet): true,
string(feature.ExternalFleet): true,
}))
}

0 comments on commit 45533ee

Please sign in to comment.