@@ -116,10 +116,11 @@ func TestOperatorGroup(t *testing.T) {
116
116
require .NoError (t , err )
117
117
118
118
t .Log ("Creating CRD" )
119
- mainCRDPlural := genName ("ins " )
120
- apiGroup := "cluster .com"
119
+ mainCRDPlural := genName ("opgroup " )
120
+ apiGroup := "opcluster .com"
121
121
mainCRDName := mainCRDPlural + "." + apiGroup
122
122
mainCRD := newCRD (mainCRDName , mainCRDPlural )
123
+ mainCRD .Spec .Group = apiGroup
123
124
cleanupCRD , err := createCRD (c , mainCRD )
124
125
require .NoError (t , err )
125
126
defer cleanupCRD ()
@@ -129,6 +130,10 @@ func TestOperatorGroup(t *testing.T) {
129
130
createdCSV , err := crc .OperatorsV1alpha1 ().ClusterServiceVersions (testNamespace ).Create (& aCSV )
130
131
require .NoError (t , err )
131
132
133
+ t .Log ("wait for CSV to succeed" )
134
+ _ , err = fetchCSV (t , crc , createdCSV .GetName (), csvSucceededChecker )
135
+ require .NoError (t , err )
136
+
132
137
t .Log ("Creating operator group" )
133
138
operatorGroup := v1alpha2.OperatorGroup {
134
139
ObjectMeta : metav1.ObjectMeta {
@@ -145,7 +150,7 @@ func TestOperatorGroup(t *testing.T) {
145
150
_ , err = crc .OperatorsV1alpha2 ().OperatorGroups (testNamespace ).Create (& operatorGroup )
146
151
require .NoError (t , err )
147
152
expectedOperatorGroupStatus := v1alpha2.OperatorGroupStatus {
148
- Namespaces : []string {createdOtherNamespace .GetName ()},
153
+ Namespaces : []string {createdOtherNamespace .GetName (), testNamespace },
149
154
}
150
155
151
156
t .Log ("Waiting on operator group to have correct status" )
@@ -161,30 +166,51 @@ func TestOperatorGroup(t *testing.T) {
161
166
return false , nil
162
167
})
163
168
164
- t .Log ("Checking for proper generated operator-group RBAC roles" )
165
- roleList , err := c .KubernetesInterface ().RbacV1 ().ClusterRoles ().List (metav1.ListOptions {})
166
- for _ , item := range roleList .Items {
167
- role , err := c .GetClusterRole (item .GetName ())
168
- require .NoError (t , err )
169
- switch roleName := item .GetName (); roleName {
170
- case "owned-crd-manager-another-csv" :
171
- managerPolicyRules := []rbacv1.PolicyRule {
172
- {Verbs : []string {"*" }, APIGroups : []string {apiGroup }, Resources : []string {mainCRDPlural }},
173
- }
174
- require .Equal (t , managerPolicyRules , role .Rules )
175
- case "e2e-operator-group-edit" :
176
- editPolicyRules := []rbacv1.PolicyRule {
177
- {Verbs : []string {"create" , "update" , "patch" , "delete" }, APIGroups : []string {apiGroup }, Resources : []string {mainCRDPlural }},
169
+ t .Log ("Waiting for expected operator group test APIGroup from CSV" )
170
+ err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
171
+ // (view role is the last role created, so the rest should exist as well by this point)
172
+ viewRole , fetchErr := c .KubernetesInterface ().RbacV1 ().ClusterRoles ().Get ("e2e-operator-group-view" , metav1.GetOptions {})
173
+ if fetchErr != nil {
174
+ if errors .IsNotFound (fetchErr ) {
175
+ return false , nil
178
176
}
179
- t .Log (role )
180
- require .Equal (t , editPolicyRules , role .Rules )
181
- case "e2e-operator-group-view" :
182
- viewPolicyRules := []rbacv1.PolicyRule {
183
- {Verbs : []string {"get" , "list" , "watch" }, APIGroups : []string {apiGroup }, Resources : []string {mainCRDPlural }},
177
+ t .Logf ("Unable to fetch view role: %v" , fetchErr .Error ())
178
+ return false , fetchErr
179
+ }
180
+ for _ , rule := range viewRole .Rules {
181
+ for _ , group := range rule .APIGroups {
182
+ if group == apiGroup {
183
+ return true , nil
184
+ }
184
185
}
185
- require .Equal (t , viewPolicyRules , role .Rules )
186
186
}
187
+ return false , nil
188
+ })
189
+
190
+ t .Log ("Checking for proper generated operator group RBAC roles" )
191
+ editRole , err := c .KubernetesInterface ().RbacV1 ().ClusterRoles ().Get ("e2e-operator-group-edit" , metav1.GetOptions {})
192
+ require .NoError (t , err )
193
+ editPolicyRules := []rbacv1.PolicyRule {
194
+ {Verbs : []string {"create" , "update" , "patch" , "delete" }, APIGroups : []string {apiGroup }, Resources : []string {mainCRDPlural }},
195
+ }
196
+ t .Log (editRole )
197
+ require .Equal (t , editPolicyRules , editRole .Rules )
198
+
199
+ viewRole , err := c .KubernetesInterface ().RbacV1 ().ClusterRoles ().Get ("e2e-operator-group-view" , metav1.GetOptions {})
200
+ require .NoError (t , err )
201
+ viewPolicyRules := []rbacv1.PolicyRule {
202
+ {Verbs : []string {"get" , "list" , "watch" }, APIGroups : []string {apiGroup }, Resources : []string {mainCRDPlural }},
203
+ }
204
+ t .Log (viewRole )
205
+ require .Equal (t , viewPolicyRules , viewRole .Rules )
206
+
207
+ managerRole , err := c .KubernetesInterface ().RbacV1 ().ClusterRoles ().Get ("owned-crd-manager-another-csv" , metav1.GetOptions {})
208
+ require .NoError (t , err )
209
+ managerPolicyRules := []rbacv1.PolicyRule {
210
+ {Verbs : []string {"*" }, APIGroups : []string {apiGroup }, Resources : []string {mainCRDPlural }},
187
211
}
212
+ t .Log (managerRole )
213
+ require .Equal (t , managerPolicyRules , managerRole .Rules )
188
214
189
215
t .Log ("Waiting for operator namespace csv to have annotations" )
190
216
err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
@@ -203,7 +229,10 @@ func TestOperatorGroup(t *testing.T) {
203
229
err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
204
230
fetchedCSV , fetchErr := crc .OperatorsV1alpha1 ().ClusterServiceVersions (otherNamespaceName ).Get (csvName , metav1.GetOptions {})
205
231
if fetchErr != nil {
206
- t .Log (fetchErr .Error ())
232
+ if errors .IsNotFound (fetchErr ) {
233
+ return false , nil
234
+ }
235
+ t .Logf ("Error (in %v): %v" , otherNamespaceName , fetchErr .Error ())
207
236
return false , fetchErr
208
237
}
209
238
if checkOperatorGroupAnnotations (fetchedCSV , & operatorGroup , bothNamespaceNames ) == nil {
@@ -214,12 +243,21 @@ func TestOperatorGroup(t *testing.T) {
214
243
})
215
244
// since annotations are set along with status, no reason to poll for this check as done above
216
245
t .Log ("Checking status on csv in target namespace" )
217
- fetchedCSV , err := crc .OperatorsV1alpha1 ().ClusterServiceVersions (otherNamespaceName ).Get (csvName , metav1.GetOptions {})
246
+ err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
247
+ fetchedCSV , fetchErr := crc .OperatorsV1alpha1 ().ClusterServiceVersions (otherNamespaceName ).Get (csvName , metav1.GetOptions {})
248
+ if fetchErr != nil {
249
+ if errors .IsNotFound (fetchErr ) {
250
+ return false , nil
251
+ }
252
+ t .Logf ("Error (in %v): %v" , otherNamespaceName , fetchErr .Error ())
253
+ return false , fetchErr
254
+ }
255
+ if fetchedCSV .Status .Reason == v1alpha1 .CSVReasonCopied {
256
+ return true , nil
257
+ }
258
+ return false , nil
259
+ })
218
260
require .NoError (t , err )
219
- require .EqualValues (t , v1alpha1 .CSVReasonCopied , fetchedCSV .Status .Reason )
220
- // also check name and spec
221
- require .EqualValues (t , createdCSV .Name , fetchedCSV .Name )
222
- require .EqualValues (t , createdCSV .Spec , fetchedCSV .Spec )
223
261
224
262
t .Log ("Waiting on deployment to have correct annotations" )
225
263
err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
0 commit comments