Skip to content

Commit

Permalink
use smaller test index image, cleanup after tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ankita Thomas <ankithom@redhat.com>
  • Loading branch information
ankitathomas committed May 26, 2023
1 parent ce48991 commit 9755169
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 58 deletions.
3 changes: 1 addition & 2 deletions controllers/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
125 changes: 71 additions & 54 deletions test/e2e/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand All @@ -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())
Expand All @@ -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))
Expand All @@ -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())
})
})
})

0 comments on commit 9755169

Please sign in to comment.