diff --git a/charts/rancher-turtles/templates/post-upgrade-job.yaml b/charts/rancher-turtles/templates/post-upgrade-job.yaml deleted file mode 100644 index f2001c96..00000000 --- a/charts/rancher-turtles/templates/post-upgrade-job.yaml +++ /dev/null @@ -1,66 +0,0 @@ ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: post-upgrade-job - namespace: '{{ .Values.rancherTurtles.namespace }}' - annotations: - "helm.sh/hook": post-upgrade - "helm.sh/hook-weight": "1" ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: post-upgrade-job-delete-clusters - annotations: - "helm.sh/hook": post-upgrade - "helm.sh/hook-weight": "1" -rules: -- apiGroups: - - provisioning.cattle.io - resources: - - clusters - verbs: - - list - - delete ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: post-upgrade-job-delete-clusters - annotations: - "helm.sh/hook": post-upgrade - "helm.sh/hook-weight": "1" -subjects: - - kind: ServiceAccount - name: post-upgrade-job - namespace: '{{ .Values.rancherTurtles.namespace }}' -roleRef: - kind: ClusterRole - name: post-upgrade-job-delete-clusters - apiGroup: rbac.authorization.k8s.io ---- -apiVersion: batch/v1 -kind: Job -metadata: - name: post-upgrade-delete-clusters - namespace: '{{ .Values.rancherTurtles.namespace }}' - annotations: - "helm.sh/hook": post-upgrade - "helm.sh/hook-weight": "2" -spec: - ttlSecondsAfterFinished: 300 - template: - spec: - serviceAccountName: post-upgrade-job - containers: - - name: post-upgrade-delete-clusters - image: {{ index .Values "rancherTurtles" "kubectlImage" }} - args: - - delete - - clusters.provisioning.cattle.io - - --selector=cluster-api.cattle.io/owned - - -A - - --ignore-not-found=true - - --wait - restartPolicy: OnFailure diff --git a/test/e2e/specs/migrate_gitops_provv1_mgmtv3.go b/test/e2e/specs/migrate_gitops_provv1_mgmtv3.go deleted file mode 100644 index 4f329212..00000000 --- a/test/e2e/specs/migrate_gitops_provv1_mgmtv3.go +++ /dev/null @@ -1,405 +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 specs - -import ( - "context" - "fmt" - "os" - "path/filepath" - "strconv" - "time" - - . "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" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "sigs.k8s.io/cluster-api/test/framework" - "sigs.k8s.io/cluster-api/test/framework/clusterctl" - "sigs.k8s.io/cluster-api/util/conditions" - "sigs.k8s.io/controller-runtime/pkg/client" - "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - "sigs.k8s.io/controller-runtime/pkg/log" - - managementv3 "github.com/rancher/turtles/api/rancher/management/v3" - 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" - turtlesannotations "github.com/rancher/turtles/util/annotations" - turtlesnaming "github.com/rancher/turtles/util/naming" -) - -type MigrateToV3UsingGitOpsSpecInput struct { - E2EConfig *clusterctl.E2EConfig - BootstrapClusterProxy framework.ClusterProxy - ArtifactFolder string `env:"ARTIFACTS_FOLDER"` - RancherServerURL string - - ClusterctlBinaryPath string `env:"CLUSTERCTL_BINARY_PATH"` - ClusterTemplate []byte - AdditionalTemplates [][]byte - ClusterName string - AdditionalTemplateVariables map[string]string - - CAPIClusterCreateWaitName string - DeleteClusterWaitName string - - // ControlPlaneMachineCount defines the number of control plane machines to be added to the workload cluster. - // If not specified, 1 will be used. - ControlPlaneMachineCount *int - - // WorkerMachineCount defines number of worker machines to be added to the workload cluster. - // If not specified, 1 will be used. - WorkerMachineCount *int - - GitAddr string - - SkipCleanup bool `env:"SKIP_RESOURCE_CLEANUP"` - SkipDeletionTest bool - - LabelNamespace bool - - // TestClusterReimport defines whether to test un-importing and re-importing the cluster after initial test. - TestClusterReimport bool - - // management.cattle.io specifc - CapiClusterOwnerLabel string - CapiClusterOwnerNamespaceLabel string - OwnedLabelName string -} - -// MigrateToV3UsingGitOpsSpec implements a spec that will create a cluster via Fleet and test that it -// automatically imports into Rancher Manager. -func MigrateToV3UsingGitOpsSpec(ctx context.Context, inputGetter func() MigrateToV3UsingGitOpsSpecInput) { - var ( - specName = "migrategitops" - input MigrateToV3UsingGitOpsSpecInput - namespace *corev1.Namespace - repoName string - cancelWatches context.CancelFunc - capiCluster *types.NamespacedName - rancherKubeconfig *turtlesframework.RancherGetClusterKubeconfigResult - originalKubeconfig *turtlesframework.RancherGetClusterKubeconfigResult - rancherConnectRes *turtlesframework.RunCommandResult - rancherCluster *managementv3.Cluster - rancherLegacyCluster *provisioningv1.Cluster - capiClusterCreateWait []interface{} - deleteClusterWait []interface{} - ) - - validateLegacyRancherCluster := func() { - By("Waiting for the rancher cluster record to appear") - rancherLegacyCluster = &provisioningv1.Cluster{ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace.Name, - Name: turtlesnaming.Name(capiCluster.Name).ToRancherName(), - }} - Eventually(komega.Get(rancherLegacyCluster), input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(Succeed()) - - By("Waiting for the rancher cluster to have a deployed agent") - Eventually(komega.Object(rancherLegacyCluster), input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(HaveField("Status.AgentDeployed", BeTrue())) - - By("Waiting for the rancher cluster to be ready") - Eventually(komega.Object(rancherLegacyCluster), input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(HaveField("Status.Ready", BeTrue())) - - By("Waiting for the CAPI cluster to be connectable using Rancher kubeconfig") - turtlesframework.RancherGetClusterKubeconfig(ctx, turtlesframework.RancherGetClusterKubeconfigInput{ - Getter: input.BootstrapClusterProxy.GetClient(), - SecretName: fmt.Sprintf("%s-capi-kubeconfig", capiCluster.Name), - Namespace: capiCluster.Namespace, - RancherServerURL: input.RancherServerURL, - WriteToTempFile: true, - }, rancherKubeconfig) - - 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") - } - - validateRancherCluster := func() { - By("Waiting for the rancher cluster record to appear") - rancherClusters := &managementv3.ClusterList{} - selectors := []client.ListOption{ - client.MatchingLabels{ - input.CapiClusterOwnerLabel: capiCluster.Name, - input.CapiClusterOwnerNamespaceLabel: capiCluster.Namespace, - input.OwnedLabelName: "", - }, - } - Eventually(func() bool { - Eventually(komega.List(rancherClusters, selectors...)).Should(Succeed()) - return len(rancherClusters.Items) == 1 - }, input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(BeTrue()) - rancherCluster = &rancherClusters.Items[0] - Eventually(komega.Get(rancherCluster), input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(Succeed()) - - By("Waiting for the rancher cluster to have a deployed agent") - Eventually(func() bool { - Eventually(komega.Get(rancherCluster), input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(Succeed()) - return conditions.IsTrue(rancherCluster, managementv3.ClusterConditionAgentDeployed) - }, input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(BeTrue()) - - By("Waiting for the rancher cluster to be ready") - Eventually(func() bool { - Eventually(komega.Get(rancherCluster), input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(Succeed()) - return conditions.IsTrue(rancherCluster, managementv3.ClusterConditionReady) - }, input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(BeTrue()) - - By("Rancher cluster should have the 'NoCreatorRBAC' annotation") - Eventually(func() bool { - Eventually(komega.Get(rancherCluster), input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(Succeed()) - _, found := rancherCluster.Annotations[turtlesannotations.NoCreatorRBACAnnotation] - return found - }, input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(BeTrue()) - - By("Waiting for the CAPI cluster to be connectable using Rancher kubeconfig") - turtlesframework.RancherGetClusterKubeconfig(ctx, turtlesframework.RancherGetClusterKubeconfigInput{ - Getter: input.BootstrapClusterProxy.GetClient(), - SecretName: fmt.Sprintf("%s-kubeconfig", rancherCluster.Name), - Namespace: rancherCluster.Spec.FleetWorkspaceName, - RancherServerURL: input.RancherServerURL, - WriteToTempFile: true, - }, rancherKubeconfig) - - 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") - } - - BeforeEach(func() { - Expect(ctx).NotTo(BeNil(), "ctx is required for %s spec", specName) - input = inputGetter() - Expect(turtlesframework.Parse(&input)).To(Succeed(), "Failed to parse environment variables") - - Expect(input.E2EConfig).ToNot(BeNil(), "Invalid argument. input.E2EConfig can't be nil when calling %s spec", specName) - Expect(input.BootstrapClusterProxy).ToNot(BeNil(), "Invalid argument. input.BootstrapClusterProxy can't be nil when calling %s spec", specName) - Expect(os.MkdirAll(input.ArtifactFolder, 0750)).To(Succeed(), "Invalid argument. input.ArtifactFolder can't be created for %s spec", specName) - - Expect(input.E2EConfig.Variables).To(HaveKey(e2e.KubernetesManagementVersionVar)) - namespace, cancelWatches = e2e.SetupSpecNamespace(ctx, specName, input.BootstrapClusterProxy, input.ArtifactFolder) - repoName = e2e.CreateRepoName(specName) - - capiClusterCreateWait = input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), input.CAPIClusterCreateWaitName) - Expect(capiClusterCreateWait).ToNot(BeNil(), "Failed to get wait intervals %s", input.CAPIClusterCreateWaitName) - - deleteClusterWait = input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), input.DeleteClusterWaitName) - Expect(capiClusterCreateWait).ToNot(BeNil(), "Failed to get wait intervals %s", input.CAPIClusterCreateWaitName) - - capiCluster = &types.NamespacedName{ - Namespace: namespace.Name, - Name: input.ClusterName, - } - - rancherKubeconfig = new(turtlesframework.RancherGetClusterKubeconfigResult) - originalKubeconfig = new(turtlesframework.RancherGetClusterKubeconfigResult) - rancherConnectRes = new(turtlesframework.RunCommandResult) - - komega.SetClient(input.BootstrapClusterProxy.GetClient()) - komega.SetContext(ctx) - }) - - It("Should import a cluster using gitops", func() { - controlPlaneMachineCount := 1 - if input.ControlPlaneMachineCount != nil { - controlPlaneMachineCount = *input.ControlPlaneMachineCount - } - - workerMachineCount := 1 - if input.WorkerMachineCount != nil { - workerMachineCount = *input.WorkerMachineCount - } - - if input.LabelNamespace { - turtlesframework.AddLabelsToNamespace(ctx, turtlesframework.AddLabelsToNamespaceInput{ - ClusterProxy: input.BootstrapClusterProxy, - Name: namespace.Name, - Labels: map[string]string{ - "cluster-api.cattle.io/rancher-auto-import": "true", - }, - }) - } - - By("Create Git repository") - - repoCloneAddr := turtlesframework.GiteaCreateRepo(ctx, turtlesframework.GiteaCreateRepoInput{ - ServerAddr: input.GitAddr, - RepoName: repoName, - }) - repoDir := turtlesframework.GitCloneRepo(ctx, turtlesframework.GitCloneRepoInput{ - Address: repoCloneAddr, - }) - - By("Create fleet repository structure") - - clustersDir := filepath.Join(repoDir, "clusters") - os.MkdirAll(clustersDir, os.ModePerm) - - additionalVars := map[string]string{ - "CLUSTER_NAME": input.ClusterName, - "WORKER_MACHINE_COUNT": strconv.Itoa(workerMachineCount), - "CONTROL_PLANE_MACHINE_COUNT": strconv.Itoa(controlPlaneMachineCount), - } - for k, v := range input.AdditionalTemplateVariables { - additionalVars[k] = v - } - - clusterPath := filepath.Join(clustersDir, fmt.Sprintf("%s.yaml", input.ClusterName)) - Expect(turtlesframework.ApplyFromTemplate(ctx, turtlesframework.ApplyFromTemplateInput{ - Template: input.ClusterTemplate, - OutputFilePath: clusterPath, - AddtionalEnvironmentVariables: additionalVars, - })).To(Succeed()) - - for n, template := range input.AdditionalTemplates { - templatePath := filepath.Join(clustersDir, fmt.Sprintf("%s-template-%d.yaml", input.ClusterName, n)) - Expect(turtlesframework.ApplyFromTemplate(ctx, turtlesframework.ApplyFromTemplateInput{ - Template: template, - OutputFilePath: templatePath, - AddtionalEnvironmentVariables: additionalVars, - })).To(Succeed()) - } - - fleetPath := filepath.Join(clustersDir, "fleet.yaml") - turtlesframework.FleetCreateFleetFile(ctx, turtlesframework.FleetCreateFleetFileInput{ - Namespace: namespace.Name, - FilePath: fleetPath, - }) - - By("Committing changes to fleet repo and pushing") - - turtlesframework.GitCommitAndPush(ctx, turtlesframework.GitCommitAndPushInput{ - CloneLocation: repoDir, - CommitMessage: "ci: add clusters bundle", - }) - - By("Applying GitRepo") - - turtlesframework.FleetCreateGitRepo(ctx, turtlesframework.FleetCreateGitRepoInput{ - Name: repoName, - Repo: repoCloneAddr, - FleetGeneration: 1, - Paths: []string{"clusters"}, - ClusterProxy: input.BootstrapClusterProxy, - }) - - By("Waiting for the CAPI cluster to appear") - capiCluster := &clusterv1.Cluster{ObjectMeta: metav1.ObjectMeta{ - Namespace: namespace.Name, - Name: input.ClusterName, - }} - Eventually( - komega.Get(capiCluster), - input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...). - Should(Succeed(), "Failed to apply CAPI cluster definition to cluster via Fleet") - - By("Waiting for cluster control plane to be Ready") - Eventually(komega.Object(capiCluster), capiClusterCreateWait...).Should(HaveField("Status.ControlPlaneReady", BeTrue())) - - By("Waiting for the CAPI cluster to be connectable") - Eventually(func() error { - remoteClient := input.BootstrapClusterProxy.GetWorkloadCluster(ctx, capiCluster.Namespace, capiCluster.Name).GetClient() - namespaces := &corev1.NamespaceList{} - - return remoteClient.List(ctx, namespaces) - }, capiClusterCreateWait...).Should(Succeed(), "Failed to connect to workload cluster using CAPI kubeconfig") - - By("Storing the original CAPI cluster kubeconfig") - turtlesframework.RancherGetOriginalKubeconfig(ctx, turtlesframework.RancherGetClusterKubeconfigInput{ - Getter: input.BootstrapClusterProxy.GetClient(), - SecretName: fmt.Sprintf("%s-kubeconfig", capiCluster.Name), - ClusterName: capiCluster.Name, - Namespace: capiCluster.Namespace, - WriteToTempFile: true, - }, originalKubeconfig) - - By("Running checks on Rancher cluster") - validateLegacyRancherCluster() - - upgradeInput := testenv.UpgradeRancherTurtlesInput{ - BootstrapClusterProxy: input.BootstrapClusterProxy, - SkipCleanup: true, - } - - testenv.UpgradeRancherTurtles(ctx, upgradeInput) - - By("Waiting for the Rancher cluster record to be removed") - Eventually(komega.Get(rancherLegacyCluster), deleteClusterWait...).Should(MatchError(ContainSubstring("not found")), "Rancher cluster should be unimported (deleted)") - - By("CAPI cluster should NOT have the 'imported' annotation") - Consistently(func() bool { - Eventually(komega.Get(capiCluster), input.E2EConfig.GetIntervals(input.BootstrapClusterProxy.GetName(), "wait-rancher")...).Should(Succeed()) - annotations := capiCluster.GetAnnotations() - _, found := annotations["imported"] - return !found - }, 5*time.Second).Should(BeTrue(), "'imported' annotation is NOT expected on CAPI cluster") - - By("Rancher should be available using new cluster import") - validateRancherCluster() - }) - - AfterEach(func() { - err := testenv.CollectArtifacts(ctx, testenv.CollectArtifactsInput{ - Path: input.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: originalKubeconfig.TempFilePath, - Path: input.ClusterName + specName, - }) - if err != nil { - log.FromContext(ctx).Error(err, "failed to collect artifacts for the child cluster") - } - - By("Deleting GitRepo from Rancher") - turtlesframework.FleetDeleteGitRepo(ctx, turtlesframework.FleetDeleteGitRepoInput{ - Name: repoName, - ClusterProxy: input.BootstrapClusterProxy, - }) - - By("Waiting for the rancher cluster record to be removed") - Eventually(komega.Get(rancherCluster), deleteClusterWait...).Should(MatchError(ContainSubstring("not found")), "Rancher cluster should be deleted") - - e2e.DumpSpecResourcesAndCleanup(ctx, specName, input.BootstrapClusterProxy, namespace, cancelWatches, capiCluster, input.E2EConfig.GetIntervals, input.SkipCleanup) - }) -} diff --git a/test/e2e/suites/migrate-gitops/migrate_gitops_provv1_mgmtv3_test.go b/test/e2e/suites/migrate-gitops/migrate_gitops_provv1_mgmtv3_test.go deleted file mode 100644 index 68b01996..00000000 --- a/test/e2e/suites/migrate-gitops/migrate_gitops_provv1_mgmtv3_test.go +++ /dev/null @@ -1,61 +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 migrate_gitops - -import ( - _ "embed" - - . "github.com/onsi/ginkgo/v2" - "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - - "k8s.io/utils/ptr" - - "github.com/rancher/turtles/test/e2e" - "github.com/rancher/turtles/test/e2e/specs" -) - -var _ = Describe("[Docker] [Kubeadm] - [management.cattle.io/v3] Migrate v1 to management v3 cluster functionality should work", Label(e2e.ShortTestLabel), func() { - BeforeEach(func() { - komega.SetClient(bootstrapClusterProxy.GetClient()) - komega.SetContext(ctx) - }) - - specs.MigrateToV3UsingGitOpsSpec(ctx, func() specs.MigrateToV3UsingGitOpsSpecInput { - return specs.MigrateToV3UsingGitOpsSpecInput{ - E2EConfig: e2e.LoadE2EConfig(), - BootstrapClusterProxy: bootstrapClusterProxy, - ClusterTemplate: e2e.CAPIDockerKubeadm, - AdditionalTemplates: [][]byte{e2e.CAPIKindnet}, - ClusterName: "clusterv3-migrated", - ControlPlaneMachineCount: ptr.To(1), - WorkerMachineCount: ptr.To(1), - GitAddr: gitAddress, - SkipDeletionTest: false, - LabelNamespace: true, - TestClusterReimport: true, - RancherServerURL: hostName, - CAPIClusterCreateWaitName: "wait-rancher", - DeleteClusterWaitName: "wait-controllers", - CapiClusterOwnerLabel: e2e.CapiClusterOwnerLabel, - CapiClusterOwnerNamespaceLabel: e2e.CapiClusterOwnerNamespaceLabel, - OwnedLabelName: e2e.OwnedLabelName, - } - }) -}) diff --git a/test/e2e/suites/migrate-gitops/suite_test.go b/test/e2e/suites/migrate-gitops/suite_test.go deleted file mode 100644 index d309aa0e..00000000 --- a/test/e2e/suites/migrate-gitops/suite_test.go +++ /dev/null @@ -1,148 +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 migrate_gitops - -import ( - "context" - "encoding/json" - "testing" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/rancher/turtles/test/e2e" - "github.com/rancher/turtles/test/testenv" - - capiframework "sigs.k8s.io/cluster-api/test/framework" - ctrl "sigs.k8s.io/controller-runtime" - "sigs.k8s.io/controller-runtime/pkg/log/zap" -) - -// Test suite global vars. -var ( - // hostName is the host name for the Rancher Manager server. - hostName string - - ctx = context.Background() - - setupClusterResult *testenv.SetupTestClusterResult - bootstrapClusterProxy capiframework.ClusterProxy - gitAddress string -) - -func TestE2E(t *testing.T) { - RegisterFailHandler(Fail) - - ctrl.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) - - RunSpecs(t, "rancher-turtles-e2e-migrate-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, - RancherHost: hostName, - RancherPatches: [][]byte{e2e.RancherSettingPatch}, - }) - - testenv.DeployChartMuseum(ctx, testenv.DeployChartMuseumInput{ - BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, - }) - - testenv.DeployRancherTurtles(ctx, testenv.DeployRancherTurtlesInput{ - BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, - CAPIProvidersYAML: e2e.CapiProviders, - TurtlesChartPath: "https://rancher.github.io/turtles", - Version: "v0.15.0", - AdditionalValues: map[string]string{ - "rancherTurtles.features.addon-provider-fleet.enabled": "true", - "rancherTurtles.features.managementv3-cluster.enabled": "false", - "rancherTurtles.features.managementv3-cluster-migration.enabled": "false", - }, - WaitForDeployments: append(testenv.DefaultDeployments, testenv.NamespaceName{ - Name: "caapf-controller-manager", - Namespace: e2e.RancherTurtlesNamespace, - }), - ConfigurationPatches: [][]byte{e2e.AddonProviderFleetHostNetworkPatch}, - }) - - giteaResult := testenv.DeployGitea(ctx, testenv.DeployGiteaInput{ - BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, - ValuesFile: e2e.GiteaValues, - CustomIngressConfig: e2e.GiteaIngress, - }) - - data, err := json.Marshal(e2e.Setup{ - ClusterName: setupClusterResult.ClusterName, - KubeconfigPath: setupClusterResult.KubeconfigPath, - GitAddress: giteaResult.GitAddress, - RancherHostname: rancherHookResult.Hostname, - }) - Expect(err).ToNot(HaveOccurred()) - return data - }, - func(sharedData []byte) { - setup := e2e.Setup{} - Expect(json.Unmarshal(sharedData, &setup)).To(Succeed()) - - gitAddress = setup.GitAddress - hostName = setup.RancherHostname - - 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.UninstallGitea(ctx, testenv.UninstallGiteaInput{ - BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, - }) - - testenv.UninstallRancherTurtles(ctx, testenv.UninstallRancherTurtlesInput{ - BootstrapClusterProxy: setupClusterResult.BootstrapClusterProxy, - }) - - testenv.CleanupTestCluster(ctx, testenv.CleanupTestClusterInput{ - SetupTestClusterResult: *setupClusterResult, - }) - }, -) - -func shortTestOnly() bool { - return GinkgoLabelFilter() == e2e.ShortTestLabel -} - -func localTestOnly() bool { - return GinkgoLabelFilter() == e2e.LocalTestLabel -}