Skip to content

Commit

Permalink
Move install plan e2e to one namespace per spec (#2708)
Browse files Browse the repository at this point in the history
Signed-off-by: perdasilva <perdasilva@redhat.com>
  • Loading branch information
perdasilva committed Mar 28, 2022
1 parent c64ebd6 commit eb01127
Show file tree
Hide file tree
Showing 3 changed files with 512 additions and 256 deletions.
73 changes: 72 additions & 1 deletion test/e2e/catalog_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"time"

operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
k8serror "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/blang/semver/v4"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -78,9 +80,18 @@ var _ = Describe("Catalog represents a store of bundles which OLM can use to ins
},
}

crd := newCRD(genName("ins"))
crd := newCRD(genName("ins-"))
csv := newCSV(packageStable, ns.GetName(), "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{crd}, nil, nil)

defer func() {
Eventually(func() error {
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), crd.GetName(), metav1.DeleteOptions{})
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &csv))
}).Should(Succeed())
}()

catalogSourceName := genName("mock-ocs-")
_, cleanupSource := createInternalCatalogSource(c, crc, catalogSourceName, ns.GetName(), manifests, []apiextensions.CustomResourceDefinition{crd}, []v1alpha1.ClusterServiceVersion{csv})
defer cleanupSource()
Expand Down Expand Up @@ -138,6 +149,18 @@ var _ = Describe("Catalog represents a store of bundles which OLM can use to ins
mainCSV := newCSV(mainPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{mainCRD}, nil, nil)
replacementCSV := newCSV(mainPackageReplacement, ns.GetName(), mainPackageStable, semver.MustParse("0.2.0"), []apiextensions.CustomResourceDefinition{mainCRD}, nil, nil)

defer func() {
Eventually(func() error {
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), mainCRD.GetName(), metav1.DeleteOptions{})
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &mainCSV))
}).Should(Succeed())
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &replacementCSV))
}).Should(Succeed())
}()

mainCatalogName := genName("mock-ocs-main-")

// Create separate manifests for each CatalogSource
Expand Down Expand Up @@ -230,6 +253,18 @@ var _ = Describe("Catalog represents a store of bundles which OLM can use to ins
mainCSV := newCSV(mainPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), nil, []apiextensions.CustomResourceDefinition{dependentCRD}, nil)
dependentCSV := newCSV(dependentPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{dependentCRD}, nil, nil)

defer func() {
Eventually(func() error {
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), dependentCRD.GetName(), metav1.DeleteOptions{})
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &mainCSV))
}).Should(Succeed())
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &dependentCSV))
}).Should(Succeed())
}()

mainCatalogName := genName("mock-ocs-main-")

// Create separate manifests for each CatalogSource
Expand Down Expand Up @@ -351,6 +386,18 @@ var _ = Describe("Catalog represents a store of bundles which OLM can use to ins
mainCSV := newCSV(mainPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), nil, []apiextensions.CustomResourceDefinition{dependentCRD}, nil)
dependentCSV := newCSV(dependentPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{dependentCRD}, nil, nil)

defer func() {
Eventually(func() error {
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), dependentCRD.GetName(), metav1.DeleteOptions{})
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &mainCSV))
}).Should(Succeed())
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &dependentCSV))
}).Should(Succeed())
}()

mainCatalogName := genName("mock-ocs-main-")

// Create separate manifests for each CatalogSource
Expand Down Expand Up @@ -433,6 +480,21 @@ var _ = Describe("Catalog represents a store of bundles which OLM can use to ins
replacementCSV := newCSV(mainPackageReplacement, ns.GetName(), mainPackageStable, semver.MustParse("0.2.0"), nil, []apiextensions.CustomResourceDefinition{dependentCRD}, nil)
dependentCSV := newCSV(dependentPackageStable, ns.GetName(), "", semver.MustParse("0.1.0"), []apiextensions.CustomResourceDefinition{dependentCRD}, nil, nil)

defer func() {
Eventually(func() error {
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), dependentCRD.GetName(), metav1.DeleteOptions{})
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &mainCSV))
}).Should(Succeed())
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &dependentCSV))
}).Should(Succeed())
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &replacementCSV))
}).Should(Succeed())
}()

mainSourceName := genName("mock-ocs-main-")
replacementSourceName := genName("mock-ocs-main-with-replacement-")

Expand Down Expand Up @@ -565,6 +627,15 @@ var _ = Describe("Catalog represents a store of bundles which OLM can use to ins
},
}

defer func() {
Eventually(func() error {
return ctx.Ctx().KubeClient().ApiextensionsInterface().ApiextensionsV1().CustomResourceDefinitions().Delete(context.TODO(), crd.GetName(), metav1.DeleteOptions{})
}).Should(Or(Succeed(), WithTransform(k8serror.IsNotFound, BeTrue())))
Eventually(func() error {
return client.IgnoreNotFound(ctx.Ctx().Client().Delete(context.TODO(), &csv))
}).Should(Succeed())
}()

_, cleanupSource := createInternalCatalogSource(c, crc, sourceName, ns.GetName(), manifests, []apiextensions.CustomResourceDefinition{crd}, []v1alpha1.ClusterServiceVersion{csv})
defer cleanupSource()

Expand Down
3 changes: 2 additions & 1 deletion test/e2e/ctx/ctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

g "github.com/onsi/ginkgo"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic"
Expand Down Expand Up @@ -162,12 +163,12 @@ func setDerivedFields(ctx *TestContext) error {

ctx.scheme = runtime.NewScheme()
localSchemeBuilder := runtime.NewSchemeBuilder(
apiextensionsv1.AddToScheme,
kscheme.AddToScheme,
operatorsv1alpha1.AddToScheme,
operatorsv1.AddToScheme,
operatorsv2.AddToScheme,
apiextensionsv1.AddToScheme,
apiextensions.AddToScheme,
)
if err := localSchemeBuilder.AddToScheme(ctx.scheme); err != nil {
return err
Expand Down
Loading

0 comments on commit eb01127

Please sign in to comment.