@@ -33,14 +33,20 @@ import (
33
33
var _ = Describe ("Metrics are generated for OLM managed resources" , func () {
34
34
35
35
var (
36
- c operatorclient.ClientInterface
37
- crc versioned.Interface
36
+ c operatorclient.ClientInterface
37
+ crc versioned.Interface
38
+ generatedNamespace corev1.Namespace
38
39
)
39
40
40
41
BeforeEach (func () {
41
42
c = newKubeClient ()
42
43
crc = newCRClient ()
44
+ namespaceName := genName ("metrics-e2e-" )
45
+ generatedNamespace = SetupGeneratedTestNamespace (namespaceName , namespaceName )
46
+ })
43
47
48
+ AfterEach (func () {
49
+ TeardownNamespace (generatedNamespace .GetName ())
44
50
})
45
51
46
52
Context ("Given an OperatorGroup that supports all namespaces" , func () {
@@ -74,10 +80,10 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
74
80
}
75
81
76
82
var err error
77
- cleanupCSV , err = createCSV (c , crc , failingCSV , testNamespace , false , false )
83
+ cleanupCSV , err = createCSV (c , crc , failingCSV , generatedNamespace . GetName () , false , false )
78
84
Expect (err ).ToNot (HaveOccurred ())
79
85
80
- _ , err = fetchCSV (crc , failingCSV .Name , testNamespace , csvFailedChecker )
86
+ _ , err = fetchCSV (crc , failingCSV .Name , generatedNamespace . GetName () , csvFailedChecker )
81
87
Expect (err ).ToNot (HaveOccurred ())
82
88
})
83
89
@@ -127,12 +133,12 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
127
133
BeforeEach (func () {
128
134
packageName := genName ("csv-test-" )
129
135
packageStable := fmt .Sprintf ("%s-stable" , packageName )
130
- csv = newCSV (packageStable , testNamespace , "" , semver .MustParse ("0.1.0" ), nil , nil , nil )
136
+ csv = newCSV (packageStable , generatedNamespace . GetName () , "" , semver .MustParse ("0.1.0" ), nil , nil , nil )
131
137
132
138
var err error
133
- _ , err = createCSV (c , crc , csv , testNamespace , false , false )
139
+ _ , err = createCSV (c , crc , csv , generatedNamespace . GetName () , false , false )
134
140
Expect (err ).ToNot (HaveOccurred ())
135
- _ , err = fetchCSV (crc , csv .Name , testNamespace , csvSucceededChecker )
141
+ _ , err = fetchCSV (crc , csv .Name , generatedNamespace . GetName () , csvSucceededChecker )
136
142
Expect (err ).ToNot (HaveOccurred ())
137
143
})
138
144
AfterEach (func () {
@@ -170,7 +176,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
170
176
171
177
When ("A subscription object is created" , func () {
172
178
BeforeEach (func () {
173
- subscriptionCleanup , _ = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-create" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
179
+ subscriptionCleanup , _ = createSubscription (GinkgoT (), crc , generatedNamespace . GetName () , "metric-subscription-for-create" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
174
180
})
175
181
176
182
AfterEach (func () {
@@ -211,17 +217,17 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
211
217
When ("A subscription object is updated after emitting metrics" , func () {
212
218
213
219
BeforeEach (func () {
214
- subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-update" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
220
+ subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , generatedNamespace . GetName () , "metric-subscription-for-update" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
215
221
Eventually (func () []Metric {
216
222
return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
217
223
}).Should (ContainElement (LikeMetric (WithFamily ("subscription_sync_total" ), WithLabel ("name" , "metric-subscription-for-update" ))))
218
224
Eventually (func () error {
219
- s , err := crc .OperatorsV1alpha1 ().Subscriptions (subscription .GetNamespace ()).Get (context .TODO (), subscription .GetName (), metav1.GetOptions {})
225
+ s , err := crc .OperatorsV1alpha1 ().Subscriptions (subscription .GetNamespace ()).Get (context .Background (), subscription .GetName (), metav1.GetOptions {})
220
226
if err != nil {
221
227
return err
222
228
}
223
229
s .Spec .Channel = betaChannel
224
- _ , err = crc .OperatorsV1alpha1 ().Subscriptions (s .GetNamespace ()).Update (context .TODO (), s , metav1.UpdateOptions {})
230
+ _ , err = crc .OperatorsV1alpha1 ().Subscriptions (s .GetNamespace ()).Update (context .Background (), s , metav1.UpdateOptions {})
225
231
return err
226
232
}).Should (Succeed ())
227
233
})
@@ -256,12 +262,12 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
256
262
257
263
BeforeEach (func () {
258
264
Eventually (func () error {
259
- s , err := crc .OperatorsV1alpha1 ().Subscriptions (subscription .GetNamespace ()).Get (context .TODO (), subscription .GetName (), metav1.GetOptions {})
265
+ s , err := crc .OperatorsV1alpha1 ().Subscriptions (subscription .GetNamespace ()).Get (context .Background (), subscription .GetName (), metav1.GetOptions {})
260
266
if err != nil {
261
267
return err
262
268
}
263
269
s .Spec .Channel = alphaChannel
264
- _ , err = crc .OperatorsV1alpha1 ().Subscriptions (s .GetNamespace ()).Update (context .TODO (), s , metav1.UpdateOptions {})
270
+ _ , err = crc .OperatorsV1alpha1 ().Subscriptions (s .GetNamespace ()).Update (context .Background (), s , metav1.UpdateOptions {})
265
271
return err
266
272
}).Should (Succeed ())
267
273
})
@@ -296,7 +302,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
296
302
When ("A subscription object is deleted after emitting metrics" , func () {
297
303
298
304
BeforeEach (func () {
299
- subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , testNamespace , "metric-subscription-for-delete" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
305
+ subscriptionCleanup , subscription = createSubscription (GinkgoT (), crc , generatedNamespace . GetName () , "metric-subscription-for-delete" , testPackageName , stableChannel , v1alpha1 .ApprovalManual )
300
306
Eventually (func () []Metric {
301
307
return getMetricsFromPod (c , getPodWithLabel (c , "app=catalog-operator" ))
302
308
}).Should (ContainElement (LikeMetric (WithFamily ("subscription_sync_total" ), WithLabel ("name" , "metric-subscription-for-delete" ))))
@@ -334,7 +340,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
334
340
stableChannel := "stable"
335
341
336
342
mainCRD := newCRD (genName ("ins-" ))
337
- mainCSV := newCSV (mainPackageStable , testNamespace , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {mainCRD }, nil , nil )
343
+ mainCSV := newCSV (mainPackageStable , generatedNamespace . GetName () , "" , semver .MustParse ("0.1.0" ), []apiextensions.CustomResourceDefinition {mainCRD }, nil , nil )
338
344
339
345
mainManifests := []registry.PackageManifest {
340
346
{
@@ -345,7 +351,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
345
351
DefaultChannelName : stableChannel ,
346
352
},
347
353
}
348
- cs , cleanupAll := createInternalCatalogSource (c , crc , name , testNamespace , mainManifests , []apiextensions.CustomResourceDefinition {mainCRD }, []v1alpha1.ClusterServiceVersion {mainCSV })
354
+ cs , cleanupAll := createInternalCatalogSource (c , crc , name , generatedNamespace . GetName () , mainManifests , []apiextensions.CustomResourceDefinition {mainCRD }, []v1alpha1.ClusterServiceVersion {mainCSV })
349
355
// Note(tflannag): Dependending on how ginkgo orders these test specs, and how bloated the cluster we're running
350
356
// this test case against, we risk creating and then immediately deleting the catalogsource before the catalog
351
357
// operator can generate all the requisite resources (e.g. the ServiceAccount), which can leave the underlying
@@ -373,7 +379,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
373
379
ContainElement (LikeMetric (
374
380
WithFamily ("catalogsource_ready" ),
375
381
WithName (name ),
376
- WithNamespace (testNamespace ),
382
+ WithNamespace (generatedNamespace . GetName () ),
377
383
WithValue (1 ),
378
384
)),
379
385
))
@@ -389,7 +395,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
389
395
Not (ContainElement (LikeMetric (
390
396
WithFamily ("catalogsource_ready" ),
391
397
WithName (name ),
392
- WithNamespace (testNamespace ),
398
+ WithNamespace (generatedNamespace . GetName () ),
393
399
)))))
394
400
})
395
401
})
@@ -401,7 +407,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
401
407
cleanup func ()
402
408
)
403
409
BeforeEach (func () {
404
- _ , cleanup = createInvalidGRPCCatalogSource (crc , name , testNamespace )
410
+ _ , cleanup = createInvalidGRPCCatalogSource (crc , name , generatedNamespace . GetName () )
405
411
})
406
412
AfterEach (func () {
407
413
cleanup ()
@@ -413,7 +419,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
413
419
ContainElement (LikeMetric (
414
420
WithFamily ("catalogsource_ready" ),
415
421
WithName (name ),
416
- WithNamespace (testNamespace ),
422
+ WithNamespace (generatedNamespace . GetName () ),
417
423
WithValue (0 ),
418
424
)),
419
425
))
@@ -423,7 +429,7 @@ var _ = Describe("Metrics are generated for OLM managed resources", func() {
423
429
ContainElement (LikeMetric (
424
430
WithFamily ("catalogsource_ready" ),
425
431
WithName (name ),
426
- WithNamespace (testNamespace ),
432
+ WithNamespace (generatedNamespace . GetName () ),
427
433
WithValue (0 ),
428
434
)),
429
435
))
@@ -436,7 +442,7 @@ func getPodWithLabel(client operatorclient.ClientInterface, label string) *corev
436
442
listOptions := metav1.ListOptions {LabelSelector : label }
437
443
var podList * corev1.PodList
438
444
EventuallyWithOffset (1 , func () (numPods int , err error ) {
439
- podList , err = client .KubernetesInterface ().CoreV1 ().Pods (operatorNamespace ).List (context .TODO (), listOptions )
445
+ podList , err = client .KubernetesInterface ().CoreV1 ().Pods (operatorNamespace ).List (context .Background (), listOptions )
440
446
if podList != nil {
441
447
numPods = len (podList .Items )
442
448
}
@@ -451,7 +457,7 @@ func getDeploymentWithLabel(client operatorclient.ClientInterface, label string)
451
457
listOptions := metav1.ListOptions {LabelSelector : label }
452
458
var deploymentList * appsv1.DeploymentList
453
459
EventuallyWithOffset (1 , func () (numDeps int , err error ) {
454
- deploymentList , err = client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).List (context .TODO (), listOptions )
460
+ deploymentList , err = client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).List (context .Background (), listOptions )
455
461
if deploymentList != nil {
456
462
numDeps = len (deploymentList .Items )
457
463
}
@@ -467,11 +473,11 @@ func restartDeploymentWithLabel(client operatorclient.ClientInterface, l string)
467
473
z := int32 (0 )
468
474
oldZ := * d .Spec .Replicas
469
475
d .Spec .Replicas = & z
470
- _ , err := client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Update (context .TODO (), d , metav1.UpdateOptions {})
476
+ _ , err := client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Update (context .Background (), d , metav1.UpdateOptions {})
471
477
Expect (err ).ToNot (HaveOccurred ())
472
478
473
479
EventuallyWithOffset (1 , func () (replicas int32 , err error ) {
474
- deployment , err := client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Get (context .TODO (), d .Name , metav1.GetOptions {})
480
+ deployment , err := client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Get (context .Background (), d .Name , metav1.GetOptions {})
475
481
if deployment != nil {
476
482
replicas = deployment .Status .Replicas
477
483
}
@@ -480,11 +486,11 @@ func restartDeploymentWithLabel(client operatorclient.ClientInterface, l string)
480
486
481
487
updated := getDeploymentWithLabel (client , l )
482
488
updated .Spec .Replicas = & oldZ
483
- _ , err = client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Update (context .TODO (), updated , metav1.UpdateOptions {})
489
+ _ , err = client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Update (context .Background (), updated , metav1.UpdateOptions {})
484
490
Expect (err ).ToNot (HaveOccurred ())
485
491
486
492
EventuallyWithOffset (1 , func () (replicas int32 , err error ) {
487
- deployment , err := client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Get (context .TODO (), d .Name , metav1.GetOptions {})
493
+ deployment , err := client .KubernetesInterface ().AppsV1 ().Deployments (operatorNamespace ).Get (context .Background (), d .Name , metav1.GetOptions {})
488
494
if deployment != nil {
489
495
replicas = deployment .Status .Replicas
490
496
}
0 commit comments