From 0fd81f6073c41a60e458fb5e6e1ebe14cd679e9d Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Wed, 22 Jan 2025 11:40:50 +0100 Subject: [PATCH] Remove rancher-kubeconfigs feature Current rancher version used with turtles uses CAPI 1.9, so the feature is no longer needed and thus removed. Signed-off-by: Danil-Grigorev --- .github/workflows/e2e-long.yaml | 12 +- charts/rancher-turtles/questions.yml | 6 - .../rancher-turtles/templates/deployment.yaml | 2 +- charts/rancher-turtles/values.yaml | 2 - feature/feature.go | 9 +- internal/controllers/import_controller_v3.go | 1 + internal/controllers/patch_kcfg_controller.go | 161 ------------- .../controllers/patch_kcfg_controller_test.go | 216 ------------------ main.go | 16 -- test/e2e/suites/update-labels/suite_test.go | 122 ---------- .../update-labels/update_labels_test.go | 193 ---------------- 11 files changed, 5 insertions(+), 735 deletions(-) delete mode 100644 internal/controllers/patch_kcfg_controller.go delete mode 100644 internal/controllers/patch_kcfg_controller_test.go delete mode 100644 test/e2e/suites/update-labels/suite_test.go delete mode 100644 test/e2e/suites/update-labels/update_labels_test.go diff --git a/.github/workflows/e2e-long.yaml b/.github/workflows/e2e-long.yaml index 0c615c12..2678aa52 100644 --- a/.github/workflows/e2e-long.yaml +++ b/.github/workflows/e2e-long.yaml @@ -31,18 +31,8 @@ jobs: artifact_name: artifacts_v2prov MANAGEMENT_CLUSTER_ENVIRONMENT: eks secrets: inherit - e2e_update_labels: - needs: publish_e2e_image - uses: ./.github/workflows/run-e2e-suite.yaml - with: - test_suite: test/e2e/suites/update-labels - test_name: Update labels - run_azure_janitor: false - artifact_name: artifacts_update_labels - MANAGEMENT_CLUSTER_ENVIRONMENT: eks - secrets: inherit clean_e2e_image: if: always() - needs: [e2e_import_gitops_v3, e2e_v2prov, e2e_update_labels] + needs: [e2e_import_gitops_v3, e2e_v2prov] uses: ./.github/workflows/e2e-image-clean.yaml secrets: inherit diff --git a/charts/rancher-turtles/questions.yml b/charts/rancher-turtles/questions.yml index 68b535d2..e0a1e85d 100644 --- a/charts/rancher-turtles/questions.yml +++ b/charts/rancher-turtles/questions.yml @@ -19,12 +19,6 @@ questions: type: boolean label: Cleanup CAPI Operator installation group: "CAPI Operator 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." diff --git a/charts/rancher-turtles/templates/deployment.yaml b/charts/rancher-turtles/templates/deployment.yaml index efd37cfd..fe3b803d 100644 --- a/charts/rancher-turtles/templates/deployment.yaml +++ b/charts/rancher-turtles/templates/deployment.yaml @@ -26,7 +26,7 @@ spec: containers: - args: - --leader-elect - - --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"}} + - --feature-gates=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 }} diff --git a/charts/rancher-turtles/values.yaml b/charts/rancher-turtles/values.yaml index 3aa032fe..82574a5f 100644 --- a/charts/rancher-turtles/values.yaml +++ b/charts/rancher-turtles/values.yaml @@ -8,8 +8,6 @@ rancherTurtles: rancherInstalled: true kubectlImage: registry.k8s.io/kubernetes/kubectl:v1.30.0 features: - rancher-kubeconfigs: - label: false etcd-snapshot-restore: enabled: false image: controller diff --git a/feature/feature.go b/feature/feature.go index 0094b3a1..4864f3c9 100644 --- a/feature/feature.go +++ b/feature/feature.go @@ -22,10 +22,6 @@ import ( ) const ( - // RancherKubeSecretPatch is used to enable patching of the Rancher v2prov created kubeconfig - // secrets so that they can be used with CAPI 1.5.x. - RancherKubeSecretPatch featuregate.Feature = "rancher-kube-secret-patch" //nolint:gosec - // ExternalFleet allows to disable in-tree management of the Fleet clusters // in the imported rancher clusters, by setting "provisioning.cattle.io/externally-managed" // annotation. @@ -41,7 +37,6 @@ func init() { } var defaultGates = map[featuregate.Feature]featuregate.FeatureSpec{ - RancherKubeSecretPatch: {Default: false, PreRelease: featuregate.Beta}, - ExternalFleet: {Default: true, PreRelease: featuregate.Beta}, - AgentTLSMode: {Default: false, PreRelease: featuregate.Beta}, + ExternalFleet: {Default: true, PreRelease: featuregate.Beta}, + AgentTLSMode: {Default: false, PreRelease: featuregate.Beta}, } diff --git a/internal/controllers/import_controller_v3.go b/internal/controllers/import_controller_v3.go index e109a15d..1c1eab0e 100644 --- a/internal/controllers/import_controller_v3.go +++ b/internal/controllers/import_controller_v3.go @@ -136,6 +136,7 @@ func (r *CAPIImportManagementV3Reconciler) SetupWithManager(ctx context.Context, // +kubebuilder:rbac:groups=infrastructure.cluster.x-k8s.io,resources=*,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=management.cattle.io,resources=clusters;clusters/status;clusterregistrationtokens,verbs=get;list;watch;create;update;delete;deletecollection;patch // +kubebuilder:rbac:groups=management.cattle.io,resources=clusterregistrationtokens/status;settings,verbs=get;list;watch +// +kubebuilder:rbac:groups=provisioning.cattle.io,resources=clusters;clusters/status,verbs=get;list;watch // //nolint:lll diff --git a/internal/controllers/patch_kcfg_controller.go b/internal/controllers/patch_kcfg_controller.go deleted file mode 100644 index 46fb24d4..00000000 --- a/internal/controllers/patch_kcfg_controller.go +++ /dev/null @@ -1,161 +0,0 @@ -/* -Copyright © 2023 - 2024 SUSE LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controllers - -import ( - "context" - "fmt" - - corev1 "k8s.io/api/core/v1" - apierrors "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/types" - "k8s.io/client-go/tools/record" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/controller" - "sigs.k8s.io/controller-runtime/pkg/log" - - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/controllers/external" - "sigs.k8s.io/cluster-api/util/predicates" - - provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" - turtlespredicates "github.com/rancher/turtles/util/predicates" -) - -// RancherKubeconfigSecretReconciler is a controller that will reconcile secrets created by Rancher as -// part of provisioning v2. Its job is to add the label required by Cluster API v1.5.0 and higher. -type RancherKubeconfigSecretReconciler struct { - Client client.Client - recorder record.EventRecorder - WatchFilterValue string - Scheme *runtime.Scheme - - controller controller.Controller - externalTracker external.ObjectTracker -} - -// SetupWithManager will setup the controller. -func (r *RancherKubeconfigSecretReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, options controller.Options) error { - log := log.FromContext(ctx) - - capiPredicates := predicates.All(r.Scheme, log, - turtlespredicates.V2ProvClusterOwned(log), - turtlespredicates.NameHasSuffix(log, "-kubeconfig"), - ) - - c, err := ctrl.NewControllerManagedBy(mgr). - For(&corev1.Secret{}). - WithOptions(options). - WithEventFilter(capiPredicates). - Build(r) - if err != nil { - return fmt.Errorf("creating new controller: %w", err) - } - - r.recorder = mgr.GetEventRecorderFor("rancher-turtles-v2prov") - r.controller = c - r.externalTracker = external.ObjectTracker{ - Controller: c, - } - - return nil -} - -// +kubebuilder:rbac:groups="",resources=secrets;events,verbs=get;list;watch;create;update;patch -// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;create;update -// +kubebuilder:rbac:groups=provisioning.cattle.io,resources=clusters;clusters/status,verbs=get;list;watch - -// Reconcile will patch v2prov created kubeconfig secrets to add the required owner label if its missing. -func (r *RancherKubeconfigSecretReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, reterr error) { - log := log.FromContext(ctx) - log.Info("Reconciling v2prov cluster") - - secret := &corev1.Secret{} - if err := r.Client.Get(ctx, req.NamespacedName, secret); err != nil { - if apierrors.IsNotFound(err) { - return ctrl.Result{Requeue: true}, nil - } - - return ctrl.Result{Requeue: true}, err - } - - if _, ok := secret.Labels[clusterv1.ClusterNameLabel]; ok { - log.V(4).Info("kubeconfig secret %s/%s already has the capi cluster label", secret.Name, secret.Name) - - return ctrl.Result{}, nil - } - - clusterName, err := r.getClusterName(ctx, secret) - if err != nil { - return ctrl.Result{}, fmt.Errorf("getting cluster name from secret: %w", err) - } - - if clusterName == "" { - log.Info("Could not determine cluster name from kubeconfig secret") - - return ctrl.Result{}, nil - } - - secretCopy := secret.DeepCopy() - if secretCopy.Labels == nil { - secretCopy.Labels = map[string]string{} - } - - secretCopy.Labels[clusterv1.ClusterNameLabel] = clusterName - - patchBase := client.MergeFromWithOptions(secret, client.MergeFromWithOptimisticLock{}) - - if err := r.Client.Patch(ctx, secretCopy, patchBase); err != nil { - return ctrl.Result{}, fmt.Errorf("failed to patch secret: %w", err) - } - - log.V(4).Info("patched kubeconfig secret", "name", secret.Name, "namespace", secret.Namespace, "cluster", clusterName) - - return ctrl.Result{}, nil -} - -func (r *RancherKubeconfigSecretReconciler) getClusterName(ctx context.Context, secret *corev1.Secret) (string, error) { - v2ProvClusterName := "" - - for _, ref := range secret.OwnerReferences { - if ref.APIVersion == provisioningv1.GroupVersion.Identifier() { - if ref.Kind == "Cluster" { - v2ProvClusterName = ref.Name - - break - } - } - } - - if v2ProvClusterName == "" { - return "", nil - } - - v2ProvCluster := &provisioningv1.Cluster{} - - if err := r.Client.Get(ctx, types.NamespacedName{Name: v2ProvClusterName, Namespace: secret.Namespace}, v2ProvCluster); err != nil { - return "", fmt.Errorf("getting rancher cluster: %w", err) - } - - if v2ProvCluster.Spec.RKEConfig == nil { - return "", nil - } - - return v2ProvCluster.Name, nil -} diff --git a/internal/controllers/patch_kcfg_controller_test.go b/internal/controllers/patch_kcfg_controller_test.go deleted file mode 100644 index 481d86d3..00000000 --- a/internal/controllers/patch_kcfg_controller_test.go +++ /dev/null @@ -1,216 +0,0 @@ -/* -Copyright © 2023 - 2024 SUSE LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package controllers - -import ( - "fmt" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "sigs.k8s.io/cluster-api/util/secret" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/reconcile" - - provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" - "github.com/rancher/turtles/internal/test" -) - -var _ = Describe("Patch Rancher v2Prov Kubeconfig secrets", func() { - var ( - r *RancherKubeconfigSecretReconciler - rancherCluster *provisioningv1.Cluster - kubeconfigSecret *corev1.Secret - clusterName string - ns *corev1.Namespace - ) - - BeforeEach(func() { - var err error - - ns, err = testEnv.CreateNamespace(ctx, "v2prov") - Expect(err).ToNot(HaveOccurred()) - - r = &RancherKubeconfigSecretReconciler{ - Client: cl, - } - clusterName = "test1" - - rancherCluster = &provisioningv1.Cluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: clusterName, - Namespace: ns.Name, - }, - TypeMeta: metav1.TypeMeta{ - Kind: "Cluster", - APIVersion: "provisioning.cattle.io/v1", - }, - Spec: provisioningv1.ClusterSpec{ - RKEConfig: &provisioningv1.RKEConfig{}, - }, - } - Expect(cl.Create(ctx, rancherCluster)).To(Succeed()) - - kubeconfigSecret = &corev1.Secret{ - ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-kubeconfig", clusterName), - Namespace: ns.Name, - OwnerReferences: []metav1.OwnerReference{ - { - APIVersion: "provisioning.cattle.io/v1", - Kind: "Cluster", - Name: clusterName, - UID: rancherCluster.UID, - }, - }, - }, - Data: map[string][]byte{ - secret.KubeconfigDataName: kubeConfigBytes, - }, - } - }) - - AfterEach(func() { - clientObjs := []client.Object{ - rancherCluster, - kubeconfigSecret, - } - Expect(test.CleanupAndWait(ctx, cl, clientObjs...)).To(Succeed()) - Expect(testEnv.Cleanup(ctx, ns)).To(Succeed()) - }) - - It("should add label to a v2prov secret", func() { - Expect(cl.Create(ctx, kubeconfigSecret)).To(Succeed()) - - _, err := r.Reconcile(ctx, reconcile.Request{ - NamespacedName: types.NamespacedName{ - Namespace: kubeconfigSecret.Namespace, - Name: kubeconfigSecret.Name, - }, - }) - Expect(err).NotTo(HaveOccurred()) - - updatedSecret := &corev1.Secret{} - Eventually(ctx, func(g Gomega) { - g.Expect(cl.Get(ctx, client.ObjectKeyFromObject(kubeconfigSecret), updatedSecret)).ToNot(HaveOccurred()) - g.Expect(updatedSecret.GetLabels()).To(HaveLen(1)) - }).Should(Succeed()) - - labvelVal, labelFound := updatedSecret.Labels["cluster.x-k8s.io/cluster-name"] - Expect(labelFound).To(BeTrue(), "Failed to find expected CAPI label") - Expect(labvelVal).To(Equal(clusterName)) - }) - - It("should not change anything if label already exists on v2prov secret", func() { - kubeconfigSecret.Labels = map[string]string{ - "cluster.x-k8s.io/cluster-name": clusterName, - } - Expect(cl.Create(ctx, kubeconfigSecret)).To(Succeed()) - - _, err := r.Reconcile(ctx, reconcile.Request{ - NamespacedName: types.NamespacedName{ - Namespace: kubeconfigSecret.Namespace, - Name: kubeconfigSecret.Name, - }, - }) - Expect(err).NotTo(HaveOccurred()) - - updatedSecret := &corev1.Secret{} - Eventually(ctx, func(g Gomega) { - g.Expect(cl.Get(ctx, client.ObjectKeyFromObject(kubeconfigSecret), updatedSecret)).ToNot(HaveOccurred()) - g.Expect(updatedSecret.Labels).To(HaveLen(1)) - labvelVal, labelFound := updatedSecret.Labels["cluster.x-k8s.io/cluster-name"] - g.Expect(labelFound).To(BeTrue(), "Failed to find expected CAPI label") - g.Expect(labvelVal).To(Equal(clusterName)) - g.Expect(kubeconfigSecret.ResourceVersion).To(Equal(updatedSecret.ResourceVersion), "Secret shouldn't have been updated") - }) - }) - - It("should not change already existing labels but add label to v2prov secret", func() { - // Add an label - kubeconfigSecret.Labels = map[string]string{ - "existing": "myvalue", - } - Expect(cl.Create(ctx, kubeconfigSecret)).To(Succeed()) - - Eventually(func(g Gomega) { - _, err := r.Reconcile(ctx, reconcile.Request{ - NamespacedName: types.NamespacedName{ - Namespace: kubeconfigSecret.Namespace, - Name: kubeconfigSecret.Name, - }, - }) - g.Expect(err).NotTo(HaveOccurred()) - - updatedSecret := &corev1.Secret{} - - g.Expect(cl.Get(ctx, client.ObjectKeyFromObject(kubeconfigSecret), updatedSecret)).ToNot(HaveOccurred()) - g.Expect(updatedSecret.GetLabels()).To(HaveLen(2)) - - labvelVal, labelFound := updatedSecret.Labels["cluster.x-k8s.io/cluster-name"] - g.Expect(labelFound).To(BeTrue(), "Failed to find expected CAPI label") - g.Expect(labvelVal).To(Equal(clusterName)) - - labvelVal, labelFound = updatedSecret.Labels["existing"] - g.Expect(labelFound).To(BeTrue(), "Failed to find existing label") - g.Expect(labvelVal).To(Equal("myvalue")) - }).Should(Succeed()) - - }) - - It("should not add a label to a non-v2prov secret", func() { - // Remove the owner ref on the secret - kubeconfigSecret.OwnerReferences = []metav1.OwnerReference{} - Expect(cl.Create(ctx, kubeconfigSecret)).To(Succeed()) - - _, err := r.Reconcile(ctx, reconcile.Request{ - NamespacedName: types.NamespacedName{ - Namespace: kubeconfigSecret.Namespace, - Name: kubeconfigSecret.Name, - }, - }) - Expect(err).NotTo(HaveOccurred()) - - Eventually(testEnv.GetAs(kubeconfigSecret, &corev1.Secret{})).Should(HaveField("Labels", HaveLen(0))) - }) - - It("should not add a label to a non-v2prov Rancher cluster secret", func() { - rancherClusterCopy := rancherCluster.DeepCopy() - rancherClusterCopy.Spec.RKEConfig = nil - err := cl.Update(ctx, rancherClusterCopy) - Expect(err).ShouldNot(HaveOccurred()) - - Expect(cl.Create(ctx, kubeconfigSecret)).To(Succeed()) - - _, err = r.Reconcile(ctx, reconcile.Request{ - NamespacedName: types.NamespacedName{ - Namespace: kubeconfigSecret.Namespace, - Name: kubeconfigSecret.Name, - }, - }) - Expect(err).NotTo(HaveOccurred()) - - updatedSecret := &corev1.Secret{} - Eventually(ctx, func(g Gomega) { - g.Expect(cl.Get(ctx, client.ObjectKeyFromObject(kubeconfigSecret), updatedSecret)).ToNot(HaveOccurred()) - g.Expect(updatedSecret.Labels).To(HaveLen(0)) - }) - }) -}) diff --git a/main.go b/main.go index 15216049..53a2b74e 100644 --- a/main.go +++ b/main.go @@ -254,22 +254,6 @@ func setupReconcilers(ctx context.Context, mgr ctrl.Manager) { os.Exit(1) } - if feature.Gates.Enabled(feature.RancherKubeSecretPatch) { - setupLog.Info("enabling Rancher kubeconfig secret patching") - - if err := (&controllers.RancherKubeconfigSecretReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - WatchFilterValue: watchFilterValue, - }).SetupWithManager(ctx, mgr, controller.Options{ - MaxConcurrentReconciles: concurrencyNumber, - CacheSyncTimeout: maxDuration, - }); err != nil { - setupLog.Error(err, "unable to create Rancher kubeconfig secret controller") - os.Exit(1) - } - } - setupLog.Info("enabling Clusterctl Config synchronization controller") if err := (&controllers.ClusterctlConfigReconciler{ diff --git a/test/e2e/suites/update-labels/suite_test.go b/test/e2e/suites/update-labels/suite_test.go deleted file mode 100644 index dc76d03b..00000000 --- a/test/e2e/suites/update-labels/suite_test.go +++ /dev/null @@ -1,122 +0,0 @@ -//go:build e2e -// +build e2e - -/* -Copyright © 2023 - 2024 SUSE LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package update_labels - -import ( - "context" - "encoding/json" - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/log/zap" - - "github.com/rancher/turtles/test/e2e" - "github.com/rancher/turtles/test/testenv" - capiframework "sigs.k8s.io/cluster-api/test/framework" - "sigs.k8s.io/cluster-api/test/framework/clusterctl" -) - -// Test suite global vars. -var ( - // e2eConfig to be used for this test, read from configPath. - e2eConfig *clusterctl.E2EConfig - - // hostName is the host name for the Rancher Manager server. - hostName string - - artifactsFolder string - - ctx = context.Background() - - setupClusterResult *testenv.SetupTestClusterResult - bootstrapClusterProxy capiframework.ClusterProxy -) - -func TestE2E(t *testing.T) { - RegisterFailHandler(Fail) - - ctrl.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) - - RunSpecs(t, "rancher-turtles-e2e-import-gitops") -} - -var _ = SynchronizedBeforeSuite( - func() []byte { - setupClusterResult = testenv.SetupTestCluster(ctx, testenv.SetupTestClusterInput{ - E2EConfig: e2e.LoadE2EConfig(), - Scheme: e2e.InitScheme(), - }) - - testenv.RancherDeployIngress(ctx, testenv.RancherDeployIngressInput{ - BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, - CustomIngress: e2e.NginxIngress, - DefaultIngressClassPatch: e2e.IngressClassPatch, - }) - - rancherHookResult := testenv.DeployRancher(ctx, testenv.DeployRancherInput{ - BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, - RancherPatches: [][]byte{e2e.RancherSettingPatch}, - }) - - testenv.DeployRancherTurtles(ctx, testenv.DeployRancherTurtlesInput{ - BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, - CAPIProvidersYAML: e2e.CapiProviders, - AdditionalValues: map[string]string{ - "cluster-api-operator.cluster-api.version": e2e.CAPIVersion, - "rancherTurtles.features.rancher-kubeconfigs.label": "true", // force to be true even if the default in the chart changes - }, - WaitForDeployments: testenv.DefaultDeployments, - }) - - testenv.RestartRancher(ctx, testenv.RestartRancherInput{ - BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, - }) - - data, err := json.Marshal(e2e.Setup{ - ClusterName: setupClusterResult.ClusterName, - KubeconfigPath: setupClusterResult.KubeconfigPath, - RancherHostname: rancherHookResult.Hostname, - }) - Expect(err).ToNot(HaveOccurred()) - return data - }, - func(sharedData []byte) { - setup := e2e.Setup{} - Expect(json.Unmarshal(sharedData, &setup)).To(Succeed()) - - hostName = setup.RancherHostname - e2eConfig = e2e.LoadE2EConfig() - - bootstrapClusterProxy = capiframework.NewClusterProxy(setup.ClusterName, setup.KubeconfigPath, e2e.InitScheme(), capiframework.WithMachineLogCollector(capiframework.DockerLogCollector{})) - Expect(bootstrapClusterProxy).ToNot(BeNil(), "cluster proxy should not be nil") - }, -) - -var _ = SynchronizedAfterSuite( - func() { - }, - func() { - testenv.CleanupTestCluster(ctx, testenv.CleanupTestClusterInput{ - SetupTestClusterResult: *setupClusterResult, - }) - }, -) diff --git a/test/e2e/suites/update-labels/update_labels_test.go b/test/e2e/suites/update-labels/update_labels_test.go deleted file mode 100644 index 42930388..00000000 --- a/test/e2e/suites/update-labels/update_labels_test.go +++ /dev/null @@ -1,193 +0,0 @@ -//go:build e2e -// +build e2e - -/* -Copyright © 2023 - 2024 SUSE LLC - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package update_labels - -import ( - "fmt" - "os" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - - "github.com/drone/envsubst/v2" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - "sigs.k8s.io/controller-runtime/pkg/log" - - provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" - "github.com/rancher/turtles/test/e2e" - turtlesframework "github.com/rancher/turtles/test/framework" - "github.com/rancher/turtles/test/testenv" -) - -var _ = Describe("[v2prov] [Azure] Creating a cluster with v2prov should still work with CAPI 1.5.x and label renaming", Label(e2e.FullTestLabel), func() { - var ( - specName = "updatelabels" - rancherKubeconfig *turtlesframework.RancherGetClusterKubeconfigResult - clusterName string - rancherCluster *provisioningv1.Cluster - ) - - BeforeEach(func() { - komega.SetClient(bootstrapClusterProxy.GetClient()) - komega.SetContext(ctx) - - rancherKubeconfig = new(turtlesframework.RancherGetClusterKubeconfigResult) - clusterName = "az-cluster1-update-labels" - }) - - It("Should create a RKE2 cluster in Azure", func() { - azSubId := e2eConfig.GetVariable(e2e.AzureSubIDVar) - Expect(azSubId).ToNot(BeEmpty(), "Azure Subscription ID is required") - azClientId := e2eConfig.GetVariable(e2e.AzureClientIDVar) - Expect(azSubId).ToNot(BeEmpty(), "Azure Client ID is required") - azClientSecret := e2eConfig.GetVariable(e2e.AzureClientSecretVar) - Expect(azSubId).ToNot(BeEmpty(), "Azure Client Secret is required") - - rke2Version := e2eConfig.GetVariable(e2e.RKE2VersionVar) - Expect(rke2Version).ToNot(BeEmpty(), "RKE2 version is required") - - credsSecretName := "cc-test99" - credsName := "az-ecm" - poolName := "az-test-pool" - - lookupResult := &turtlesframework.RancherLookupUserResult{} - turtlesframework.RancherLookupUser(ctx, turtlesframework.RancherLookupUserInput{ - Username: "admin", - ClusterProxy: bootstrapClusterProxy, - }, lookupResult) - - turtlesframework.CreateSecret(ctx, turtlesframework.CreateSecretInput{ - Creator: bootstrapClusterProxy.GetClient(), - Name: credsSecretName, - Namespace: "cattle-global-data", - Type: corev1.SecretTypeOpaque, - Data: map[string]string{ - "azurecredentialConfig-clientId": azClientId, - "azurecredentialConfig-clientSecret": azClientSecret, - "azurecredentialConfig-environment": "AzurePublicCloud", - "azurecredentialConfig-subscriptionId": azSubId, - "azurecredentialConfig-tenantId": "", - }, - Annotations: map[string]string{ - "field.cattle.io/name": credsName, - "provisioning.cattle.io/driver": "azure", - "field.cattle.io/creatorId": lookupResult.User, - }, - Labels: map[string]string{ - "cattle.io/creator": "norman", - }, - }) - - rkeConfig, err := envsubst.Eval(string(e2e.V2ProvAzureRkeConfig), func(s string) string { - switch s { - case "POOL_NAME": - return poolName - case "USER": - return lookupResult.User - default: - return os.Getenv(s) - } - }) - Expect(err).ToNot(HaveOccurred()) - Expect(turtlesframework.Apply(ctx, bootstrapClusterProxy, []byte(rkeConfig))).To(Succeed(), "Failed apply Digital Ocean RKE config") - - cluster, err := envsubst.Eval(string(e2e.V2ProvAzureCluster), func(s string) string { - switch s { - case "CLUSTER_NAME": - return clusterName - case "USER": - return lookupResult.User - case "CREDENTIAL_SECRET": - return fmt.Sprintf("cattle-global-data:%s", credsSecretName) - case "KUBERNETES_VERSION": - return rke2Version - case "AZ_CONFIG_NAME": - return poolName - default: - return os.Getenv(s) - } - }) - Expect(err).ToNot(HaveOccurred()) - Expect(turtlesframework.Apply(ctx, bootstrapClusterProxy, []byte(cluster))).To(Succeed(), "Failed apply Digital Ocean cluster config") - - By("Waiting for the rancher cluster record to appear") - rancherCluster = &provisioningv1.Cluster{ObjectMeta: metav1.ObjectMeta{ - Namespace: "fleet-default", - Name: clusterName, - }} - Eventually(komega.Get(rancherCluster), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-rancher")...).Should(Succeed()) - - By("Waiting for the rancher cluster to have a deployed agent") - Eventually(komega.Object(rancherCluster), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-v2prov-create")...).Should(HaveField("Status.AgentDeployed", BeTrue())) - - By("Waiting for the rancher cluster to be ready") - Eventually(komega.Object(rancherCluster), e2eConfig.GetIntervals(bootstrapClusterProxy.GetName(), "wait-rancher")...).Should(HaveField("Status.Ready", BeTrue())) - - By("Getting kubeconfig from Rancher for new cluster") - turtlesframework.RancherGetClusterKubeconfig(ctx, turtlesframework.RancherGetClusterKubeconfigInput{ - Getter: bootstrapClusterProxy.GetClient(), - SecretName: fmt.Sprintf("%s-kubeconfig", rancherCluster.Name), - Namespace: rancherCluster.Namespace, - RancherServerURL: hostName, - WriteToTempFile: true, - }, rancherKubeconfig) - - By("Using kubeconfig to query new cluster") - rancherConnectRes := &turtlesframework.RunCommandResult{} - turtlesframework.RunCommand(ctx, turtlesframework.RunCommandInput{ - Command: "kubectl", - Args: []string{ - "--kubeconfig", - rancherKubeconfig.TempFilePath, - "get", - "nodes", - "--insecure-skip-tls-verify", - }, - }, rancherConnectRes) - Expect(rancherConnectRes.Error).NotTo(HaveOccurred(), "Failed getting nodes with Rancher Kubeconfig") - Expect(rancherConnectRes.ExitCode).To(Equal(0), "Getting nodes return non-zero exit code") - }) - - AfterEach(func() { - err := testenv.CollectArtifacts(ctx, testenv.CollectArtifactsInput{ - Path: clusterName + "bootstrap" + specName, - }) - if err != nil { - log.FromContext(ctx).Error(err, "failed to collect artifacts for the bootstrap cluster") - } - - err = testenv.CollectArtifacts(ctx, testenv.CollectArtifactsInput{ - KubeconfigPath: rancherKubeconfig.TempFilePath, - Path: clusterName + specName, - }) - if err != nil { - log.FromContext(ctx).Error(err, "failed to collect artifacts for the child cluster") - } - - By("Deleting cluster from Rancher") - err = bootstrapClusterProxy.GetClient().Delete(ctx, rancherCluster) - Expect(err).NotTo(HaveOccurred(), "Failed to delete rancher cluster") - - By("Waiting for the rancher cluster record to be removed") - Eventually(komega.Get(rancherCluster), e2e.LoadE2EConfig().GetIntervals(bootstrapClusterProxy.GetName(), "wait-azure-delete")...).Should(MatchError(ContainSubstring("not found")), "Rancher cluster should be deleted") - }) -})