@@ -11,6 +11,7 @@ import (
11
11
k8serrors "k8s.io/apimachinery/pkg/api/errors"
12
12
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13
13
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14
+ "open-cluster-management.io/governance-policy-propagator/test/utils"
14
15
15
16
"github.com/stolostron/governance-policy-framework/test/common"
16
17
)
@@ -44,6 +45,46 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the ACM Hardening "+
44
45
Expect (err ).ToNot (HaveOccurred ())
45
46
}
46
47
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
+
47
88
By ("Creating the application subscription" )
48
89
_ , err = common .OcUser (
49
90
gitopsUser ,
@@ -107,6 +148,8 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the ACM Hardening "+
107
148
1 ,
108
149
).Should (BeNil ())
109
150
151
+ eCounter := 0
152
+
110
153
By ("Checking that the policy-managedclusteraddon-available policy " +
111
154
"was propagated to the local-cluster namespace" )
112
155
Eventually (
@@ -117,6 +160,24 @@ var _ = Describe("GRC: [P1][Sev1][policy-grc] Test the ACM Hardening "+
117
160
metav1.GetOptions {},
118
161
)
119
162
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
+
120
181
return err
121
182
},
122
183
defaultTimeoutSeconds * 2 ,
0 commit comments