Skip to content

Commit 530cc31

Browse files
committed
Try binding the clusterset
This still has some debug lines we can remove later. Signed-off-by: Justin Kulikauskas <[email protected]>
1 parent eb0d17d commit 530cc31

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

test/common/gvr.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,9 @@ var (
127127
Version: "v1beta2",
128128
Resource: "managedclustersets",
129129
}
130+
GvrManagedClusterSetBinding = schema.GroupVersionResource{
131+
Group: "cluster.open-cluster-management.io",
132+
Version: "v1beta2",
133+
Resource: "managedclustersetbindings",
134+
}
130135
)

test/integration/policy_generator_acm_hardening_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1212
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1313
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14+
"open-cluster-management.io/governance-policy-propagator/test/utils"
1415

1516
"github.com/stolostron/governance-policy-framework/test/common"
1617
)
@@ -44,6 +45,46 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the ACM Hardening "+
4445
Expect(err).ToNot(HaveOccurred())
4546
}
4647

48+
By("Verifying that the default ManagedClusterSet is bound to the policies namespace")
49+
clusterbindings, err := clientHubDynamic.Resource(common.GvrManagedClusterSetBinding).
50+
Namespace("policies").List(context.TODO(), metav1.ListOptions{})
51+
Expect(err).ToNot(HaveOccurred())
52+
53+
found := false
54+
55+
for _, mcsb := range clusterbindings.Items {
56+
clustersetName, ok, err := unstructured.NestedString(mcsb.Object, "spec", "clusterSet")
57+
Expect(err).ToNot(HaveOccurred())
58+
Expect(ok).To(BeTrue())
59+
60+
if clustersetName == "default" {
61+
found = true
62+
break
63+
}
64+
}
65+
66+
if !found {
67+
By("Creating the ManagedClusterSetBinding")
68+
69+
defaultBinding := unstructured.Unstructured{
70+
Object: map[string]interface{}{
71+
"apiVersion": "cluster.open-cluster-management.io/v1beta2",
72+
"kind": "ManagedClusterSetBinding",
73+
"metadata": map[string]interface{}{
74+
"name": "default",
75+
"namespace": "policies",
76+
},
77+
"spec": map[string]interface{}{
78+
"clusterSet": "default",
79+
},
80+
},
81+
}
82+
83+
_, err := clientHubDynamic.Resource(common.GvrManagedClusterSetBinding).
84+
Namespace("policies").Create(context.TODO(), &defaultBinding, metav1.CreateOptions{})
85+
Expect(err).ToNot(HaveOccurred())
86+
}
87+
4788
By("Creating the application subscription")
4889
_, err = common.OcUser(
4990
gitopsUser,
@@ -107,6 +148,8 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the ACM Hardening "+
107148
1,
108149
).Should(BeNil())
109150

151+
eCounter := 0
152+
110153
By("Checking that the policy-managedclusteraddon-available policy " +
111154
"was propagated to the local-cluster namespace")
112155
Eventually(
@@ -117,6 +160,24 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the ACM Hardening "+
117160
metav1.GetOptions{},
118161
)
119162

163+
if eCounter > 9 {
164+
eCounter = 0
165+
166+
GinkgoWriter.Print("placement: ")
167+
_, _ = utils.KubectlWithOutput("get", "placement", "-A", "-ojsonpath={@}",
168+
"--kubeconfig="+kubeconfigHub)
169+
170+
GinkgoWriter.Print("managedclusterset: ")
171+
_, _ = utils.KubectlWithOutput("get", "managedclusterset", "-A", "-ojsonpath={@}",
172+
"--kubeconfig="+kubeconfigHub)
173+
174+
GinkgoWriter.Print("managedclustersetbinding: ")
175+
_, _ = utils.KubectlWithOutput("get", "managedclustersetbinding", "-A", "-ojsonpath={@}",
176+
"--kubeconfig="+kubeconfigHub)
177+
}
178+
179+
eCounter++
180+
120181
return err
121182
},
122183
defaultTimeoutSeconds*2,

0 commit comments

Comments
 (0)