@@ -28,7 +28,7 @@ import (
28
28
)
29
29
30
30
// Describes test specs for the Operator resource.
31
- var _ = Describe ("Operator" , func () {
31
+ var _ = Describe ("Operator API " , func () {
32
32
var (
33
33
clientCtx context.Context
34
34
scheme * runtime.Scheme
@@ -74,6 +74,8 @@ var _ = Describe("Operator", func() {
74
74
o := & operatorsv1.Operator {}
75
75
o .SetName (genName ("o-" ))
76
76
77
+ Consistently (o ).ShouldNot (ContainCopiedCSVReferences ())
78
+
77
79
Eventually (func () error {
78
80
return client .Create (clientCtx , o )
79
81
}).Should (Succeed ())
@@ -327,6 +329,12 @@ var _ = Describe("Operator", func() {
327
329
})
328
330
329
331
It ("should automatically adopt components" , func () {
332
+ Consistently (func () (* operatorsv1.Operator , error ) {
333
+ o := & operatorsv1.Operator {}
334
+ err := client .Get (clientCtx , operatorName , o )
335
+ return o , err
336
+ }).ShouldNot (ContainCopiedCSVReferences ())
337
+
330
338
Eventually (func () (* operatorsv1.Operator , error ) {
331
339
o := & operatorsv1.Operator {}
332
340
err := client .Get (clientCtx , operatorName , o )
@@ -346,8 +354,36 @@ var _ = Describe("Operator", func() {
346
354
getReference (scheme , testobj .WithName ("monitoringdashboards.monitoring.kiali.io" , & apiextensionsv1.CustomResourceDefinition {})),
347
355
}))
348
356
})
349
- })
350
357
358
+ Context ("when a namespace is added" , func () {
359
+ var newNs * corev1.Namespace
360
+
361
+ BeforeEach (func () {
362
+ // Subscribe to a package and await a successful install
363
+ newNs = & corev1.Namespace {}
364
+ newNs .SetName (genName ("ns-" ))
365
+ Eventually (func () error {
366
+ return client .Create (clientCtx , newNs )
367
+ }).Should (Succeed ())
368
+ })
369
+ AfterEach (func () {
370
+ Eventually (func () error {
371
+ err := client .Delete (clientCtx , newNs )
372
+ if apierrors .IsNotFound (err ) {
373
+ return nil
374
+ }
375
+ return err
376
+ }).Should (Succeed ())
377
+ })
378
+ It ("should not adopt copied csvs" , func () {
379
+ Consistently (func () (* operatorsv1.Operator , error ) {
380
+ o := & operatorsv1.Operator {}
381
+ err := client .Get (clientCtx , operatorName , o )
382
+ return o , err
383
+ }).ShouldNot (ContainCopiedCSVReferences ())
384
+ })
385
+ })
386
+ })
351
387
})
352
388
353
389
func getReference (scheme * runtime.Scheme , obj runtime.Object ) * corev1.ObjectReference {
@@ -380,6 +416,53 @@ func componentRefEventuallyExists(w watch.Interface, exists bool, ref *corev1.Ob
380
416
}))
381
417
}
382
418
419
+ func ContainCopiedCSVReferences () gomegatypes.GomegaMatcher {
420
+ return & copiedCSVRefMatcher {}
421
+ }
422
+
423
+ type copiedCSVRefMatcher struct {
424
+ }
425
+
426
+ func (matcher * copiedCSVRefMatcher ) Match (actual interface {}) (success bool , err error ) {
427
+ if actual == nil {
428
+ return false , nil
429
+ }
430
+ operator , ok := actual .(* operatorsv1.Operator )
431
+ if ! ok {
432
+ return false , fmt .Errorf ("copiedCSVRefMatcher matcher expects an *Operator" )
433
+ }
434
+ if operator .Status .Components == nil {
435
+ return false , nil
436
+ }
437
+ for _ , ref := range operator .Status .Components .Refs {
438
+ if ref .Kind != operatorsv1alpha1 .ClusterServiceVersionKind {
439
+ continue
440
+ }
441
+ for _ , c := range ref .Conditions {
442
+ if c .Reason == string (operatorsv1alpha1 .CSVReasonCopied ) {
443
+ return true , nil
444
+ }
445
+ }
446
+ }
447
+ return false , nil
448
+ }
449
+
450
+ func (matcher * copiedCSVRefMatcher ) FailureMessage (actual interface {}) (message string ) {
451
+ operator , ok := actual .(* operatorsv1.Operator )
452
+ if ! ok {
453
+ return fmt .Sprintf ("copiedCSVRefMatcher matcher expects an *Operator" )
454
+ }
455
+ return fmt .Sprintf ("Expected\n \t %#v\n to contain copied CSVs in components\n \t %#v\n " , operator , operator .Status .Components )
456
+ }
457
+
458
+ func (matcher * copiedCSVRefMatcher ) NegatedFailureMessage (actual interface {}) (message string ) {
459
+ operator , ok := actual .(* operatorsv1.Operator )
460
+ if ! ok {
461
+ return fmt .Sprintf ("copiedCSVRefMatcher matcher expects an *Operator" )
462
+ }
463
+ return fmt .Sprintf ("Expected\n \t %#v\n to not contain copied CSVs in components\n \t %#v\n " , operator , operator .Status .Components )
464
+ }
465
+
383
466
func operatorPredicate (fn func (* operatorsv1.Operator ) bool ) predicateFunc {
384
467
return func (event watch.Event ) bool {
385
468
o , ok := event .Object .(* operatorsv1.Operator )
0 commit comments