From 9755169063ec42b8e57c1e6798d7b1b7d11ed3f8 Mon Sep 17 00:00:00 2001 From: Ankita Thomas Date: Thu, 25 May 2023 23:29:52 -0400 Subject: [PATCH] use smaller test index image, cleanup after tests Signed-off-by: Ankita Thomas --- controllers/operator_controller.go | 3 +- go.mod | 4 +- test/e2e/install_test.go | 125 ++++++++++++++++------------- 3 files changed, 74 insertions(+), 58 deletions(-) diff --git a/controllers/operator_controller.go b/controllers/operator_controller.go index 72ed6305b..38f326df5 100644 --- a/controllers/operator_controller.go +++ b/controllers/operator_controller.go @@ -21,7 +21,6 @@ import ( "fmt" "github.com/go-logr/logr" - operatorv1 "github.com/operator-framework/api/pkg/operators/v1" catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1" "github.com/operator-framework/deppy/pkg/deppy/solver" rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1" @@ -436,7 +435,7 @@ func setInstalledStatusConditionUnknown(conditions *[]metav1.Condition, message func operatorRequestsForCatalog(ctx context.Context, c client.Reader, logger logr.Logger) handler.MapFunc { return func(object client.Object) []reconcile.Request { // no way of associating an operator to a catalog so create reconcile requests for everything - operators := operatorv1.OperatorList{} + operators := operatorsv1alpha1.OperatorList{} err := c.List(ctx, &operators) if err != nil { logger.Error(err, "unable to enqueue operators for catalog reconcile") diff --git a/go.mod b/go.mod index c8d28c5aa..268e10e30 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,10 @@ go 1.19 require ( github.com/blang/semver/v4 v4.0.0 + github.com/go-logr/logr v1.2.3 github.com/onsi/ginkgo/v2 v2.8.3 github.com/onsi/gomega v1.27.1 + github.com/operator-framework/api v0.17.3 github.com/operator-framework/catalogd v0.1.3 github.com/operator-framework/deppy v0.0.0-20230125110717-dc02e928470f github.com/operator-framework/operator-registry v1.26.3 @@ -26,7 +28,6 @@ require ( github.com/evanphx/json-patch/v5 v5.6.0 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/go-air/gini v1.0.4 // indirect - github.com/go-logr/logr v1.2.3 // indirect github.com/go-logr/zapr v1.2.3 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect @@ -48,7 +49,6 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/operator-framework/api v0.17.3 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_golang v1.14.0 // indirect github.com/prometheus/client_model v0.3.0 // indirect diff --git a/test/e2e/install_test.go b/test/e2e/install_test.go index 8a017a230..cf39bb129 100644 --- a/test/e2e/install_test.go +++ b/test/e2e/install_test.go @@ -10,6 +10,7 @@ import ( catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1" operatorv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1" rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" apimeta "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" @@ -49,28 +50,31 @@ var _ = Describe("Operator Install", func() { Spec: catalogd.CatalogSourceSpec{ // (TODO): Set up a local image registry, and build and store a test catalog in it // to use in the test suite - Image: "quay.io/operatorhubio/catalog:latest", + Image: "quay.io/olmtest/e2e-index:single-package-fbc", //generated from: "quay.io/operatorhubio/catalog:latest", }, } + }) + It("resolves the specified package with correct bundle path", func() { err := c.Create(ctx, operatorCatalog) Expect(err).ToNot(HaveOccurred()) Eventually(func(g Gomega) { err = c.Get(ctx, types.NamespacedName{Name: "test-catalog"}, operatorCatalog) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(len(operatorCatalog.Status.Conditions)).To(Equal(1)) - g.Expect(operatorCatalog.Status.Conditions[0].Message).To(Equal("catalog contents have been unpacked and are available on cluster")) + cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeReady) + g.Expect(cond).ToNot(BeNil()) + g.Expect(cond.Status).To(Equal(metav1.ConditionTrue)) + g.Expect(cond.Reason).To(Equal(catalogd.ReasonContentsAvailable)) }).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed()) - }) - It("resolves the specified package with correct bundle path", func() { + By("creating the Operator resource") - err := c.Create(ctx, operator) + err = c.Create(ctx, operator) Expect(err).ToNot(HaveOccurred()) By("eventually reporting a successful resolution and bundle path") Eventually(func(g Gomega) { err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(len(operator.Status.Conditions)).To(Equal(2)) + cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved) g.Expect(cond).ToNot(BeNil()) g.Expect(cond.Status).To(Equal(metav1.ConditionTrue)) @@ -92,44 +96,25 @@ var _ = Describe("Operator Install", func() { bd := rukpakv1alpha1.BundleDeployment{} err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &bd) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(len(bd.Status.Conditions)).To(Equal(2)) - g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful")) - g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded")) + + cond = apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeHasValidBundle) + g.Expect(cond).ToNot(BeNil()) + g.Expect(cond.Status).To(Equal(metav1.ConditionTrue)) + g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonUnpackSuccessful)) + + cond = apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeInstalled) + g.Expect(cond).ToNot(BeNil()) + g.Expect(cond.Status).To(Equal(metav1.ConditionTrue)) + g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonInstallationSucceeded)) }).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed()) }) - AfterEach(func() { - err := c.Delete(ctx, operatorCatalog) - Expect(err).ToNot(HaveOccurred()) - err = c.Delete(ctx, operator) - Expect(err).ToNot(HaveOccurred()) - }) - }) - When("resolving for an unavailable operator package", func() { - BeforeEach(func() { - ctx = context.Background() - pkgName = "argocd-operator" - operatorName = fmt.Sprintf("operator-%s", rand.String(8)) - operator = &operatorv1alpha1.Operator{ - ObjectMeta: metav1.ObjectMeta{ - Name: operatorName, - }, - Spec: operatorv1alpha1.OperatorSpec{ - PackageName: pkgName, - }, - } - operatorCatalog = &catalogd.CatalogSource{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-catalog", - }, - Spec: catalogd.CatalogSourceSpec{ - // (TODO): Set up a local image registry, and build and store a test catalog in it - // to use in the test suite - Image: "quay.io/operatorhubio/catalog:latest", - }, - } - }) - It("resolves again when a new catalog is available", func() { + Eventually(func(g Gomega) { + // target package should not be present on cluster + err := c.Get(ctx, types.NamespacedName{Name: pkgName}, &catalogd.Package{}) + Expect(errors.IsNotFound(err)).To(BeTrue()) + }).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed()) + By("creating the Operator resource") err := c.Create(ctx, operator) Expect(err).ToNot(HaveOccurred()) @@ -138,7 +123,6 @@ var _ = Describe("Operator Install", func() { Eventually(func(g Gomega) { err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(len(operator.Status.Conditions)).To(Equal(2)) cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved) g.Expect(cond).ToNot(BeNil()) g.Expect(cond.Status).To(Equal(metav1.ConditionFalse)) @@ -150,27 +134,60 @@ var _ = Describe("Operator Install", func() { err = c.Create(ctx, operatorCatalog) Expect(err).ToNot(HaveOccurred()) Eventually(func(g Gomega) { - err = c.Get(ctx, types.NamespacedName{Name: "test-catalog"}, operatorCatalog) + err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, operatorCatalog) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(len(operatorCatalog.Status.Conditions)).To(Equal(1)) - g.Expect(operatorCatalog.Status.Conditions[0].Message).To(Equal("catalog contents have been unpacked and are available on cluster")) + cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeReady) + g.Expect(cond).ToNot(BeNil()) + g.Expect(cond.Status).To(Equal(metav1.ConditionTrue)) + g.Expect(cond.Reason).To(Equal(catalogd.ReasonContentsAvailable)) }).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed()) - By("eventually installing the package successfully") + By("eventually resolving the package successfully") Eventually(func(g Gomega) { - bd := rukpakv1alpha1.BundleDeployment{} - err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &bd) + err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator) g.Expect(err).ToNot(HaveOccurred()) - g.Expect(len(bd.Status.Conditions)).To(Equal(2)) - g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful")) - g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded")) + cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved) + g.Expect(cond).ToNot(BeNil()) + g.Expect(cond.Status).To(Equal(metav1.ConditionTrue)) + g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonSuccess)) }).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed()) }) AfterEach(func() { - err := c.Delete(ctx, operatorCatalog) + err := c.Delete(ctx, operator) Expect(err).ToNot(HaveOccurred()) - err = c.Delete(ctx, operator) + Eventually(func(g Gomega) { + err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &operatorv1alpha1.Operator{}) + Expect(errors.IsNotFound(err)).To(BeTrue()) + }).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed()) + + err = c.Delete(ctx, operatorCatalog) Expect(err).ToNot(HaveOccurred()) + Eventually(func(g Gomega) { + err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, &catalogd.CatalogSource{}) + Expect(errors.IsNotFound(err)).To(BeTrue()) + }).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed()) + + // speed up delete without waiting for gc + err = c.DeleteAllOf(ctx, &catalogd.BundleMetadata{}) + Expect(err).ToNot(HaveOccurred()) + err = c.DeleteAllOf(ctx, &catalogd.Package{}) + Expect(err).ToNot(HaveOccurred()) + + Eventually(func(g Gomega) { + // ensure resource cleanup + packages := &catalogd.PackageList{} + err = c.List(ctx, packages) + Expect(err).To(BeNil()) + Expect(packages.Items).To(BeEmpty()) + + bmd := &catalogd.BundleMetadataList{} + err = c.List(ctx, bmd) + Expect(err).To(BeNil()) + Expect(bmd.Items).To(BeEmpty()) + + err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &rukpakv1alpha1.BundleDeployment{}) + Expect(errors.IsNotFound(err)).To(BeTrue()) + }).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed()) }) }) })