mirror of
https://github.com/open-cluster-management-io/ocm.git
synced 2026-08-23 22:26:49 +00:00
Separated hosted klusterlet e2e to separated action (#206)
Signed-off-by: Jian Qiu <jqiu@redhat.com>
This commit is contained in:
@@ -46,3 +46,32 @@ jobs:
|
||||
IMAGE_TAG=e2e make test-e2e
|
||||
env:
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
e2e-hosted:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ env.GO_VERSION }}
|
||||
- name: Setup kind
|
||||
uses: engineerd/setup-kind@v0.5.0
|
||||
with:
|
||||
version: v0.17.0
|
||||
- name: install imagebuilder
|
||||
run: go install github.com/openshift/imagebuilder/cmd/imagebuilder@v1.2.3
|
||||
- name: Build images
|
||||
run: IMAGE_TAG=e2e make images
|
||||
- name: Load images
|
||||
run: |
|
||||
kind load docker-image --name=kind quay.io/open-cluster-management/registration-operator:e2e
|
||||
kind load docker-image --name=kind quay.io/open-cluster-management/registration:e2e
|
||||
kind load docker-image --name=kind quay.io/open-cluster-management/work:e2e
|
||||
kind load docker-image --name=kind quay.io/open-cluster-management/placement:e2e
|
||||
kind load docker-image --name=kind quay.io/open-cluster-management/addon-manager:e2e
|
||||
- name: Test E2E
|
||||
run: |
|
||||
IMAGE_TAG=e2e KLUSTERLET_DEPLOY_MODE=Hosted make test-e2e
|
||||
env:
|
||||
KUBECONFIG: /home/runner/.kube/config
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ include $(addprefix ./vendor/github.com/openshift/build-machinery-go/make/, \
|
||||
KUBECTL?=kubectl
|
||||
KUBECONFIG?=./.kubeconfig
|
||||
HUB_KUBECONFIG?=./.hub-kubeconfig
|
||||
KLUSTERLET_DEPLOY_MODE?=Default
|
||||
|
||||
SED_CMD:=sed
|
||||
ifeq ($(GOHOSTOS),darwin)
|
||||
@@ -32,7 +33,7 @@ test-e2e: deploy-hub deploy-spoke-operator run-e2e
|
||||
|
||||
run-e2e: cluster-ip bootstrap-secret
|
||||
go test -c ./test/e2e
|
||||
./e2e.test -test.v -ginkgo.v -deploy-klusterlet=true -nil-executor-validating=true -registration-image=$(REGISTRATION_IMAGE) -work-image=$(WORK_IMAGE)
|
||||
./e2e.test -test.v -ginkgo.v -deploy-klusterlet=true -nil-executor-validating=true -registration-image=$(REGISTRATION_IMAGE) -work-image=$(WORK_IMAGE) -klusterlet-deploy-mode=$(KLUSTERLET_DEPLOY_MODE)
|
||||
|
||||
clean-hub: clean-hub-cr clean-hub-operator
|
||||
|
||||
|
||||
@@ -32,7 +32,8 @@ var _ = ginkgo.Describe("Addon Health Check", 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))
|
||||
_, err := t.CreateApprovedKlusterlet(klusterletName, clusterName, agentNamespace, operatorapiv1.InstallModeDefault)
|
||||
_, err := t.CreateApprovedKlusterlet(
|
||||
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||
}
|
||||
|
||||
@@ -265,7 +266,8 @@ var _ = ginkgo.Describe("Addon Health Check", 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))
|
||||
_, err := t.CreateApprovedKlusterlet(klusterletName, clusterName, agentNamespace, operatorapiv1.InstallModeDefault)
|
||||
_, err := t.CreateApprovedKlusterlet(
|
||||
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ var _ = Describe("Manage the managed cluster addons", func() {
|
||||
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.InstallModeDefault)
|
||||
_, err := t.CreateApprovedKlusterlet(
|
||||
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
AfterEach(func() {
|
||||
|
||||
@@ -83,7 +83,8 @@ var _ = ginkgo.Describe("Enable addon management feature gate", ginkgo.Label("ad
|
||||
// the addon manager deployment should be running
|
||||
gomega.Eventually(t.CheckHubReady, t.EventuallyTimeout, t.EventuallyInterval).Should(gomega.Succeed())
|
||||
|
||||
_, err := t.CreateApprovedKlusterlet(klusterletName, clusterName, agentNamespace, operatorapiv1.InstallModeDefault)
|
||||
_, err := t.CreateApprovedKlusterlet(
|
||||
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||
|
||||
ginkgo.By(fmt.Sprintf("create addon template resources for cluster %v", clusterName))
|
||||
|
||||
+1
-1
@@ -303,7 +303,7 @@ func (t *Tester) CreateKlusterlet(name, clusterName, klusterletNamespace string,
|
||||
}
|
||||
|
||||
func (t *Tester) CreateApprovedKlusterlet(name, clusterName, klusterletNamespace string, mode operatorapiv1.InstallMode) (*operatorapiv1.Klusterlet, error) {
|
||||
klusterlet, err := t.CreateKlusterlet(name, clusterName, klusterletNamespace, operatorapiv1.InstallModeDefault)
|
||||
klusterlet, err := t.CreateKlusterlet(name, clusterName, klusterletNamespace, mode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package e2e
|
||||
|
||||
import (
|
||||
"flag"
|
||||
operatorapiv1 "open-cluster-management.io/api/operator/v1"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -20,6 +21,7 @@ var (
|
||||
eventuallyTimeout time.Duration
|
||||
registrationImage string
|
||||
workImage string
|
||||
klusterletDeployMode string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -31,6 +33,7 @@ func init() {
|
||||
flag.DurationVar(&eventuallyTimeout, "eventually-timeout", 60*time.Second, "The timeout of Gomega's Eventually (default 60 seconds)")
|
||||
flag.StringVar(®istrationImage, "registration-image", "", "The image of the registration")
|
||||
flag.StringVar(&workImage, "work-image", "", "The image of the work")
|
||||
flag.StringVar(&klusterletDeployMode, "klusterlet-deploy-mode", string(operatorapiv1.InstallModeDefault), "The image of the work")
|
||||
}
|
||||
|
||||
func TestE2E(tt *testing.T) {
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
operatorapiv1 "open-cluster-management.io/api/operator/v1"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Delete hosted klusterlet CR", func() {
|
||||
var klusterletName string
|
||||
var clusterName string
|
||||
var klusterletNamespace string
|
||||
|
||||
BeforeEach(func() {
|
||||
if klusterletDeployMode != string(operatorapiv1.InstallModeHosted) {
|
||||
Skip(fmt.Sprintf("Klusterlet deploy is %s", klusterletDeployMode))
|
||||
}
|
||||
klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6))
|
||||
clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6))
|
||||
klusterletNamespace = fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6))
|
||||
})
|
||||
|
||||
It("Delete klusterlet CR in Hosted mode without external managed kubeconfig", func() {
|
||||
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v in Hosted mode", klusterletName, clusterName))
|
||||
_, err := t.CreatePureHostedKlusterlet(klusterletName, clusterName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s status", klusterletName))
|
||||
Eventually(func() error {
|
||||
err := t.checkKlusterletStatus(klusterletName, "ReadyToApply", "KlusterletPrepareFailed", metav1.ConditionFalse)
|
||||
return err
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("delete the klusterlet %s", klusterletName))
|
||||
err = t.OperatorClient.OperatorV1().Klusterlets().Delete(context.TODO(),
|
||||
klusterletName, metav1.DeleteOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s was deleted", klusterletName))
|
||||
Eventually(func() error {
|
||||
_, err := t.OperatorClient.OperatorV1().Klusterlets().Get(context.TODO(),
|
||||
klusterletName, metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("klusterlet still exists")
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("check the agent namespace %s on the management cluster was deleted", klusterletName))
|
||||
Eventually(func() error {
|
||||
_, err := t.HubKubeClient.CoreV1().Namespaces().Get(context.TODO(),
|
||||
klusterletName, metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("klusterlet namespace still exists")
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
})
|
||||
|
||||
It("Delete klusterlet CR in Hosted mode when the managed cluster was destroyed", func() {
|
||||
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
|
||||
klusterlet, err := t.CreateKlusterlet(klusterletName, clusterName, klusterletNamespace, operatorapiv1.InstallModeHosted)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("waiting for the managed cluster %v to be created", clusterName))
|
||||
Eventually(func() error {
|
||||
_, err := t.GetCreatedManagedCluster(clusterName)
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s status", klusterletName))
|
||||
Eventually(func() error {
|
||||
err := t.checkKlusterletStatus(klusterletName, "HubConnectionDegraded",
|
||||
"BootstrapSecretFunctional,HubKubeConfigSecretMissing", metav1.ConditionTrue)
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("approve the created managed cluster %v", clusterName))
|
||||
Eventually(func() error {
|
||||
return t.ApproveCSR(clusterName)
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("accept the created managed cluster %v", clusterName))
|
||||
Eventually(func() error {
|
||||
return t.AcceptsClient(clusterName)
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("waiting for the managed cluster %v to be ready", clusterName))
|
||||
Eventually(func() error {
|
||||
return t.CheckManagedClusterStatus(clusterName)
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s status", klusterletName))
|
||||
Eventually(func() error {
|
||||
err := t.checkKlusterletStatus(klusterletName, "HubConnectionDegraded",
|
||||
"HubConnectionFunctional", metav1.ConditionFalse)
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
// change the kubeconfig host of external managed kubeconfig secret to a wrong value
|
||||
// to simulate the managed cluster was destroyed
|
||||
By("Delete external managed kubeconfig", func() {
|
||||
err = t.DeleteExternalKubeconfigSecret(klusterlet)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
By("Delete managed cluster", func() {
|
||||
// clean the managed clusters
|
||||
err = t.ClusterClient.ClusterV1().ManagedClusters().Delete(context.TODO(),
|
||||
clusterName, metav1.DeleteOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
By("Delete klusterlet", func() {
|
||||
// clean the klusterlets
|
||||
err = t.OperatorClient.OperatorV1().Klusterlets().Delete(context.TODO(),
|
||||
klusterletName, metav1.DeleteOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
By("Create a fake external managed kubeconfig", func() {
|
||||
err = t.CreateFakeExternalKubeconfigSecret(klusterlet)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
// in the future, if the eviction can be configured, we can set a short timeout period and
|
||||
// remove the wait and update parts
|
||||
evictionTimestampAnno := "operator.open-cluster-management.io/managed-resources-eviction-timestamp"
|
||||
By("Wait for the eviction timestamp annotation", func() {
|
||||
Eventually(func() error {
|
||||
k, err := t.OperatorClient.OperatorV1().Klusterlets().Get(context.TODO(),
|
||||
klusterletName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, ok := k.Annotations[evictionTimestampAnno]
|
||||
if !ok {
|
||||
return fmt.Errorf("expected annotation %s does not exist", evictionTimestampAnno)
|
||||
}
|
||||
return nil
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
})
|
||||
|
||||
time.Sleep(3 * time.Second) // after the eviction timestamp exists, wait 3 seconds for cache syncing
|
||||
By("Update the eviction timestamp annotation", func() {
|
||||
Eventually(func() error {
|
||||
k, err := t.OperatorClient.OperatorV1().Klusterlets().Get(context.TODO(),
|
||||
klusterletName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ta := time.Now().Add(-6 * time.Minute).Format(time.RFC3339)
|
||||
By(fmt.Sprintf("add time %v anno for klusterlet %s", ta, klusterletName))
|
||||
k.Annotations[evictionTimestampAnno] = ta
|
||||
_, err = t.OperatorClient.OperatorV1().Klusterlets().Update(context.TODO(),
|
||||
k, metav1.UpdateOptions{})
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
})
|
||||
|
||||
By("Check manged cluster and klusterlet can be deleted", func() {
|
||||
Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
||||
+2
-201
@@ -1,13 +1,9 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
|
||||
@@ -73,7 +69,7 @@ var _ = Describe("Create klusterlet CR", func() {
|
||||
|
||||
It("Create klusterlet CR with managed cluster name", func() {
|
||||
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
|
||||
_, err := t.CreateKlusterlet(klusterletName, clusterName, klusterletNamespace, operatorapiv1.InstallModeDefault)
|
||||
_, err := t.CreateKlusterlet(klusterletName, clusterName, klusterletNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("waiting for the managed cluster %v to be created", clusterName))
|
||||
@@ -115,7 +111,7 @@ var _ = Describe("Create klusterlet CR", func() {
|
||||
klusterletNamespace = ""
|
||||
var err error
|
||||
By(fmt.Sprintf("create klusterlet %v without managed cluster name", klusterletName))
|
||||
_, err = t.CreateKlusterlet(klusterletName, clusterName, klusterletNamespace, operatorapiv1.InstallModeDefault)
|
||||
_, err = t.CreateKlusterlet(klusterletName, clusterName, klusterletNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By("waiting for the managed cluster to be created")
|
||||
@@ -151,199 +147,4 @@ var _ = Describe("Create klusterlet CR", func() {
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
})
|
||||
|
||||
It("Create klusterlet CR in Hosted mode", func() {
|
||||
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
|
||||
_, err := t.CreateKlusterlet(klusterletName, clusterName, klusterletNamespace, operatorapiv1.InstallModeHosted)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("waiting for the managed cluster %v to be created", clusterName))
|
||||
Eventually(func() error {
|
||||
_, err := t.GetCreatedManagedCluster(clusterName)
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s status", klusterletName))
|
||||
Eventually(func() error {
|
||||
err := t.checkKlusterletStatus(klusterletName, "HubConnectionDegraded", "BootstrapSecretFunctional,HubKubeConfigSecretMissing", metav1.ConditionTrue)
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("approve the created managed cluster %v", clusterName))
|
||||
Eventually(func() error {
|
||||
return t.ApproveCSR(clusterName)
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("accept the created managed cluster %v", clusterName))
|
||||
Eventually(func() error {
|
||||
return t.AcceptsClient(clusterName)
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("waiting for the managed cluster %v to be ready", clusterName))
|
||||
Eventually(func() error {
|
||||
return t.CheckManagedClusterStatus(clusterName)
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s status", klusterletName))
|
||||
Eventually(func() error {
|
||||
err := t.checkKlusterletStatus(klusterletName, "HubConnectionDegraded", "HubConnectionFunctional", metav1.ConditionFalse)
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
})
|
||||
})
|
||||
|
||||
var _ = Describe("Delete klusterlet CR", func() {
|
||||
var klusterletName string
|
||||
var clusterName string
|
||||
var klusterletNamespace string
|
||||
|
||||
BeforeEach(func() {
|
||||
klusterletName = fmt.Sprintf("e2e-klusterlet-%s", rand.String(6))
|
||||
clusterName = fmt.Sprintf("e2e-managedcluster-%s", rand.String(6))
|
||||
klusterletNamespace = fmt.Sprintf("open-cluster-management-agent-%s", rand.String(6))
|
||||
})
|
||||
|
||||
It("Delete klusterlet CR in Hosted mode without external managed kubeconfig", func() {
|
||||
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v in Hosted mode", klusterletName, clusterName))
|
||||
_, err := t.CreatePureHostedKlusterlet(klusterletName, clusterName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s status", klusterletName))
|
||||
Eventually(func() error {
|
||||
err := t.checkKlusterletStatus(klusterletName, "ReadyToApply", "KlusterletPrepareFailed", metav1.ConditionFalse)
|
||||
return err
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("delete the klusterlet %s", klusterletName))
|
||||
err = t.OperatorClient.OperatorV1().Klusterlets().Delete(context.TODO(),
|
||||
klusterletName, metav1.DeleteOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s was deleted", klusterletName))
|
||||
Eventually(func() error {
|
||||
_, err := t.OperatorClient.OperatorV1().Klusterlets().Get(context.TODO(),
|
||||
klusterletName, metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("klusterlet still exists")
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("check the agent namespace %s on the management cluster was deleted", klusterletName))
|
||||
Eventually(func() error {
|
||||
_, err := t.HubKubeClient.CoreV1().Namespaces().Get(context.TODO(),
|
||||
klusterletName, metav1.GetOptions{})
|
||||
if errors.IsNotFound(err) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("klusterlet namespace still exists")
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
})
|
||||
|
||||
It("Delete klusterlet CR in Hosted mode when the managed cluster was destroyed", func() {
|
||||
By(fmt.Sprintf("create klusterlet %v with managed cluster name %v", klusterletName, clusterName))
|
||||
klusterlet, err := t.CreateKlusterlet(klusterletName, clusterName, klusterletNamespace, operatorapiv1.InstallModeHosted)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("waiting for the managed cluster %v to be created", clusterName))
|
||||
Eventually(func() error {
|
||||
_, err := t.GetCreatedManagedCluster(clusterName)
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s status", klusterletName))
|
||||
Eventually(func() error {
|
||||
err := t.checkKlusterletStatus(klusterletName, "HubConnectionDegraded",
|
||||
"BootstrapSecretFunctional,HubKubeConfigSecretMissing", metav1.ConditionTrue)
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("approve the created managed cluster %v", clusterName))
|
||||
Eventually(func() error {
|
||||
return t.ApproveCSR(clusterName)
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("accept the created managed cluster %v", clusterName))
|
||||
Eventually(func() error {
|
||||
return t.AcceptsClient(clusterName)
|
||||
}, t.EventuallyTimeout, t.EventuallyInterval).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("waiting for the managed cluster %v to be ready", clusterName))
|
||||
Eventually(func() error {
|
||||
return t.CheckManagedClusterStatus(clusterName)
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
By(fmt.Sprintf("check klusterlet %s status", klusterletName))
|
||||
Eventually(func() error {
|
||||
err := t.checkKlusterletStatus(klusterletName, "HubConnectionDegraded",
|
||||
"HubConnectionFunctional", metav1.ConditionFalse)
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
|
||||
// change the kubeconfig host of external managed kubeconfig secret to a wrong value
|
||||
// to simulate the managed cluster was destroyed
|
||||
By("Delete external managed kubeconfig", func() {
|
||||
err = t.DeleteExternalKubeconfigSecret(klusterlet)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
By("Delete managed cluster", func() {
|
||||
// clean the managed clusters
|
||||
err = t.ClusterClient.ClusterV1().ManagedClusters().Delete(context.TODO(),
|
||||
clusterName, metav1.DeleteOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
By("Delete klusterlet", func() {
|
||||
// clean the klusterlets
|
||||
err = t.OperatorClient.OperatorV1().Klusterlets().Delete(context.TODO(),
|
||||
klusterletName, metav1.DeleteOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
By("Create a fake external managed kubeconfig", func() {
|
||||
err = t.CreateFakeExternalKubeconfigSecret(klusterlet)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
// in the future, if the eviction can be configured, we can set a short timeout period and
|
||||
// remove the wait and update parts
|
||||
evictionTimestampAnno := "operator.open-cluster-management.io/managed-resources-eviction-timestamp"
|
||||
By("Wait for the eviction timestamp annotation", func() {
|
||||
Eventually(func() error {
|
||||
k, err := t.OperatorClient.OperatorV1().Klusterlets().Get(context.TODO(),
|
||||
klusterletName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, ok := k.Annotations[evictionTimestampAnno]
|
||||
if !ok {
|
||||
return fmt.Errorf("expected annotation %s does not exist", evictionTimestampAnno)
|
||||
}
|
||||
return nil
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
})
|
||||
|
||||
time.Sleep(3 * time.Second) // after the eviction timestamp exists, wait 3 seconds for cache syncing
|
||||
By("Update the eviction timestamp annotation", func() {
|
||||
Eventually(func() error {
|
||||
k, err := t.OperatorClient.OperatorV1().Klusterlets().Get(context.TODO(),
|
||||
klusterletName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ta := time.Now().Add(-6 * time.Minute).Format(time.RFC3339)
|
||||
By(fmt.Sprintf("add time %v anno for klusterlet %s", ta, klusterletName))
|
||||
k.Annotations[evictionTimestampAnno] = ta
|
||||
_, err = t.OperatorClient.OperatorV1().Klusterlets().Update(context.TODO(),
|
||||
k, metav1.UpdateOptions{})
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
})
|
||||
|
||||
By("Check manged cluster and klusterlet can be deleted", func() {
|
||||
Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -72,7 +72,8 @@ var _ = ginkgo.Describe("Loopback registration [development]", 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))
|
||||
_, err := t.CreateApprovedKlusterlet(klusterletName, clusterName, agentNamespace, operatorapiv1.InstallModeDefault)
|
||||
_, err := t.CreateApprovedKlusterlet(
|
||||
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||
}
|
||||
var (
|
||||
|
||||
@@ -54,7 +54,8 @@ var _ = ginkgo.Describe("Test ManifestWorkReplicaSet", 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))
|
||||
_, err := t.CreateApprovedKlusterlet(klusterletName, clusterName, agentNamespace, operatorapiv1.InstallModeDefault)
|
||||
_, err := t.CreateApprovedKlusterlet(
|
||||
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package e2e
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
|
||||
operatorapiv1 "open-cluster-management.io/api/operator/v1"
|
||||
)
|
||||
|
||||
var _ = Describe("Create klusterlet and then create a configmap by manifestwork in hosted mode", func() {
|
||||
var klusterletName, clusterName, agentNamespace, workName, configMapName string
|
||||
var configMapNamespace = "default"
|
||||
|
||||
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))
|
||||
workName = fmt.Sprintf("e2e-work-configmap-%s", rand.String(6))
|
||||
configMapName = fmt.Sprintf("e2e-configmap-%s", rand.String(6))
|
||||
|
||||
_, err := t.CreateApprovedKlusterlet(klusterletName, clusterName, agentNamespace, operatorapiv1.InstallModeHosted)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
By(fmt.Sprintf("delete manifestwork %v/%v", clusterName, workName))
|
||||
Expect(t.cleanManifestWorks(clusterName, workName)).To(BeNil())
|
||||
By(fmt.Sprintf("clean klusterlet %s resources after the test case, clusterName: %s", klusterletName, clusterName))
|
||||
Expect(t.cleanKlusterletResources(klusterletName, clusterName)).To(BeNil())
|
||||
})
|
||||
|
||||
It("Create configmap using manifestwork and then delete klusterlet in Hosted mode", func() {
|
||||
var err error
|
||||
|
||||
By(fmt.Sprintf("create configmap %v/%v using manifestwork %v/%v", configMapNamespace,
|
||||
configMapName, clusterName, workName))
|
||||
_, err = t.CreateWorkOfConfigMap(workName, clusterName, configMapName, configMapNamespace)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By(fmt.Sprintf("waiting for configmap %v/%v to be created", configMapNamespace, configMapName))
|
||||
Eventually(func() error {
|
||||
_, err := t.SpokeKubeClient.CoreV1().ConfigMaps(configMapNamespace).
|
||||
Get(context.TODO(), configMapName, metav1.GetOptions{})
|
||||
return err
|
||||
}, t.EventuallyTimeout*5, t.EventuallyInterval*5).Should(Succeed())
|
||||
})
|
||||
})
|
||||
@@ -34,7 +34,8 @@ var _ = ginkgo.Describe("ManifestWork admission webhook", ginkgo.Label("validati
|
||||
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.InstallModeDefault)
|
||||
_, err := t.CreateApprovedKlusterlet(
|
||||
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -161,7 +161,8 @@ var _ = ginkgo.Describe("Work agent", ginkgo.Label("work-agent", "sanity-check")
|
||||
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.InstallModeDefault)
|
||||
_, err := t.CreateApprovedKlusterlet(
|
||||
klusterletName, clusterName, agentNamespace, operatorapiv1.InstallMode(klusterletDeployMode))
|
||||
gomega.Expect(err).ToNot(gomega.HaveOccurred())
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user