diff --git a/deploy/foundation/hub/resources/clusterrole.yaml b/deploy/foundation/hub/resources/clusterrole.yaml index ed0392b85..844c17134 100644 --- a/deploy/foundation/hub/resources/clusterrole.yaml +++ b/deploy/foundation/hub/resources/clusterrole.yaml @@ -37,7 +37,7 @@ rules: verbs: ["get", "list", "watch", "update", "patch"] - apiGroups: ["cluster.open-cluster-management.io"] resources: ["managedclusters","managedclustersets","placementdecisions","placementdecisions/status"] - verbs: ["get", "list", "watch", "update"] + verbs: ["get", "list", "watch", "update", "patch"] - apiGroups: ["cluster.open-cluster-management.io"] resources: ["managedclustersetbindings"] verbs: ["create", "update", "get", "list", "watch", "delete", "deletecollection", "patch"] diff --git a/test/e2e/clusterinfos_test.go b/test/e2e/clusterinfos_test.go index 16e837f84..8b4105f77 100644 --- a/test/e2e/clusterinfos_test.go +++ b/test/e2e/clusterinfos_test.go @@ -91,6 +91,7 @@ var _ = ginkgo.Describe("Testing ManagedClusterInfo", func() { err := util.DeleteClusterResource(dynamicClient, util.ManagedClusterGVR, testManagedClusterName) gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) + // managedClusterInfo should be deleted gomega.Eventually(func() bool { existing, err := util.HasResource(dynamicClient, util.ClusterInfoGVR, testManagedClusterName, testManagedClusterName) if err != nil { @@ -98,6 +99,15 @@ var _ = ginkgo.Describe("Testing ManagedClusterInfo", func() { } return existing }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.BeTrue()) + + // managedCluster should be deleted + gomega.Eventually(func() bool { + existing, err := util.HasClusterResource(dynamicClient, util.ManagedClusterGVR, testManagedClusterName) + if err != nil { + return false + } + return existing + }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.BeTrue()) }) }) }) diff --git a/test/e2e/managedcluster_test.go b/test/e2e/managedcluster_test.go index 6a135f3d0..3b66873bc 100644 --- a/test/e2e/managedcluster_test.go +++ b/test/e2e/managedcluster_test.go @@ -90,23 +90,25 @@ var _ = ginkgo.Describe("Testing ManagedCluster", func() { newApiserver, err = ocpClient.ConfigV1().APIServers().Update(context.TODO(), newApiserver, metav1.UpdateOptions{}) gomega.Expect(err).ToNot(gomega.HaveOccurred()) - gomega.Eventually(func() bool { + gomega.Eventually(func() error { cluster, err := clusterClient.ClusterV1().ManagedClusters().Get(context.Background(), defaultManagedCluster, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + if err != nil { + return err + } if len(cluster.Spec.ManagedClusterClientConfigs) == 0 { - return false + return fmt.Errorf("cluster.Spec.ManagedClusterClientConfigs should not be 0") } for _, config := range cluster.Spec.ManagedClusterClientConfigs { if config.URL != apiserverAddress { continue } if reflect.DeepEqual(config.CABundle, fakeSecret.Data["tls.crt"]) { - return true + return nil } } - return false - }, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue()) + return fmt.Errorf("cannot found config") + }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) //rollback apiserver and delete secret newApiserver.Spec.ServingCerts.NamedCertificates = []configv1.APIServerNamedServingCert{} @@ -161,20 +163,22 @@ var _ = ginkgo.Describe("Testing ManagedCluster", func() { serviceAccountCa, err := utils.GetCAFromServiceAccount(context.TODO(), kubeClient) gomega.Expect(err).ToNot(gomega.HaveOccurred()) - gomega.Eventually(func() bool { + gomega.Eventually(func() error { cluster, err := clusterClient.ClusterV1().ManagedClusters().Get(context.Background(), defaultManagedCluster, metav1.GetOptions{}) - gomega.Expect(err).ToNot(gomega.HaveOccurred()) + if err != nil { + return err + } if len(cluster.Spec.ManagedClusterClientConfigs) == 0 { - return false + return fmt.Errorf("cluster.Spec.ManagedClusterClientConfigs should not be 0") } for _, config := range cluster.Spec.ManagedClusterClientConfigs { if reflect.DeepEqual(config.CABundle, serviceAccountCa) { - return true + return nil } } - return false - }, eventuallyTimeout, eventuallyInterval).Should(gomega.BeTrue()) + return fmt.Errorf("cannot found config") + }, eventuallyTimeout, eventuallyInterval).ShouldNot(gomega.HaveOccurred()) }) })