Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 39 additions & 18 deletions test/e2e/csv_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,25 @@ var _ = Describe("ClusterServiceVersion", func() {
var (
ns corev1.Namespace
crd apiextensionsv1.CustomResourceDefinition
og operatorsv1.OperatorGroup
apiname string
apifullname string
)

BeforeEach(func() {
ns = corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "test-namespace-1",
Name: genName("test-namespace-"),
},
}

Eventually(func() error {
return ctx.Ctx().Client().Create(context.Background(), &ns)
}).Should(Succeed())

og := operatorsv1.OperatorGroup{
og = operatorsv1.OperatorGroup{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-operatorgroup", ns.GetName()),
Name: genName(fmt.Sprintf("%s-operatorgroup-", ns.GetName())),
Namespace: ns.GetName(),
},
Spec: operatorsv1.OperatorGroupSpec{
Expand All @@ -90,9 +94,11 @@ var _ = Describe("ClusterServiceVersion", func() {
return ctx.Ctx().Client().Create(context.Background(), &og)
}).Should(Succeed())

apiname = genName("api")
apifullname = apiname + "s.example.com"
crd = apiextensionsv1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: "tests.example.com",
Name: apifullname,
Annotations: map[string]string{
"operatorframework.io/installed-alongside-0": fmt.Sprintf("%s/associated-csv", ns.GetName()),
},
Expand All @@ -101,10 +107,10 @@ var _ = Describe("ClusterServiceVersion", func() {
Group: "example.com",
Scope: apiextensionsv1.ClusterScoped,
Names: apiextensionsv1.CustomResourceDefinitionNames{
Plural: "tests",
Singular: "test",
Kind: "Test",
ListKind: "TestList",
Plural: apiname + "s",
Singular: apiname,
Kind: strings.Title(apiname),
ListKind: strings.Title(apiname) + "List",
},
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{{
Name: "v1",
Expand All @@ -125,11 +131,15 @@ var _ = Describe("ClusterServiceVersion", func() {

AfterEach(func() {
Eventually(func() error {
return ctx.Ctx().Client().Delete(context.Background(), &ns)
return ctx.Ctx().Client().Delete(context.Background(), &crd)
}).Should(WithTransform(k8serrors.IsNotFound, BeTrue()))

Eventually(func() error {
return ctx.Ctx().Client().Delete(context.Background(), &crd)
return ctx.Ctx().Client().Delete(context.Background(), &og)
}).Should(WithTransform(k8serrors.IsNotFound, BeTrue()))

Eventually(func() error {
return ctx.Ctx().Client().Delete(context.Background(), &ns)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this call is still prone to the previous behavior, but deleting the OG and CRD beforehand should smooth out the time that the namespace is hanging in the terminating status (on top of reducing the current flakiness of this test), and I don't have any better solutions poking around the code.

}).Should(WithTransform(k8serrors.IsNotFound, BeTrue()))
})

Expand All @@ -142,7 +152,7 @@ var _ = Describe("ClusterServiceVersion", func() {
Spec: operatorsv1alpha1.ClusterServiceVersionSpec{
CustomResourceDefinitions: operatorsv1alpha1.CustomResourceDefinitions{
Owned: []operatorsv1alpha1.CRDDescription{{
Name: "tests.example.com",
Name: apifullname,
Version: "v1",
Kind: "Test",
}},
Expand Down Expand Up @@ -182,6 +192,10 @@ var _ = Describe("ClusterServiceVersion", func() {
Status: operatorsv1alpha1.RequirementStatusReasonPresent,
},
))

Eventually(func() error {
return ctx.Ctx().Client().Delete(context.Background(), &associated)
}).Should(Succeed())
})

// Without this exception, upgrades can become blocked
Expand All @@ -196,7 +210,7 @@ var _ = Describe("ClusterServiceVersion", func() {
Spec: operatorsv1alpha1.ClusterServiceVersionSpec{
CustomResourceDefinitions: operatorsv1alpha1.CustomResourceDefinitions{
Owned: []operatorsv1alpha1.CRDDescription{{
Name: "tests.example.com",
Name: apifullname,
Version: "v1",
Kind: "Test",
}},
Expand All @@ -220,7 +234,7 @@ var _ = Describe("ClusterServiceVersion", func() {
Spec: operatorsv1alpha1.ClusterServiceVersionSpec{
CustomResourceDefinitions: operatorsv1alpha1.CustomResourceDefinitions{
Owned: []operatorsv1alpha1.CRDDescription{{
Name: "tests.example.com",
Name: apifullname,
Version: "v1",
Kind: "Test",
}},
Expand All @@ -240,6 +254,10 @@ var _ = Describe("ClusterServiceVersion", func() {
Eventually(func() error {
return ctx.Ctx().Client().Get(context.Background(), client.ObjectKeyFromObject(&unassociated), &unassociated)
}).Should(WithTransform(k8serrors.IsNotFound, BeTrue()))

Eventually(func() error {
return ctx.Ctx().Client().Delete(context.Background(), &associated)
}).Should(Succeed())
})

It("can satisfy an unassociated ClusterServiceVersion's non-ownership requirement", func() {
Expand All @@ -251,7 +269,7 @@ var _ = Describe("ClusterServiceVersion", func() {
Spec: operatorsv1alpha1.ClusterServiceVersionSpec{
CustomResourceDefinitions: operatorsv1alpha1.CustomResourceDefinitions{
Required: []operatorsv1alpha1.CRDDescription{{
Name: "tests.example.com",
Name: apifullname,
Version: "v1",
Kind: "Test",
}},
Expand Down Expand Up @@ -291,6 +309,9 @@ var _ = Describe("ClusterServiceVersion", func() {
Status: operatorsv1alpha1.RequirementStatusReasonPresent,
},
))
Eventually(func() error {
return ctx.Ctx().Client().Delete(context.Background(), &unassociated)
}).Should(Succeed())
})

When("an unassociated ClusterServiceVersion in different namespace owns the same CRD", func() {
Expand All @@ -301,12 +322,12 @@ var _ = Describe("ClusterServiceVersion", func() {
BeforeEach(func() {
ns = corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: "test-namespace-2",
Name: genName("test-namespace-2-"),
},
}
Expect(ctx.Ctx().Client().Create(context.Background(), &ns)).To(Succeed())

og := operatorsv1.OperatorGroup{
og = operatorsv1.OperatorGroup{
Comment thread
timflannagan marked this conversation as resolved.
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-operatorgroup", ns.GetName()),
Namespace: ns.GetName(),
Expand All @@ -333,7 +354,7 @@ var _ = Describe("ClusterServiceVersion", func() {
Spec: operatorsv1alpha1.ClusterServiceVersionSpec{
CustomResourceDefinitions: operatorsv1alpha1.CustomResourceDefinitions{
Owned: []operatorsv1alpha1.CRDDescription{{
Name: "tests.example.com",
Name: apifullname,
Version: "v1",
Kind: "Test",
}},
Expand All @@ -357,7 +378,7 @@ var _ = Describe("ClusterServiceVersion", func() {
Spec: operatorsv1alpha1.ClusterServiceVersionSpec{
CustomResourceDefinitions: operatorsv1alpha1.CustomResourceDefinitions{
Owned: []operatorsv1alpha1.CRDDescription{{
Name: "tests.example.com",
Name: apifullname,
Version: "v1",
Kind: "Test",
}},
Expand Down