From a5d2159b9f1c28a03487674bbc3e2b7bd1a04797 Mon Sep 17 00:00:00 2001 From: Ekaterina Kazakova Date: Thu, 14 Nov 2024 16:56:28 +0400 Subject: [PATCH] [e2e] Support to upgrade managed clusters --- test/e2e/managedcluster/upgrade.go | 68 ++++++++++++++++++++++++++++++ test/e2e/provider_aws_test.go | 18 ++++++++ test/e2e/provider_azure_test.go | 18 ++++++++ test/e2e/provider_vsphere_test.go | 9 ++++ 4 files changed, 113 insertions(+) create mode 100644 test/e2e/managedcluster/upgrade.go diff --git a/test/e2e/managedcluster/upgrade.go b/test/e2e/managedcluster/upgrade.go new file mode 100644 index 00000000..cae8c4ed --- /dev/null +++ b/test/e2e/managedcluster/upgrade.go @@ -0,0 +1,68 @@ +// Copyright 2024 +// +// 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 managedcluster + +import ( + "context" + "time" + + hcv2 "github.com/fluxcd/helm-controller/api/v2" + . "github.com/onsi/gomega" + apimeta "k8s.io/apimachinery/pkg/api/meta" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + crclient "sigs.k8s.io/controller-runtime/pkg/client" + + hmc "github.com/Mirantis/hmc/api/v1alpha1" +) + +func Upgrade(ctx context.Context, cl crclient.Client, clusterNamespace, clusterName, newTemplate string) { + cluster := &hmc.ManagedCluster{} + err := cl.Get(ctx, types.NamespacedName{ + Namespace: clusterNamespace, + Name: clusterName, + }, cluster) + Expect(err).NotTo(HaveOccurred()) + + patch := crclient.MergeFrom(cluster.DeepCopy()) + cluster.Spec.Template = newTemplate + err = cl.Patch(ctx, cluster, patch) + Expect(err).NotTo(HaveOccurred()) + + template := &hmc.ClusterTemplate{} + err = cl.Get(ctx, types.NamespacedName{ + Namespace: clusterNamespace, + Name: newTemplate, + }, template) + Expect(err).NotTo(HaveOccurred()) + + // Verifying the HelmRelease was updated + hr := &hcv2.HelmRelease{} + err = cl.Get(ctx, types.NamespacedName{ + Namespace: clusterNamespace, + Name: clusterName, + }, hr) + Expect(err).NotTo(HaveOccurred()) + + // Verifying the HelmRelease status is up-to-date + // Verifying the ChartRef was updated in the HelmRelease + Eventually(hr.Spec.ChartRef, 5*time.Minute, 10*time.Second).Should(Equal(template.Status.ChartRef)) + + // Verifying the HelmRelease was successfully updated by checking the Ready condition + readyCondition := apimeta.FindStatusCondition(hr.GetConditions(), hmc.HelmReleaseReadyCondition) + Eventually(readyCondition.ObservedGeneration, 5*time.Minute, 10*time.Second).Should(Equal(hr.Generation)) + Eventually(readyCondition.Status, 15*time.Minute, 10*time.Second).Should(Equal(metav1.ConditionTrue)) + Eventually(readyCondition.Reason, 15*time.Minute, 10*time.Second).Should(Equal(hcv2.UpgradeSucceededReason)) +} diff --git a/test/e2e/provider_aws_test.go b/test/e2e/provider_aws_test.go index 5b2ba956..20b991f1 100644 --- a/test/e2e/provider_aws_test.go +++ b/test/e2e/provider_aws_test.go @@ -175,6 +175,24 @@ var _ = Describe("AWS Templates", Label("provider:cloud", "provider:aws"), Order return deploymentValidator.Validate(context.Background(), standaloneClient) }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + if testingConfig.Standalone.Upgrade { + managedcluster.Upgrade(ctx, kc.CrClient, managedcluster.Namespace, clusterName, testingConfig.Standalone.UpgradeTemplate) + Eventually(func() error { + return deploymentValidator.Validate(context.Background(), kc) + }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + + // Validate hosted deployment + Eventually(func() error { + return deploymentValidator.Validate(context.Background(), standaloneClient) + }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + } + if testingConfig.Hosted.Upgrade { + managedcluster.Upgrade(ctx, standaloneClient.CrClient, managedcluster.Namespace, hdName, testingConfig.Hosted.UpgradeTemplate) + Eventually(func() error { + return deploymentValidator.Validate(context.Background(), standaloneClient) + }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + } + // Delete the hosted ManagedCluster and verify it is removed. templateBy(managedcluster.TemplateAWSHostedCP, "deleting the ManagedCluster") err = hostedDeleteFunc() diff --git a/test/e2e/provider_azure_test.go b/test/e2e/provider_azure_test.go index b2d81a75..791e322e 100644 --- a/test/e2e/provider_azure_test.go +++ b/test/e2e/provider_azure_test.go @@ -168,6 +168,24 @@ var _ = Context("Azure Templates", Label("provider:cloud", "provider:azure"), Or return deploymentValidator.Validate(context.Background(), standaloneClient) }).WithTimeout(90 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + if testingConfig.Standalone.Upgrade { + managedcluster.Upgrade(ctx, kc.CrClient, managedcluster.Namespace, sdName, testingConfig.Standalone.UpgradeTemplate) + Eventually(func() error { + return deploymentValidator.Validate(context.Background(), kc) + }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + + // Validate hosted deployment + Eventually(func() error { + return deploymentValidator.Validate(context.Background(), standaloneClient) + }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + } + if testingConfig.Hosted.Upgrade { + managedcluster.Upgrade(ctx, standaloneClient.CrClient, managedcluster.Namespace, hdName, testingConfig.Hosted.UpgradeTemplate) + Eventually(func() error { + return deploymentValidator.Validate(context.Background(), standaloneClient) + }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + } + By("verify the deployment deletes successfully") err = hostedDeleteFunc() Expect(err).NotTo(HaveOccurred()) diff --git a/test/e2e/provider_vsphere_test.go b/test/e2e/provider_vsphere_test.go index 9cf9bc0c..1cb222a7 100644 --- a/test/e2e/provider_vsphere_test.go +++ b/test/e2e/provider_vsphere_test.go @@ -33,6 +33,8 @@ import ( ) var _ = Context("vSphere Templates", Label("provider:onprem", "provider:vsphere"), Ordered, func() { + ctx := context.Background() + var ( kc *kubeclient.KubeClient deleteFunc func() error @@ -112,5 +114,12 @@ var _ = Context("vSphere Templates", Label("provider:onprem", "provider:vsphere" Eventually(func() error { return deploymentValidator.Validate(context.Background(), kc) }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + + if testingConfig.Standalone.Upgrade { + managedcluster.Upgrade(ctx, kc.CrClient, managedcluster.Namespace, clusterName, testingConfig.Standalone.UpgradeTemplate) + Eventually(func() error { + return deploymentValidator.Validate(context.Background(), kc) + }).WithTimeout(30 * time.Minute).WithPolling(10 * time.Second).Should(Succeed()) + } }) })