Skip to content

Commit

Permalink
add patch mcl rbac and e2e (stolostron#612)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhiwei Yin <[email protected]>
  • Loading branch information
zhiweiyin318 authored May 18, 2023
1 parent a581bc5 commit 7c7eb07
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deploy/foundation/hub/resources/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/clusterinfos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,23 @@ 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 {
return false
}
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())
})
})
})
28 changes: 16 additions & 12 deletions test/e2e/managedcluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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())
})

})
Expand Down

0 comments on commit 7c7eb07

Please sign in to comment.