Skip to content

Commit 5b2df84

Browse files
committed
test that the operator api never adopts copied CSVs
Signed-off-by: Evan Cordell <[email protected]>
1 parent c7bc438 commit 5b2df84

File tree

2 files changed

+86
-3
lines changed

2 files changed

+86
-3
lines changed

pkg/controller/operators/operatorcondition_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ var _ = Describe("OperatorCondition", func() {
250250
}
251251
Expect(k8sClient.Create(ctx, operatorCondition)).To(Succeed())
252252
})
253-
It("does not injected the OperatorCondition name into the deployment's Environment Variables", func() {
253+
It("does not inject the OperatorCondition name into the deployment's Environment Variables", func() {
254254
deployment := &appsv1.Deployment{}
255255
Consistently(func() error {
256256
err := k8sClient.Get(ctx, types.NamespacedName{Name: operatorCondition.Spec.Deployments[0], Namespace: namespace.GetName()}, deployment)

test/e2e/operator_test.go

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
)
2929

3030
// Describes test specs for the Operator resource.
31-
var _ = Describe("Operator", func() {
31+
var _ = Describe("Operator API", func() {
3232
var (
3333
clientCtx context.Context
3434
scheme *runtime.Scheme
@@ -74,6 +74,8 @@ var _ = Describe("Operator", func() {
7474
o := &operatorsv1.Operator{}
7575
o.SetName(genName("o-"))
7676

77+
Consistently(o).ShouldNot(ContainCopiedCSVReferences())
78+
7779
Eventually(func() error {
7880
return client.Create(clientCtx, o)
7981
}).Should(Succeed())
@@ -327,6 +329,12 @@ var _ = Describe("Operator", func() {
327329
})
328330

329331
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+
330338
Eventually(func() (*operatorsv1.Operator, error) {
331339
o := &operatorsv1.Operator{}
332340
err := client.Get(clientCtx, operatorName, o)
@@ -346,8 +354,36 @@ var _ = Describe("Operator", func() {
346354
getReference(scheme, testobj.WithName("monitoringdashboards.monitoring.kiali.io", &apiextensionsv1.CustomResourceDefinition{})),
347355
}))
348356
})
349-
})
350357

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+
})
351387
})
352388

353389
func getReference(scheme *runtime.Scheme, obj runtime.Object) *corev1.ObjectReference {
@@ -380,6 +416,53 @@ func componentRefEventuallyExists(w watch.Interface, exists bool, ref *corev1.Ob
380416
}))
381417
}
382418

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\nto 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\nto not contain copied CSVs in components\n\t%#v\n", operator, operator.Status.Components)
464+
}
465+
383466
func operatorPredicate(fn func(*operatorsv1.Operator) bool) predicateFunc {
384467
return func(event watch.Event) bool {
385468
o, ok := event.Object.(*operatorsv1.Operator)

0 commit comments

Comments
 (0)