Skip to content

Commit

Permalink
Reduce e2e process time
Browse files Browse the repository at this point in the history
for work and addon e2e, we do not need to
restart klusterlet for each case

Signed-off-by: Jian Qiu <jqiu@redhat.com>
  • Loading branch information
qiujian16 committed Jul 5, 2023
1 parent eb9b7fa commit 0a2b2eb
Show file tree
Hide file tree
Showing 8 changed files with 144 additions and 242 deletions.
198 changes: 82 additions & 116 deletions test/e2e/addon_lease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"

clusterv1 "open-cluster-management.io/api/cluster/v1"
Expand All @@ -22,21 +21,8 @@ import (

var _ = ginkgo.Describe("Addon Health Check", func() {
ginkgo.Context("Checking addon lease on managed cluster to update addon status", func() {
var (
klusterletName string
addOnName string
)

var addOnName string
ginkgo.BeforeEach(func() {
if deployKlusterlet {
klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6))
clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6))
agentNamespace := fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6))
_, err := t.CreateApprovedKlusterlet(
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
gomega.Expect(err).ToNot(gomega.HaveOccurred())
}

// create an addon on created managed cluster
addOnName = fmt.Sprintf("addon-%s", rand.String(6))
ginkgo.By(fmt.Sprintf("Creating managed cluster addon %q", addOnName))
Expand All @@ -54,11 +40,6 @@ var _ = ginkgo.Describe("Addon Health Check", func() {
})

ginkgo.AfterEach(func() {
ginkgo.By(fmt.Sprintf("Cleaning managed cluster %q", clusterName))
if deployKlusterlet {
ginkgo.By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName))
gomega.Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(gomega.BeNil())
}
ginkgo.By(fmt.Sprintf("Cleaning managed cluster addon installation namespace %q", addOnName))
err := t.SpokeKubeClient.CoreV1().Namespaces().Delete(context.TODO(), addOnName, metav1.DeleteOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
Expand All @@ -77,33 +58,29 @@ var _ = ginkgo.Describe("Addon Health Check", func() {
}, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

err = wait.Poll(1*time.Second, 90*time.Second, func() (bool, error) {
gomega.Eventually(func() error {
found, err := t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Get(context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return false, err
return err
}

if !meta.IsStatusConditionTrue(found.Status.Conditions, "Available") {
return false, nil
return fmt.Errorf("condition should be available")
}

return true, nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return nil
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.Succeed())

// check if the cluster has a label for addon with expected value
err = wait.Poll(1*time.Second, 90*time.Second, func() (bool, error) {
gomega.Eventually(func() bool {
cluster, err := t.ClusterClient.ClusterV1().ManagedClusters().Get(context.TODO(), clusterName, metav1.GetOptions{})
if err != nil {
return false, err
return false
}
if len(cluster.Labels) == 0 {
return false, nil
return false
}
key := fmt.Sprintf("feature.open-cluster-management.io/addon-%s", addOnName)
return cluster.Labels[key] == "available", nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return cluster.Labels[key] == "available"
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.BeTrue())
})

ginkgo.It("Should update addon status to unavailable if addon stops to update its lease", func() {
Expand All @@ -119,32 +96,29 @@ var _ = ginkgo.Describe("Addon Health Check", func() {
}, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() error {
found, err := t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Get(context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return false, err
return err
}
if found.Status.Conditions == nil {
return false, nil
if !meta.IsStatusConditionTrue(found.Status.Conditions, "Available") {
return fmt.Errorf("condition should be available")
}
cond := meta.FindStatusCondition(found.Status.Conditions, "Available")
return cond.Status == metav1.ConditionTrue, nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return nil
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.Succeed())

// check if the cluster has a label for addon with expected value
err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() bool {
cluster, err := t.ClusterClient.ClusterV1().ManagedClusters().Get(context.TODO(), clusterName, metav1.GetOptions{})
if err != nil {
return false, err
return false
}
if len(cluster.Labels) == 0 {
return false, nil
return false
}
key := fmt.Sprintf("feature.open-cluster-management.io/addon-%s", addOnName)
return cluster.Labels[key] == "available", nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return cluster.Labels[key] == "available"
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.BeTrue())

ginkgo.By(fmt.Sprintf("Updating lease %q with a past time", addOnName))
lease, err := t.SpokeKubeClient.CoordinationV1().Leases(addOnName).Get(context.TODO(), addOnName, metav1.GetOptions{})
Expand All @@ -153,32 +127,29 @@ var _ = ginkgo.Describe("Addon Health Check", func() {
_, err = t.SpokeKubeClient.CoordinationV1().Leases(addOnName).Update(context.TODO(), lease, metav1.UpdateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() error {
found, err := t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Get(context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return false, err
return err
}
if found.Status.Conditions == nil {
return false, nil
if !meta.IsStatusConditionFalse(found.Status.Conditions, "Available") {
return fmt.Errorf("condition should be available")
}
cond := meta.FindStatusCondition(found.Status.Conditions, "Available")
return cond.Status == metav1.ConditionFalse, nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return nil
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.Succeed())

// check if the cluster has a label for addon with expected value
err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() bool {
cluster, err := t.ClusterClient.ClusterV1().ManagedClusters().Get(context.TODO(), clusterName, metav1.GetOptions{})
if err != nil {
return false, err
return false
}
if len(cluster.Labels) == 0 {
return false, nil
return false
}
key := fmt.Sprintf("feature.open-cluster-management.io/addon-%s", addOnName)
return cluster.Labels[key] == "unhealthy", nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return cluster.Labels[key] == "unhealthy"
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.BeTrue())
})

ginkgo.It("Should update addon status to unknown if there is no lease for this addon", func() {
Expand All @@ -194,87 +165,76 @@ var _ = ginkgo.Describe("Addon Health Check", func() {
}, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() error {
found, err := t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Get(context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return false, err
return err
}
if found.Status.Conditions == nil {
return false, nil
if !meta.IsStatusConditionTrue(found.Status.Conditions, "Available") {
return fmt.Errorf("condition should be available")
}
cond := meta.FindStatusCondition(found.Status.Conditions, "Available")
return cond.Status == metav1.ConditionTrue, nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return nil
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.Succeed())

// check if the cluster has a label for addon with expected value
err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() bool {
cluster, err := t.ClusterClient.ClusterV1().ManagedClusters().Get(context.TODO(), clusterName, metav1.GetOptions{})
if err != nil {
return false, err
return false
}
if len(cluster.Labels) == 0 {
return false, nil
return false
}
key := fmt.Sprintf("feature.open-cluster-management.io/addon-%s", addOnName)
return cluster.Labels[key] == "available", nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return cluster.Labels[key] == "available"
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.BeTrue())

ginkgo.By(fmt.Sprintf("Deleting lease %q", addOnName))
err = t.SpokeKubeClient.CoordinationV1().Leases(addOnName).Delete(context.TODO(), addOnName, metav1.DeleteOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() error {
found, err := t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Get(context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return false, err
return err
}
if !meta.IsStatusConditionTrue(found.Status.Conditions, "Available") {
return false, nil
return fmt.Errorf("condition should be available")
}

return true, nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return nil
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.Succeed())

// check if the cluster has a label for addon with expected value
err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() bool {
cluster, err := t.ClusterClient.ClusterV1().ManagedClusters().Get(context.TODO(), clusterName, metav1.GetOptions{})
if err != nil {
return false, err
return false
}
if len(cluster.Labels) == 0 {
return false, nil
return false
}
key := fmt.Sprintf("feature.open-cluster-management.io/addon-%s", addOnName)
return cluster.Labels[key] == "unreachable", nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
return cluster.Labels[key] == "unreachable"
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.BeTrue())
})
})

ginkgo.Context("Checking managed cluster status to update addon status", func() {
var (
klusterletName string
addOnName string
)

var klusterletName, clusterName, addOnName string
ginkgo.BeforeEach(func() {
// create a managed cluster
if deployKlusterlet {
klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6))
clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6))
agentNamespace := fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6))
_, err := t.CreateApprovedKlusterlet(
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
gomega.Expect(err).ToNot(gomega.HaveOccurred())
if !deployKlusterlet {
ginkgo.Skip(fmt.Sprintf("skip if disabling deploy klusterlet"))
}

klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6))
clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6))
agentNamespace := fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6))
_, err := t.CreateApprovedKlusterlet(
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
gomega.Expect(err).ToNot(gomega.HaveOccurred())
// create an addon on created managed cluster
addOnName = fmt.Sprintf("addon-%s", rand.String(6))
ginkgo.By(fmt.Sprintf("Creating managed cluster addon %q", addOnName))
err := t.CreateManagedClusterAddOn(clusterName, addOnName, addOnName)
err = t.CreateManagedClusterAddOn(clusterName, addOnName, addOnName)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

// create addon installation namespace
Expand All @@ -291,6 +251,8 @@ var _ = ginkgo.Describe("Addon Health Check", func() {
ginkgo.By(fmt.Sprintf("Cleaning managed cluster addon installation namespace %q", addOnName))
err := t.HubKubeClient.CoreV1().Namespaces().Delete(context.TODO(), addOnName, metav1.DeleteOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
ginkgo.By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName))
gomega.Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(gomega.BeNil())
})

ginkgo.It("Should update addon status to unknown if managed cluster stops to update its lease", func() {
Expand All @@ -306,18 +268,20 @@ var _ = ginkgo.Describe("Addon Health Check", func() {
}, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() error {
found, err := t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Get(context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return false, err
return err
}
if found.Status.Conditions == nil {
return false, nil
return fmt.Errorf("condition should not be nil")
}
cond := meta.FindStatusCondition(found.Status.Conditions, "Available")
return cond.Status == metav1.ConditionTrue, nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
if cond.Status != metav1.ConditionTrue {
return fmt.Errorf("available status should be true")
}
return nil
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.Succeed())

// delete registration agent to stop agent update its status
ginkgo.By(fmt.Sprintf("Stoping klusterlet"))
Expand Down Expand Up @@ -355,18 +319,20 @@ var _ = ginkgo.Describe("Addon Health Check", func() {
_, err = t.ClusterClient.ClusterV1().ManagedClusters().UpdateStatus(context.TODO(), found, metav1.UpdateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

err = wait.Poll(1*time.Second, 60*time.Second, func() (bool, error) {
gomega.Eventually(func() error {
found, err := t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Get(context.TODO(), addOnName, metav1.GetOptions{})
if err != nil {
return false, err
return err
}
if found.Status.Conditions == nil {
return false, nil
return fmt.Errorf("condition should not be nil")
}
cond := meta.FindStatusCondition(found.Status.Conditions, "Available")
return cond.Status == metav1.ConditionUnknown, nil
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
if cond.Status != metav1.ConditionUnknown {
return fmt.Errorf("available status should be unknown")
}
return nil
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(gomega.Succeed())
})
})
})
19 changes: 6 additions & 13 deletions test/e2e/addon_test.go
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
package e2e

import (
"context"
"fmt"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/rand"

operatorapiv1 "open-cluster-management.io/api/operator/v1"
)

var _ = Describe("Manage the managed cluster addons", func() {
var klusterletName, clusterName, agentNamespace, addOnName string

var addOnName string
BeforeEach(func() {
klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6))
clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6))
agentNamespace = fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6))
addOnName = fmt.Sprintf("e2e-addon-%s", rand.String(6))

_, err := t.CreateApprovedKlusterlet(
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func() {
By(fmt.Sprintf("clean klusterlet %v resources after the test case", klusterletName))
Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil())
err := t.AddOnClinet.AddonV1alpha1().ManagedClusterAddOns(clusterName).Delete(context.TODO(), addOnName, metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
})

It("Create one managed cluster addon and make sure it is available", func() {
Expand Down
Loading

0 comments on commit 0a2b2eb

Please sign in to comment.