Skip to content

Commit

Permalink
[e2e] Support to upgrade managed clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
eromanova committed Nov 14, 2024
1 parent 64dc32a commit a5d2159
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/e2e/managedcluster/upgrade.go
Original file line number Diff line number Diff line change
@@ -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))
}
18 changes: 18 additions & 0 deletions test/e2e/provider_aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/provider_azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/provider_vsphere_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
}
})
})

0 comments on commit a5d2159

Please sign in to comment.