@@ -77,7 +77,7 @@ func checkOperatorGroupAnnotations(obj metav1.Object, op *v1alpha2.OperatorGroup
77
77
return nil
78
78
}
79
79
80
- func TestCreateOperatorGroupWithMatchingNamespace (t * testing.T ) {
80
+ func TestOperatorGroup (t * testing.T ) {
81
81
// Create namespace with specific label
82
82
// Create CSV in operator namespace
83
83
// Create operator group that watches namespace and uses specific label
@@ -89,7 +89,7 @@ func TestCreateOperatorGroupWithMatchingNamespace(t *testing.T) {
89
89
log .SetLevel (log .DebugLevel )
90
90
c := newKubeClient (t )
91
91
crc := newCRClient (t )
92
- csvName := "another-csv"
92
+ csvName := "another-csv" // must be lowercase for DNS-1123 validation
93
93
94
94
matchingLabel := map [string ]string {"matchLabel" : testNamespace }
95
95
otherNamespaceName := testNamespace + "-namespace-two"
@@ -107,45 +107,9 @@ func TestCreateOperatorGroupWithMatchingNamespace(t *testing.T) {
107
107
108
108
log .Debug ("Creating CSV" )
109
109
aCSV := newCSV (csvName , testNamespace , "" , * semver .New ("0.0.0" ), nil , nil , newNginxInstallStrategy ("operator-deployment" , nil , nil ))
110
- _ , err = crc .OperatorsV1alpha1 ().ClusterServiceVersions (testNamespace ).Create (& aCSV )
110
+ createdCSV , err : = crc .OperatorsV1alpha1 ().ClusterServiceVersions (testNamespace ).Create (& aCSV )
111
111
require .NoError (t , err )
112
112
113
- // var one = int32(1)
114
- // deployment := appsv1.Deployment{
115
- // ObjectMeta: metav1.ObjectMeta{
116
- // Name: "operator-deployment",
117
- // Namespace: testNamespace,
118
- // },
119
- // Spec: appsv1.DeploymentSpec{
120
- // Selector: &metav1.LabelSelector{
121
- // MatchLabels: matchingLabel,
122
- // },
123
- // Replicas: &one,
124
- // Template: corev1.PodTemplateSpec{
125
- // ObjectMeta: metav1.ObjectMeta{
126
- // Labels: matchingLabel,
127
- // },
128
- // Spec: corev1.PodSpec{Containers: []corev1.Container{
129
- // {
130
- // Name: genName("nginx"),
131
- // Image: "nginx:1.7.9",
132
- // Ports: []corev1.ContainerPort{{ContainerPort: 80}},
133
- // },
134
- // }},
135
- // },
136
- // },
137
- // }
138
- // deployment.SetOwnerReferences([]metav1.OwnerReference{
139
- // {
140
- // Kind: "ClusterServiceVersion",
141
- // Name: "fake-csv",
142
- // },
143
- // })
144
-
145
- // log.Debug("Creating deployment")
146
- // createdDeployment, err := c.CreateDeployment(&deployment)
147
- // require.NoError(t, err)
148
-
149
113
log .Debug ("Creating operator group" )
150
114
operatorGroup := v1alpha2.OperatorGroup {
151
115
ObjectMeta : metav1.ObjectMeta {
@@ -205,112 +169,38 @@ func TestCreateOperatorGroupWithMatchingNamespace(t *testing.T) {
205
169
return false , nil
206
170
})
207
171
// since annotations are set along with status, no reason to poll for this check as done above
208
- log .Debug ("Checking status on CSV in target namespace" )
172
+ log .Debug ("Checking status on csv in target namespace" )
209
173
fetchedCSV , err := crc .OperatorsV1alpha1 ().ClusterServiceVersions (otherNamespaceName ).Get (csvName , metav1.GetOptions {})
210
174
require .NoError (t , err )
211
175
require .EqualValues (t , v1alpha1 .CSVReasonCopied , fetchedCSV .Status .Reason )
176
+ // also check name and spec
177
+ require .Equal (t , createdCSV .Name , fetchedCSV .Name )
178
+ require .Equal (t , createdCSV .Spec , fetchedCSV .Spec )
212
179
213
- //log.Debug("Waiting on deployment to have correct annotation")
214
- //err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
215
- // createdDeployment, err := c.GetDeployment(testNamespace, "operator-deployment")
216
- // if err != nil {
217
- // if errors.IsNotFound(err) {
218
- // return false, nil
219
- // }
220
- // return false, err
221
- // }
222
- // // TODO: verify operatorNamespace annotation, operatorGroup annotation
223
- // if createdDeployment.Spec.Template.Annotations["olm.targetNamespaces"] == otherNamespaceName {
224
- // return true, nil
225
- // }
226
- // return false, nil
227
- //})
228
-
229
- // clean up
230
- // TODO: unpatch function
231
- runningDeploy , err := c .GetDeployment (testNamespace , "olm-operator" )
232
- require .NoError (t , err )
233
- runningDeploy .Spec .Template .Spec .Containers [0 ].Command = oldCommand
234
- _ , updated , err := c .UpdateDeployment (runningDeploy )
235
- if err != nil || updated == false {
236
- t .Fatalf ("Deployment update failed: (updated %v) %v\n " , updated , err )
237
- }
238
- require .NoError (t , err )
239
-
240
- err = c .KubernetesInterface ().CoreV1 ().Namespaces ().Delete (otherNamespaceName , & metav1.DeleteOptions {})
241
- require .NoError (t , err )
242
- err = crc .OperatorsV1alpha2 ().OperatorGroups (testNamespace ).Delete (operatorGroup .Name , & metav1.DeleteOptions {})
243
- require .NoError (t , err )
244
- }
245
-
246
- func TestCreateOperatorGroupCSVCopy (t * testing.T ) {
247
- // create target namespace
248
- // create operator group in OLM namespace, which serves as operator namespace
249
- // create CSV in OLM namespace
250
- // verify CSV is copied to target namespace
251
-
252
- log .SetLevel (log .DebugLevel )
253
- c := newKubeClient (t )
254
- crc := newCRClient (t )
255
- targetNamespaceName := testNamespace + "-target"
256
- csvName := "acsv-that-is-unique" // must be lowercase for DNS-1123 validation
257
- matchingLabel := map [string ]string {"matchLabel" : testNamespace }
258
-
259
- log .Debug ("Creating operator namespace" )
260
- targetNamespace := corev1.Namespace {
261
- ObjectMeta : metav1.ObjectMeta {
262
- Name : targetNamespaceName ,
263
- Labels : matchingLabel ,
264
- },
265
- }
266
- _ , err := c .KubernetesInterface ().CoreV1 ().Namespaces ().Create (& targetNamespace )
267
- require .NoError (t , err )
268
-
269
- oldCommand := patchOlmDeployment (t , c , targetNamespaceName )
270
-
271
- log .Debug ("Creating operator group" )
272
- operatorGroup := v1alpha2.OperatorGroup {
273
- ObjectMeta : metav1.ObjectMeta {
274
- Name : "e2e-operator-group" ,
275
- Namespace : testNamespace ,
276
- },
277
- Spec : v1alpha2.OperatorGroupSpec {
278
- Selector : metav1.LabelSelector {
279
- MatchLabels : matchingLabel ,
280
- },
281
- },
282
- }
283
- _ , err = crc .OperatorsV1alpha2 ().OperatorGroups (testNamespace ).Create (& operatorGroup )
284
- require .NoError (t , err )
285
-
286
- log .Debug ("Creating CSV" )
287
- aCSV := newCSV (csvName , testNamespace , "" , * semver .New ("0.0.0" ), nil , nil , newNginxInstallStrategy ("aspec" , nil , nil ))
288
- createdCSV , err := crc .OperatorsV1alpha1 ().ClusterServiceVersions (testNamespace ).Create (& aCSV )
289
- require .NoError (t , err )
290
-
291
- log .Debug ("Waiting for CSV copy to have correct properties" )
292
- var csvCopy * v1alpha1.ClusterServiceVersion
180
+ log .Debug ("Waiting on deployment to have correct annotation" )
293
181
err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
294
- csvCopy , err = crc . OperatorsV1alpha1 (). ClusterServiceVersions ( targetNamespaceName ). Get ( csvName , metav1. GetOptions {} )
182
+ createdDeployment , err := c . GetDeployment ( testNamespace , "operator-deployment" )
295
183
if err != nil {
296
184
if errors .IsNotFound (err ) {
297
185
return false , nil
298
186
}
299
187
return false , err
300
188
}
301
- return true , nil
189
+ // TODO: verify operatorNamespace annotation, operatorGroup annotation
190
+ if createdDeployment .Spec .Template .Annotations ["olm.targetNamespaces" ] == otherNamespaceName {
191
+ return true , nil
192
+ }
193
+ return false , nil
302
194
})
303
- require .Equal (t , createdCSV .Name , csvCopy .Name )
304
- require .Equal (t , createdCSV .Spec , csvCopy .Spec )
305
195
306
- // part 2 - ensure deletion cleans up copied CSV
196
+ // ensure deletion cleans up copied CSV
307
197
log .Debug ("Deleting CSV" )
308
198
err = crc .OperatorsV1alpha1 ().ClusterServiceVersions (testNamespace ).Delete (csvName , & metav1.DeleteOptions {})
309
199
require .NoError (t , err )
310
200
311
201
log .Debug ("Waiting for orphaned CSV to be deleted" )
312
202
err = wait .Poll (pollInterval , pollDuration , func () (bool , error ) {
313
- csvCopy , err = crc .OperatorsV1alpha1 ().ClusterServiceVersions (targetNamespaceName ).Get (csvName , metav1.GetOptions {})
203
+ _ , err = crc .OperatorsV1alpha1 ().ClusterServiceVersions (otherNamespaceName ).Get (csvName , metav1.GetOptions {})
314
204
if err != nil {
315
205
if errors .IsNotFound (err ) {
316
206
return true , nil
@@ -322,6 +212,7 @@ func TestCreateOperatorGroupCSVCopy(t *testing.T) {
322
212
require .NoError (t , err )
323
213
324
214
// clean up
215
+ // TODO: unpatch function
325
216
runningDeploy , err := c .GetDeployment (testNamespace , "olm-operator" )
326
217
require .NoError (t , err )
327
218
runningDeploy .Spec .Template .Spec .Containers [0 ].Command = oldCommand
@@ -331,7 +222,7 @@ func TestCreateOperatorGroupCSVCopy(t *testing.T) {
331
222
}
332
223
require .NoError (t , err )
333
224
334
- err = c .KubernetesInterface ().CoreV1 ().Namespaces ().Delete (targetNamespaceName , & metav1.DeleteOptions {})
225
+ err = c .KubernetesInterface ().CoreV1 ().Namespaces ().Delete (otherNamespaceName , & metav1.DeleteOptions {})
335
226
require .NoError (t , err )
336
227
err = crc .OperatorsV1alpha2 ().OperatorGroups (testNamespace ).Delete (operatorGroup .Name , & metav1.DeleteOptions {})
337
228
require .NoError (t , err )
0 commit comments