Skip to content

Commit 9755169

Browse files
committed
use smaller test index image, cleanup after tests
Signed-off-by: Ankita Thomas <ankithom@redhat.com>
1 parent ce48991 commit 9755169

File tree

3 files changed

+74
-58
lines changed

3 files changed

+74
-58
lines changed

controllers/operator_controller.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"fmt"
2222

2323
"github.com/go-logr/logr"
24-
operatorv1 "github.com/operator-framework/api/pkg/operators/v1"
2524
catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1"
2625
"github.com/operator-framework/deppy/pkg/deppy/solver"
2726
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
@@ -436,7 +435,7 @@ func setInstalledStatusConditionUnknown(conditions *[]metav1.Condition, message
436435
func operatorRequestsForCatalog(ctx context.Context, c client.Reader, logger logr.Logger) handler.MapFunc {
437436
return func(object client.Object) []reconcile.Request {
438437
// no way of associating an operator to a catalog so create reconcile requests for everything
439-
operators := operatorv1.OperatorList{}
438+
operators := operatorsv1alpha1.OperatorList{}
440439
err := c.List(ctx, &operators)
441440
if err != nil {
442441
logger.Error(err, "unable to enqueue operators for catalog reconcile")

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ go 1.19
44

55
require (
66
github.com/blang/semver/v4 v4.0.0
7+
github.com/go-logr/logr v1.2.3
78
github.com/onsi/ginkgo/v2 v2.8.3
89
github.com/onsi/gomega v1.27.1
10+
github.com/operator-framework/api v0.17.3
911
github.com/operator-framework/catalogd v0.1.3
1012
github.com/operator-framework/deppy v0.0.0-20230125110717-dc02e928470f
1113
github.com/operator-framework/operator-registry v1.26.3
@@ -26,7 +28,6 @@ require (
2628
github.com/evanphx/json-patch/v5 v5.6.0 // indirect
2729
github.com/fsnotify/fsnotify v1.6.0 // indirect
2830
github.com/go-air/gini v1.0.4 // indirect
29-
github.com/go-logr/logr v1.2.3 // indirect
3031
github.com/go-logr/zapr v1.2.3 // indirect
3132
github.com/go-openapi/jsonpointer v0.19.5 // indirect
3233
github.com/go-openapi/jsonreference v0.20.0 // indirect
@@ -48,7 +49,6 @@ require (
4849
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4950
github.com/modern-go/reflect2 v1.0.2 // indirect
5051
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
51-
github.com/operator-framework/api v0.17.3 // indirect
5252
github.com/pkg/errors v0.9.1 // indirect
5353
github.com/prometheus/client_golang v1.14.0 // indirect
5454
github.com/prometheus/client_model v0.3.0 // indirect

test/e2e/install_test.go

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1"
1111
operatorv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
1212
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
13+
"k8s.io/apimachinery/pkg/api/errors"
1314
apimeta "k8s.io/apimachinery/pkg/api/meta"
1415
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1516
"k8s.io/apimachinery/pkg/types"
@@ -49,28 +50,31 @@ var _ = Describe("Operator Install", func() {
4950
Spec: catalogd.CatalogSourceSpec{
5051
// (TODO): Set up a local image registry, and build and store a test catalog in it
5152
// to use in the test suite
52-
Image: "quay.io/operatorhubio/catalog:latest",
53+
Image: "quay.io/olmtest/e2e-index:single-package-fbc", //generated from: "quay.io/operatorhubio/catalog:latest",
5354
},
5455
}
56+
})
57+
It("resolves the specified package with correct bundle path", func() {
5558
err := c.Create(ctx, operatorCatalog)
5659
Expect(err).ToNot(HaveOccurred())
5760
Eventually(func(g Gomega) {
5861
err = c.Get(ctx, types.NamespacedName{Name: "test-catalog"}, operatorCatalog)
5962
g.Expect(err).ToNot(HaveOccurred())
60-
g.Expect(len(operatorCatalog.Status.Conditions)).To(Equal(1))
61-
g.Expect(operatorCatalog.Status.Conditions[0].Message).To(Equal("catalog contents have been unpacked and are available on cluster"))
63+
cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeReady)
64+
g.Expect(cond).ToNot(BeNil())
65+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
66+
g.Expect(cond.Reason).To(Equal(catalogd.ReasonContentsAvailable))
6267
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
63-
})
64-
It("resolves the specified package with correct bundle path", func() {
68+
6569
By("creating the Operator resource")
66-
err := c.Create(ctx, operator)
70+
err = c.Create(ctx, operator)
6771
Expect(err).ToNot(HaveOccurred())
6872

6973
By("eventually reporting a successful resolution and bundle path")
7074
Eventually(func(g Gomega) {
7175
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
7276
g.Expect(err).ToNot(HaveOccurred())
73-
g.Expect(len(operator.Status.Conditions)).To(Equal(2))
77+
7478
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
7579
g.Expect(cond).ToNot(BeNil())
7680
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
@@ -92,44 +96,25 @@ var _ = Describe("Operator Install", func() {
9296
bd := rukpakv1alpha1.BundleDeployment{}
9397
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &bd)
9498
g.Expect(err).ToNot(HaveOccurred())
95-
g.Expect(len(bd.Status.Conditions)).To(Equal(2))
96-
g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful"))
97-
g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded"))
99+
100+
cond = apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeHasValidBundle)
101+
g.Expect(cond).ToNot(BeNil())
102+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
103+
g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonUnpackSuccessful))
104+
105+
cond = apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeInstalled)
106+
g.Expect(cond).ToNot(BeNil())
107+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
108+
g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonInstallationSucceeded))
98109
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
99110
})
100-
AfterEach(func() {
101-
err := c.Delete(ctx, operatorCatalog)
102-
Expect(err).ToNot(HaveOccurred())
103-
err = c.Delete(ctx, operator)
104-
Expect(err).ToNot(HaveOccurred())
105-
})
106-
})
107-
When("resolving for an unavailable operator package", func() {
108-
BeforeEach(func() {
109-
ctx = context.Background()
110-
pkgName = "argocd-operator"
111-
operatorName = fmt.Sprintf("operator-%s", rand.String(8))
112-
operator = &operatorv1alpha1.Operator{
113-
ObjectMeta: metav1.ObjectMeta{
114-
Name: operatorName,
115-
},
116-
Spec: operatorv1alpha1.OperatorSpec{
117-
PackageName: pkgName,
118-
},
119-
}
120-
operatorCatalog = &catalogd.CatalogSource{
121-
ObjectMeta: metav1.ObjectMeta{
122-
Name: "test-catalog",
123-
},
124-
Spec: catalogd.CatalogSourceSpec{
125-
// (TODO): Set up a local image registry, and build and store a test catalog in it
126-
// to use in the test suite
127-
Image: "quay.io/operatorhubio/catalog:latest",
128-
},
129-
}
130-
})
131-
132111
It("resolves again when a new catalog is available", func() {
112+
Eventually(func(g Gomega) {
113+
// target package should not be present on cluster
114+
err := c.Get(ctx, types.NamespacedName{Name: pkgName}, &catalogd.Package{})
115+
Expect(errors.IsNotFound(err)).To(BeTrue())
116+
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
117+
133118
By("creating the Operator resource")
134119
err := c.Create(ctx, operator)
135120
Expect(err).ToNot(HaveOccurred())
@@ -138,7 +123,6 @@ var _ = Describe("Operator Install", func() {
138123
Eventually(func(g Gomega) {
139124
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
140125
g.Expect(err).ToNot(HaveOccurred())
141-
g.Expect(len(operator.Status.Conditions)).To(Equal(2))
142126
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
143127
g.Expect(cond).ToNot(BeNil())
144128
g.Expect(cond.Status).To(Equal(metav1.ConditionFalse))
@@ -150,27 +134,60 @@ var _ = Describe("Operator Install", func() {
150134
err = c.Create(ctx, operatorCatalog)
151135
Expect(err).ToNot(HaveOccurred())
152136
Eventually(func(g Gomega) {
153-
err = c.Get(ctx, types.NamespacedName{Name: "test-catalog"}, operatorCatalog)
137+
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, operatorCatalog)
154138
g.Expect(err).ToNot(HaveOccurred())
155-
g.Expect(len(operatorCatalog.Status.Conditions)).To(Equal(1))
156-
g.Expect(operatorCatalog.Status.Conditions[0].Message).To(Equal("catalog contents have been unpacked and are available on cluster"))
139+
cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeReady)
140+
g.Expect(cond).ToNot(BeNil())
141+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
142+
g.Expect(cond.Reason).To(Equal(catalogd.ReasonContentsAvailable))
157143
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
158144

159-
By("eventually installing the package successfully")
145+
By("eventually resolving the package successfully")
160146
Eventually(func(g Gomega) {
161-
bd := rukpakv1alpha1.BundleDeployment{}
162-
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &bd)
147+
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
163148
g.Expect(err).ToNot(HaveOccurred())
164-
g.Expect(len(bd.Status.Conditions)).To(Equal(2))
165-
g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful"))
166-
g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded"))
149+
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
150+
g.Expect(cond).ToNot(BeNil())
151+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
152+
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonSuccess))
167153
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
168154
})
169155
AfterEach(func() {
170-
err := c.Delete(ctx, operatorCatalog)
156+
err := c.Delete(ctx, operator)
171157
Expect(err).ToNot(HaveOccurred())
172-
err = c.Delete(ctx, operator)
158+
Eventually(func(g Gomega) {
159+
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &operatorv1alpha1.Operator{})
160+
Expect(errors.IsNotFound(err)).To(BeTrue())
161+
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
162+
163+
err = c.Delete(ctx, operatorCatalog)
173164
Expect(err).ToNot(HaveOccurred())
165+
Eventually(func(g Gomega) {
166+
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, &catalogd.CatalogSource{})
167+
Expect(errors.IsNotFound(err)).To(BeTrue())
168+
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
169+
170+
// speed up delete without waiting for gc
171+
err = c.DeleteAllOf(ctx, &catalogd.BundleMetadata{})
172+
Expect(err).ToNot(HaveOccurred())
173+
err = c.DeleteAllOf(ctx, &catalogd.Package{})
174+
Expect(err).ToNot(HaveOccurred())
175+
176+
Eventually(func(g Gomega) {
177+
// ensure resource cleanup
178+
packages := &catalogd.PackageList{}
179+
err = c.List(ctx, packages)
180+
Expect(err).To(BeNil())
181+
Expect(packages.Items).To(BeEmpty())
182+
183+
bmd := &catalogd.BundleMetadataList{}
184+
err = c.List(ctx, bmd)
185+
Expect(err).To(BeNil())
186+
Expect(bmd.Items).To(BeEmpty())
187+
188+
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &rukpakv1alpha1.BundleDeployment{})
189+
Expect(errors.IsNotFound(err)).To(BeTrue())
190+
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
174191
})
175192
})
176193
})

0 commit comments

Comments
 (0)