@@ -6,13 +6,15 @@ import (
6
6
"strings"
7
7
"testing"
8
8
9
- appsv1 "k8s.io/api/apps/v1"
10
- "k8s.io/apimachinery/pkg/api/errors"
11
- "k8s.io/apimachinery/pkg/util/wait"
12
9
"github.com/coreos/go-semver/semver"
13
10
"github.com/stretchr/testify/require"
11
+ appsv1 "k8s.io/api/apps/v1"
14
12
corev1 "k8s.io/api/core/v1"
13
+ rbacv1 "k8s.io/api/rbac/v1"
14
+ extv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
15
+ "k8s.io/apimachinery/pkg/api/errors"
15
16
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
17
+ "k8s.io/apimachinery/pkg/util/wait"
16
18
17
19
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
18
20
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha2"
@@ -78,6 +80,7 @@ func checkOperatorGroupAnnotations(obj metav1.Object, op *v1alpha2.OperatorGroup
78
80
79
81
func TestOperatorGroup (t * testing.T ) {
80
82
// Create namespace with specific label
83
+ // Create CRD
81
84
// Create CSV in operator namespace
82
85
// Create operator group that watches namespace and uses specific label
83
86
// Verify operator group status contains correct status
@@ -103,8 +106,16 @@ func TestOperatorGroup(t *testing.T) {
103
106
104
107
oldCommand := patchOlmDeployment (t , c , otherNamespaceName )
105
108
109
+ t .Log ("Creating CRD" )
110
+ mainCRDPlural := genName ("ins" )
111
+ apiGroup := "cluster.com"
112
+ mainCRDName := mainCRDPlural + "." + apiGroup
113
+ mainCRD := newCRD (mainCRDName , testNamespace , mainCRDPlural )
114
+ cleanupCRD , err := createCRD (c , mainCRD )
115
+ require .NoError (t , err )
116
+
106
117
t .Log ("Creating CSV" )
107
- aCSV := newCSV (csvName , testNamespace , "" , * semver .New ("0.0.0" ), nil , nil , newNginxInstallStrategy ("operator-deployment" , nil , nil ))
118
+ aCSV := newCSV (csvName , testNamespace , "" , * semver .New ("0.0.0" ), []extv1beta1. CustomResourceDefinition { mainCRD } , nil , newNginxInstallStrategy ("operator-deployment" , nil , nil ))
108
119
createdCSV , err := crc .OperatorsV1alpha1 ().ClusterServiceVersions (testNamespace ).Create (& aCSV )
109
120
require .NoError (t , err )
110
121
@@ -119,6 +130,7 @@ func TestOperatorGroup(t *testing.T) {
119
130
MatchLabels : matchingLabel ,
120
131
},
121
132
},
133
+ //ServiceAccountName: "default-sa",
122
134
}
123
135
_ , err = crc .OperatorsV1alpha2 ().OperatorGroups (testNamespace ).Create (& operatorGroup )
124
136
require .NoError (t , err )
@@ -133,12 +145,36 @@ func TestOperatorGroup(t *testing.T) {
133
145
return false , fetchErr
134
146
}
135
147
if len (fetched .Status .Namespaces ) > 0 {
136
- require .Equal (t , expectedOperatorGroupStatus .Namespaces [0 ].Name , fetched .Status .Namespaces [0 ].Name )
148
+ require .EqualValues (t , expectedOperatorGroupStatus .Namespaces [0 ].Name , fetched .Status .Namespaces [0 ].Name )
137
149
return true , nil
138
150
}
139
151
return false , nil
140
152
})
141
153
154
+ t .Log ("Checking for proper RBAC permissions in target namespace" )
155
+ roleList , err := c .KubernetesInterface ().RbacV1 ().ClusterRoles ().List (metav1.ListOptions {})
156
+ for _ , item := range roleList .Items {
157
+ role , err := c .GetClusterRole (item .GetName ())
158
+ require .NoError (t , err )
159
+ switch roleName := item .GetName (); roleName {
160
+ case "owned-crd-manager-another-csv" :
161
+ managerPolicyRules := []rbacv1.PolicyRule {
162
+ rbacv1.PolicyRule {Verbs : []string {"*" }, APIGroups : []string {apiGroup }, Resources : []string {mainCRDPlural }},
163
+ }
164
+ require .Equal (t , managerPolicyRules , role .Rules )
165
+ case "e2e-operator-group-edit" :
166
+ editPolicyRules := []rbacv1.PolicyRule {
167
+ rbacv1.PolicyRule {Verbs : []string {"create" , "update" , "patch" , "delete" }, APIGroups : []string {apiGroup }, Resources : []string {mainCRDPlural }},
168
+ }
169
+ require .Equal (t , editPolicyRules , role .Rules )
170
+ case "e2e-operator-group-view" :
171
+ viewPolicyRules := []rbacv1.PolicyRule {
172
+ rbacv1.PolicyRule {Verbs : []string {"get" , "list" , "watch" }, APIGroups : []string {apiGroup }, Resources : []string {mainCRDPlural }},
173
+ }
174
+ require .Equal (t , viewPolicyRules , role .Rules )
175
+ }
176
+ }
177
+
142
178
t .Log ("Waiting for operator namespace csv to have annotations" )
143
179
err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
144
180
fetchedCSV , fetchErr := crc .OperatorsV1alpha1 ().ClusterServiceVersions (testNamespace ).Get (csvName , metav1.GetOptions {})
@@ -171,8 +207,8 @@ func TestOperatorGroup(t *testing.T) {
171
207
require .NoError (t , err )
172
208
require .EqualValues (t , v1alpha1 .CSVReasonCopied , fetchedCSV .Status .Reason )
173
209
// also check name and spec
174
- require .Equal (t , createdCSV .Name , fetchedCSV .Name )
175
- require .Equal (t , createdCSV .Spec , fetchedCSV .Spec )
210
+ require .EqualValues (t , createdCSV .Name , fetchedCSV .Name )
211
+ require .EqualValues (t , createdCSV .Spec , fetchedCSV .Spec )
176
212
177
213
t .Log ("Waiting on deployment to have correct annotations" )
178
214
err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
@@ -218,6 +254,8 @@ func TestOperatorGroup(t *testing.T) {
218
254
}
219
255
require .NoError (t , err )
220
256
257
+ cleanupCRD ()
258
+
221
259
err = c .KubernetesInterface ().CoreV1 ().Namespaces ().Delete (otherNamespaceName , & metav1.DeleteOptions {})
222
260
require .NoError (t , err )
223
261
err = crc .OperatorsV1alpha2 ().OperatorGroups (testNamespace ).Delete (operatorGroup .Name , & metav1.DeleteOptions {})
0 commit comments