Skip to content

Commit 4c372d1

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

File tree

3 files changed

+77
-58
lines changed

3 files changed

+77
-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"
@@ -414,7 +413,7 @@ func isBundleDepStale(bd *rukpakv1alpha1.BundleDeployment) bool {
414413
func operatorRequestsForCatalog(ctx context.Context, c client.Reader, logger logr.Logger) handler.MapFunc {
415414
return func(object client.Object) []reconcile.Request {
416415
// no way of associating an operator to a catalog so create reconcile requests for everything
417-
operators := operatorv1.OperatorList{}
416+
operators := operatorsv1alpha1.OperatorList{}
418417
err := c.List(ctx, &operators)
419418
if err != nil {
420419
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: 74 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,30 @@ 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))
7477
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeReady)
7578
g.Expect(cond).ToNot(BeNil())
7679
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
@@ -89,44 +92,24 @@ var _ = Describe("Operator Install", func() {
8992
bd := rukpakv1alpha1.BundleDeployment{}
9093
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &bd)
9194
g.Expect(err).ToNot(HaveOccurred())
92-
g.Expect(len(bd.Status.Conditions)).To(Equal(2))
93-
g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful"))
94-
g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded"))
95+
cond := apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeHasValidBundle)
96+
g.Expect(cond).ToNot(BeNil())
97+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
98+
g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonUnpackSuccessful))
99+
100+
cond = apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeInstalled)
101+
g.Expect(cond).ToNot(BeNil())
102+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
103+
g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonInstallationSucceeded))
95104
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
96105
})
97-
AfterEach(func() {
98-
err := c.Delete(ctx, operatorCatalog)
99-
Expect(err).ToNot(HaveOccurred())
100-
err = c.Delete(ctx, operator)
101-
Expect(err).ToNot(HaveOccurred())
102-
})
103-
})
104-
When("resolving for an unavailable operator package", func() {
105-
BeforeEach(func() {
106-
ctx = context.Background()
107-
pkgName = "argocd-operator"
108-
operatorName = fmt.Sprintf("operator-%s", rand.String(8))
109-
operator = &operatorv1alpha1.Operator{
110-
ObjectMeta: metav1.ObjectMeta{
111-
Name: operatorName,
112-
},
113-
Spec: operatorv1alpha1.OperatorSpec{
114-
PackageName: pkgName,
115-
},
116-
}
117-
operatorCatalog = &catalogd.CatalogSource{
118-
ObjectMeta: metav1.ObjectMeta{
119-
Name: "test-catalog",
120-
},
121-
Spec: catalogd.CatalogSourceSpec{
122-
// (TODO): Set up a local image registry, and build and store a test catalog in it
123-
// to use in the test suite
124-
Image: "quay.io/operatorhubio/catalog:latest",
125-
},
126-
}
127-
})
128-
129106
It("resolves again when a new catalog is available", func() {
107+
Eventually(func(g Gomega) {
108+
// target package should not be present on cluster
109+
err := c.Get(ctx, types.NamespacedName{Name: pkgName}, &catalogd.Package{})
110+
Expect(errors.IsNotFound(err)).To(BeTrue())
111+
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
112+
130113
By("creating the Operator resource")
131114
err := c.Create(ctx, operator)
132115
Expect(err).ToNot(HaveOccurred())
@@ -135,7 +118,6 @@ var _ = Describe("Operator Install", func() {
135118
Eventually(func(g Gomega) {
136119
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
137120
g.Expect(err).ToNot(HaveOccurred())
138-
g.Expect(len(operator.Status.Conditions)).To(Equal(2))
139121
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
140122
g.Expect(cond).ToNot(BeNil())
141123
g.Expect(cond.Status).To(Equal(metav1.ConditionFalse))
@@ -147,27 +129,65 @@ var _ = Describe("Operator Install", func() {
147129
err = c.Create(ctx, operatorCatalog)
148130
Expect(err).ToNot(HaveOccurred())
149131
Eventually(func(g Gomega) {
150-
err = c.Get(ctx, types.NamespacedName{Name: "test-catalog"}, operatorCatalog)
132+
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, operatorCatalog)
151133
g.Expect(err).ToNot(HaveOccurred())
152-
g.Expect(len(operatorCatalog.Status.Conditions)).To(Equal(1))
153-
g.Expect(operatorCatalog.Status.Conditions[0].Message).To(Equal("catalog contents have been unpacked and are available on cluster"))
134+
cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeReady)
135+
g.Expect(cond).ToNot(BeNil())
136+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
137+
g.Expect(cond.Reason).To(Equal(catalogd.ReasonContentsAvailable))
154138
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
155139

156-
By("eventually installing the package successfully")
140+
By("eventually resolving the package successfully")
157141
Eventually(func(g Gomega) {
158-
bd := rukpakv1alpha1.BundleDeployment{}
159-
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &bd)
142+
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
160143
g.Expect(err).ToNot(HaveOccurred())
161-
g.Expect(len(bd.Status.Conditions)).To(Equal(2))
162-
g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful"))
163-
g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded"))
144+
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeReady)
145+
g.Expect(cond).ToNot(BeNil())
146+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
147+
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonInstallationSucceeded))
148+
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))
164153
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
165154
})
166155
AfterEach(func() {
167-
err := c.Delete(ctx, operatorCatalog)
156+
err := c.Delete(ctx, operator)
157+
Expect(err).ToNot(HaveOccurred())
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)
168164
Expect(err).ToNot(HaveOccurred())
169-
err = c.Delete(ctx, operator)
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{})
170172
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())
171191
})
172192
})
173193
})

0 commit comments

Comments
 (0)