Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
exclude add-on csrs (#286)
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Liu <[email protected]>

Signed-off-by: Wei Liu <[email protected]>
  • Loading branch information
skeeey authored Nov 21, 2022
1 parent 4d8c5c5 commit 18e7982
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
3 changes: 1 addition & 2 deletions pkg/spoke/managedcluster/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ func indexByClusterFunc(obj interface{}) ([]string, error) {
}

// should not contain addon key
_, ok = accessor.GetLabels()[clientcert.AddonNameLabel]
if !ok {
if _, ok := accessor.GetLabels()[clientcert.AddonNameLabel]; ok {
return []string{}, nil
}

Expand Down
20 changes: 13 additions & 7 deletions test/e2e/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ var _ = ginkgo.Describe("Admission webhook", func() {
gomega.Expect(u.deleteManageClusterAndRelatedNamespace(clusterName)).ToNot(gomega.HaveOccurred())
gomega.Expect(cleanupClusterClient(saNamespace, sa)).ToNot(gomega.HaveOccurred())
})

ginkgo.It("Should accept the request when update managed cluster other field by unauthorized user", func() {
sa := fmt.Sprintf("webhook-sa-%s", rand.String(6))
clusterName := fmt.Sprintf("webhook-spoke-%s", rand.String(6))
Expand All @@ -277,16 +278,21 @@ var _ = ginkgo.Describe("Admission webhook", func() {
gomega.Expect(err).ToNot(gomega.HaveOccurred())

managedCluster := newManagedCluster(clusterName, true, validURL)

managedCluster, err = clusterClient.ClusterV1().ManagedClusters().Create(context.TODO(), managedCluster, metav1.CreateOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())

managedCluster, err = clusterClient.ClusterV1().ManagedClusters().Get(context.TODO(), managedCluster.Name, metav1.GetOptions{})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
updatedManagedCluster := managedCluster.DeepCopy()
updatedManagedCluster.Labels = map[string]string{
"k": "v",
}
_, err = unauthorizedClient.ClusterV1().ManagedClusters().Update(context.TODO(), updatedManagedCluster, metav1.UpdateOptions{})
err = retry.RetryOnConflict(retry.DefaultRetry, func() error {
managedCluster, err := clusterClient.ClusterV1().ManagedClusters().Get(context.TODO(), managedCluster.Name, metav1.GetOptions{})
if err != nil {
return err
}
managedCluster.Labels = map[string]string{
"k": "v",
}
_, err = unauthorizedClient.ClusterV1().ManagedClusters().Update(context.TODO(), managedCluster, metav1.UpdateOptions{})
return err
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
gomega.Expect(u.deleteManageClusterAndRelatedNamespace(clusterName)).ToNot(gomega.HaveOccurred())
gomega.Expect(cleanupClusterClient(saNamespace, sa)).ToNot(gomega.HaveOccurred())
Expand Down

0 comments on commit 18e7982

Please sign in to comment.