|
| 1 | +// Copyright Contributors to the Open Cluster Management project |
| 2 | +package clusteradme2e |
| 3 | + |
| 4 | +import ( |
| 5 | + "context" |
| 6 | + "time" |
| 7 | + |
| 8 | + "github.com/onsi/ginkgo/v2" |
| 9 | + "github.com/onsi/gomega" |
| 10 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 11 | + operatorv1 "open-cluster-management.io/api/operator/v1" |
| 12 | + "open-cluster-management.io/clusteradm/test/e2e/util" |
| 13 | +) |
| 14 | + |
| 15 | +var _ = ginkgo.Describe("test clusteradm join with annotations", func() { |
| 16 | + ginkgo.BeforeEach(func() { |
| 17 | + ginkgo.By("clear e2e environment...") |
| 18 | + err := e2e.ClearEnv() |
| 19 | + gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 20 | + }) |
| 21 | + |
| 22 | + ginkgo.Context("join hub scenario with annotations", func() { |
| 23 | + var err error |
| 24 | + |
| 25 | + ginkgo.It("should managedclusters join with annotations and be accepted successfully", func() { |
| 26 | + ginkgo.By("init hub") |
| 27 | + err = e2e.Clusteradm().Init( |
| 28 | + "--context", e2e.Cluster().Hub().Context(), |
| 29 | + "--bundle-version=latest", |
| 30 | + ) |
| 31 | + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "clusteradm init error") |
| 32 | + |
| 33 | + ginkgo.By("managedcluster1 join hub with annotations") |
| 34 | + err = e2e.Clusteradm().Join( |
| 35 | + "--context", e2e.Cluster().ManagedCluster1().Context(), |
| 36 | + "--hub-token", e2e.CommandResult().Token(), "--hub-apiserver", e2e.CommandResult().Host(), |
| 37 | + "--cluster-name", e2e.Cluster().ManagedCluster1().Name(), |
| 38 | + "--wait", |
| 39 | + "--bundle-version=latest", |
| 40 | + "--force-internal-endpoint-lookup", |
| 41 | + "--klusterlet-annotation", "foo=bar", |
| 42 | + "--klusterlet-annotation", "test=value", |
| 43 | + ) |
| 44 | + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "managedcluster1 join error") |
| 45 | + gomega.Eventually(func() error { |
| 46 | + return util.ValidateImagePullSecret(managedClusterKubeClient, |
| 47 | + "e30=", "open-cluster-management") |
| 48 | + }, time.Second*120, time.Second*2).ShouldNot(gomega.HaveOccurred()) |
| 49 | + |
| 50 | + ginkgo.By("hub accept managedcluster1") |
| 51 | + err = e2e.Clusteradm().Accept( |
| 52 | + "--clusters", e2e.Cluster().ManagedCluster1().Name(), |
| 53 | + "--wait", |
| 54 | + "--context", e2e.Cluster().Hub().Context(), |
| 55 | + ) |
| 56 | + gomega.Expect(err).NotTo(gomega.HaveOccurred(), "clusteradm accept error") |
| 57 | + |
| 58 | + ginkgo.By("verify managedcluster1 has correct annotations") |
| 59 | + gomega.Eventually(func() map[string]string { |
| 60 | + managedCluster, err := clusterClient.ClusterV1().ManagedClusters().Get( |
| 61 | + context.TODO(), e2e.Cluster().ManagedCluster1().Name(), metav1.GetOptions{}) |
| 62 | + if err != nil { |
| 63 | + return nil |
| 64 | + } |
| 65 | + return managedCluster.GetAnnotations() |
| 66 | + }, time.Second*60, time.Second*2).Should(gomega.HaveKey(operatorv1.ClusterAnnotationsKeyPrefix + "foo")) |
| 67 | + managedCluster, err := clusterClient.ClusterV1().ManagedClusters().Get( |
| 68 | + context.TODO(), e2e.Cluster().ManagedCluster1().Name(), metav1.GetOptions{}) |
| 69 | + gomega.Expect(err).NotTo(gomega.HaveOccurred()) |
| 70 | + annotations := managedCluster.GetAnnotations() |
| 71 | + gomega.Expect(annotations).NotTo(gomega.BeNil()) |
| 72 | + gomega.Expect(annotations[operatorv1.ClusterAnnotationsKeyPrefix+"/foo"]).To(gomega.Equal("bar")) |
| 73 | + gomega.Expect(annotations[operatorv1.ClusterAnnotationsKeyPrefix+"/test"]).To(gomega.Equal("value")) |
| 74 | + }) |
| 75 | + }) |
| 76 | +}) |
0 commit comments