@@ -14,7 +14,6 @@ import (
14
14
"k8s.io/apimachinery/pkg/api/meta"
15
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16
16
"k8s.io/apimachinery/pkg/runtime"
17
- "k8s.io/apimachinery/pkg/types"
18
17
"k8s.io/apimachinery/pkg/util/rand"
19
18
ctrl "sigs.k8s.io/controller-runtime"
20
19
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -39,31 +38,68 @@ func TestExtensionDeveloper(t *testing.T) {
39
38
require .NoError (t , err )
40
39
41
40
ctx := context .Background ()
42
- saName := fmt .Sprintf ("serviceaccounts-%s" , rand .String (8 ))
43
- name := types.NamespacedName {
44
- Name : saName ,
45
- Namespace : "default" ,
41
+
42
+ catalog := & catalogd.ClusterCatalog {
43
+ ObjectMeta : metav1.ObjectMeta {
44
+ GenerateName : "catalog" ,
45
+ },
46
+ Spec : catalogd.ClusterCatalogSpec {
47
+ Source : catalogd.CatalogSource {
48
+ Type : catalogd .SourceTypeImage ,
49
+ Image : & catalogd.ImageSource {
50
+ Ref : os .Getenv ("CATALOG_IMG" ),
51
+ InsecureSkipTLSVerify : true ,
52
+ },
53
+ },
54
+ },
46
55
}
56
+ require .NoError (t , c .Create (context .Background (), catalog ))
57
+
58
+ installNamespace := "default"
47
59
48
60
sa := & corev1.ServiceAccount {
49
61
ObjectMeta : metav1.ObjectMeta {
50
- Name : name . Name ,
51
- Namespace : name . Namespace ,
62
+ Name : fmt . Sprintf ( "serviceaccount-%s" , rand . String ( 8 )) ,
63
+ Namespace : installNamespace ,
52
64
},
53
65
}
54
66
require .NoError (t , c .Create (ctx , sa ))
55
67
68
+ clusterExtension := & ocv1alpha1.ClusterExtension {
69
+ ObjectMeta : metav1.ObjectMeta {
70
+ Name : "registryv1" ,
71
+ },
72
+ Spec : ocv1alpha1.ClusterExtensionSpec {
73
+ PackageName : os .Getenv ("REG_PKG_NAME" ),
74
+ InstallNamespace : installNamespace ,
75
+ ServiceAccount : ocv1alpha1.ServiceAccountReference {
76
+ Name : sa .Name ,
77
+ },
78
+ },
79
+ }
80
+
56
81
cr := & rbacv1.ClusterRole {
57
82
ObjectMeta : metav1.ObjectMeta {
58
- Name : name . Name ,
83
+ Name : fmt . Sprintf ( "clusterrole-%s" , rand . String ( 8 )) ,
59
84
},
60
85
Rules : []rbacv1.PolicyRule {
86
+ {
87
+ APIGroups : []string {
88
+ "olm.operatorframework.io" ,
89
+ },
90
+ Resources : []string {
91
+ "clusterextensions/finalizers" ,
92
+ },
93
+ Verbs : []string {
94
+ "update" ,
95
+ },
96
+ ResourceNames : []string {clusterExtension .Name },
97
+ },
61
98
{
62
99
APIGroups : []string {
63
100
"" ,
64
101
},
65
102
Resources : []string {
66
- "secrets" , // for helm
67
103
"services" ,
68
104
"serviceaccounts" ,
69
105
},
@@ -139,72 +175,36 @@ func TestExtensionDeveloper(t *testing.T) {
139
175
140
176
crb := & rbacv1.ClusterRoleBinding {
141
177
ObjectMeta : metav1.ObjectMeta {
142
- Name : name . Name ,
178
+ Name : fmt . Sprintf ( "clusterrolebinding-%s" , rand . String ( 8 )) ,
143
179
},
144
180
Subjects : []rbacv1.Subject {
145
181
{
146
182
Kind : "ServiceAccount" ,
147
- Name : name .Name ,
148
- Namespace : name .Namespace ,
183
+ Name : sa .Name ,
184
+ Namespace : sa .Namespace ,
149
185
},
150
186
},
151
187
RoleRef : rbacv1.RoleRef {
152
188
APIGroup : "rbac.authorization.k8s.io" ,
153
189
Kind : "ClusterRole" ,
154
- Name : name .Name ,
190
+ Name : cr .Name ,
155
191
},
156
192
}
157
193
require .NoError (t , c .Create (ctx , crb ))
158
194
159
- clusterExtensions := []* ocv1alpha1.ClusterExtension {
160
- {
161
- ObjectMeta : metav1.ObjectMeta {
162
- Name : "registryv1" ,
163
- },
164
- Spec : ocv1alpha1.ClusterExtensionSpec {
165
- PackageName : os .Getenv ("REG_PKG_NAME" ),
166
- InstallNamespace : "default" ,
167
- ServiceAccount : ocv1alpha1.ServiceAccountReference {
168
- Name : saName ,
169
- },
170
- },
171
- },
172
- }
173
-
174
- for _ , ce := range clusterExtensions {
175
- clusterExtension := ce
176
- t .Run (clusterExtension .ObjectMeta .Name , func (t * testing.T ) {
177
- t .Parallel ()
178
- catalog := & catalogd.ClusterCatalog {
179
- ObjectMeta : metav1.ObjectMeta {
180
- GenerateName : "catalog" ,
181
- },
182
- Spec : catalogd.ClusterCatalogSpec {
183
- Source : catalogd.CatalogSource {
184
- Type : catalogd .SourceTypeImage ,
185
- Image : & catalogd.ImageSource {
186
- Ref : os .Getenv ("CATALOG_IMG" ),
187
- InsecureSkipTLSVerify : true ,
188
- },
189
- },
190
- },
191
- }
192
- t .Logf ("When creating an ClusterExtension that references a package with a %q bundle type" , clusterExtension .ObjectMeta .Name )
193
- require .NoError (t , c .Create (context .Background (), catalog ))
194
- require .NoError (t , c .Create (context .Background (), clusterExtension ))
195
- t .Log ("It should have a status condition type of Installed with a status of True and a reason of Success" )
196
- require .EventuallyWithT (t , func (ct * assert.CollectT ) {
197
- ext := & ocv1alpha1.ClusterExtension {}
198
- assert .NoError (ct , c .Get (context .Background (), client .ObjectKeyFromObject (clusterExtension ), ext ))
199
- cond := meta .FindStatusCondition (ext .Status .Conditions , ocv1alpha1 .TypeInstalled )
200
- if ! assert .NotNil (ct , cond ) {
201
- return
202
- }
203
- assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
204
- assert .Equal (ct , ocv1alpha1 .ReasonSuccess , cond .Reason )
205
- }, 2 * time .Minute , time .Second )
206
- require .NoError (t , c .Delete (context .Background (), catalog ))
207
- require .NoError (t , c .Delete (context .Background (), clusterExtension ))
208
- })
209
- }
195
+ t .Logf ("When creating an ClusterExtension that references a package with a %q bundle type" , clusterExtension .ObjectMeta .Name )
196
+ require .NoError (t , c .Create (context .Background (), clusterExtension ))
197
+ t .Log ("It should have a status condition type of Installed with a status of True and a reason of Success" )
198
+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
199
+ ext := & ocv1alpha1.ClusterExtension {}
200
+ assert .NoError (ct , c .Get (context .Background (), client .ObjectKeyFromObject (clusterExtension ), ext ))
201
+ cond := meta .FindStatusCondition (ext .Status .Conditions , ocv1alpha1 .TypeInstalled )
202
+ if ! assert .NotNil (ct , cond ) {
203
+ return
204
+ }
205
+ assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
206
+ assert .Equal (ct , ocv1alpha1 .ReasonSuccess , cond .Reason )
207
+ }, 2 * time .Minute , time .Second )
208
+ require .NoError (t , c .Delete (context .Background (), catalog ))
209
+ require .NoError (t , c .Delete (context .Background (), clusterExtension ))
210
210
}
0 commit comments