Skip to content

Commit cd88cc7

Browse files
committed
use smaller test index image, cleanup after tests
Signed-off-by: Ankita Thomas <[email protected]>
1 parent b688885 commit cd88cc7

File tree

5 files changed

+78
-174
lines changed

5 files changed

+78
-174
lines changed

config/rbac/role.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ rules:
1515
- apiGroups:
1616
- catalogd.operatorframework.io
1717
resources:
18-
- catalogsources
18+
- catalogs
1919
verbs:
2020
- list
2121
- watch

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ 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
910
github.com/operator-framework/catalogd v0.2.0
11+
github.com/operator-framework/api v0.17.3
1012
github.com/operator-framework/deppy v0.0.0-20230125110717-dc02e928470f
1113
github.com/operator-framework/operator-registry v1.26.3
1214
github.com/operator-framework/rukpak v0.12.0
@@ -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

internal/controllers/catalog_predicates.go

Lines changed: 0 additions & 115 deletions
This file was deleted.

internal/controllers/operator_controller.go

Lines changed: 3 additions & 4 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"
@@ -62,7 +61,7 @@ type OperatorReconciler struct {
6261

6362
//+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=bundlemetadata,verbs=list;watch
6463
//+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=packages,verbs=list;watch
65-
//+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=catalogsources,verbs=list;watch
64+
//+kubebuilder:rbac:groups=catalogd.operatorframework.io,resources=catalogs,verbs=list;watch
6665

6766
func (r *OperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
6867
l := log.FromContext(ctx).WithName("operator-controller")
@@ -293,7 +292,7 @@ func (r *OperatorReconciler) generateExpectedBundleDeployment(o operatorsv1alpha
293292
func (r *OperatorReconciler) SetupWithManager(mgr ctrl.Manager) error {
294293
err := ctrl.NewControllerManagedBy(mgr).
295294
For(&operatorsv1alpha1.Operator{}).
296-
Watches(source.NewKindWithCache(&catalogd.CatalogSource{}, mgr.GetCache()),
295+
Watches(source.NewKindWithCache(&catalogd.Catalog{}, mgr.GetCache()),
297296
handler.EnqueueRequestsFromMapFunc(operatorRequestsForCatalog(context.TODO(), mgr.GetClient(), mgr.GetLogger()))).
298297
Owns(&rukpakv1alpha1.BundleDeployment{}).
299298
Complete(r)
@@ -435,7 +434,7 @@ func setInstalledStatusConditionUnknown(conditions *[]metav1.Condition, message
435434
func operatorRequestsForCatalog(ctx context.Context, c client.Reader, logger logr.Logger) handler.MapFunc {
436435
return func(object client.Object) []reconcile.Request {
437436
// no way of associating an operator to a catalog so create reconcile requests for everything
438-
operators := operatorv1.OperatorList{}
437+
operators := operatorsv1alpha1.OperatorList{}
439438
err := c.List(ctx, &operators)
440439
if err != nil {
441440
logger.Error(err, "unable to enqueue operators for catalog reconcile")

test/e2e/install_test.go

Lines changed: 72 additions & 53 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"
@@ -52,30 +53,35 @@ var _ = Describe("Operator Install", func() {
5253
Image: &catalogd.ImageSource{
5354
// (TODO): Set up a local image registry, and build and store a test catalog in it
5455
// to use in the test suite
55-
Ref: "quay.io/operatorhubio/catalog:latest",
56+
Ref: "quay.io/olmtest/e2e-index:single-package-fbc", //generated from: "quay.io/operatorhubio/catalog:latest",
5657
},
5758
},
5859
},
5960
}
61+
})
62+
It("resolves the specified package with correct bundle path", func() {
6063
err := c.Create(ctx, operatorCatalog)
6164
Expect(err).ToNot(HaveOccurred())
6265
Eventually(func(g Gomega) {
6366
err = c.Get(ctx, types.NamespacedName{Name: "test-catalog"}, operatorCatalog)
6467
g.Expect(err).ToNot(HaveOccurred())
6568
g.Expect(len(operatorCatalog.Status.Conditions)).To(Equal(1))
66-
g.Expect(operatorCatalog.Status.Conditions[0].Message).To(ContainSubstring("successfully unpacked the catalog image"))
69+
cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeUnpacked)
70+
g.Expect(cond).ToNot(BeNil())
71+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
72+
g.Expect(cond.Reason).To(Equal(catalogd.ReasonUnpackSuccessful))
73+
g.Expect(cond.Message).To(ContainSubstring("successfully unpacked the catalog image"))
6774
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
68-
})
69-
It("resolves the specified package with correct bundle path", func() {
75+
7076
By("creating the Operator resource")
71-
err := c.Create(ctx, operator)
77+
err = c.Create(ctx, operator)
7278
Expect(err).ToNot(HaveOccurred())
7379

7480
By("eventually reporting a successful resolution and bundle path")
7581
Eventually(func(g Gomega) {
7682
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
7783
g.Expect(err).ToNot(HaveOccurred())
78-
g.Expect(len(operator.Status.Conditions)).To(Equal(2))
84+
7985
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
8086
g.Expect(cond).ToNot(BeNil())
8187
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
@@ -97,44 +103,25 @@ var _ = Describe("Operator Install", func() {
97103
bd := rukpakv1alpha1.BundleDeployment{}
98104
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &bd)
99105
g.Expect(err).ToNot(HaveOccurred())
100-
g.Expect(len(bd.Status.Conditions)).To(Equal(2))
101-
g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful"))
102-
g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded"))
106+
107+
cond = apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeHasValidBundle)
108+
g.Expect(cond).ToNot(BeNil())
109+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
110+
g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonUnpackSuccessful))
111+
112+
cond = apimeta.FindStatusCondition(bd.Status.Conditions, rukpakv1alpha1.TypeInstalled)
113+
g.Expect(cond).ToNot(BeNil())
114+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
115+
g.Expect(cond.Reason).To(Equal(rukpakv1alpha1.ReasonInstallationSucceeded))
103116
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
104117
})
105-
AfterEach(func() {
106-
err := c.Delete(ctx, operatorCatalog)
107-
Expect(err).ToNot(HaveOccurred())
108-
err = c.Delete(ctx, operator)
109-
Expect(err).ToNot(HaveOccurred())
110-
})
111-
})
112-
When("resolving for an unavailable operator package", func() {
113-
BeforeEach(func() {
114-
ctx = context.Background()
115-
pkgName = "argocd-operator"
116-
operatorName = fmt.Sprintf("operator-%s", rand.String(8))
117-
operator = &operatorv1alpha1.Operator{
118-
ObjectMeta: metav1.ObjectMeta{
119-
Name: operatorName,
120-
},
121-
Spec: operatorv1alpha1.OperatorSpec{
122-
PackageName: pkgName,
123-
},
124-
}
125-
operatorCatalog = &catalogd.CatalogSource{
126-
ObjectMeta: metav1.ObjectMeta{
127-
Name: "test-catalog",
128-
},
129-
Spec: catalogd.CatalogSourceSpec{
130-
// (TODO): Set up a local image registry, and build and store a test catalog in it
131-
// to use in the test suite
132-
Image: "quay.io/operatorhubio/catalog:latest",
133-
},
134-
}
135-
})
136-
137118
It("resolves again when a new catalog is available", func() {
119+
Eventually(func(g Gomega) {
120+
// target package should not be present on cluster
121+
err := c.Get(ctx, types.NamespacedName{Name: pkgName}, &catalogd.Package{})
122+
Expect(errors.IsNotFound(err)).To(BeTrue())
123+
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
124+
138125
By("creating the Operator resource")
139126
err := c.Create(ctx, operator)
140127
Expect(err).ToNot(HaveOccurred())
@@ -143,7 +130,6 @@ var _ = Describe("Operator Install", func() {
143130
Eventually(func(g Gomega) {
144131
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
145132
g.Expect(err).ToNot(HaveOccurred())
146-
g.Expect(len(operator.Status.Conditions)).To(Equal(2))
147133
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
148134
g.Expect(cond).ToNot(BeNil())
149135
g.Expect(cond.Status).To(Equal(metav1.ConditionFalse))
@@ -155,27 +141,60 @@ var _ = Describe("Operator Install", func() {
155141
err = c.Create(ctx, operatorCatalog)
156142
Expect(err).ToNot(HaveOccurred())
157143
Eventually(func(g Gomega) {
158-
err = c.Get(ctx, types.NamespacedName{Name: "test-catalog"}, operatorCatalog)
144+
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, operatorCatalog)
159145
g.Expect(err).ToNot(HaveOccurred())
160-
g.Expect(len(operatorCatalog.Status.Conditions)).To(Equal(1))
161-
g.Expect(operatorCatalog.Status.Conditions[0].Message).To(Equal("catalog contents have been unpacked and are available on cluster"))
146+
cond := apimeta.FindStatusCondition(operatorCatalog.Status.Conditions, catalogd.TypeUnpacked)
147+
g.Expect(cond).ToNot(BeNil())
148+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
149+
g.Expect(cond.Reason).To(Equal(catalogd.ReasonUnpackSuccessful))
162150
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
163151

164-
By("eventually installing the package successfully")
152+
By("eventually resolving the package successfully")
165153
Eventually(func(g Gomega) {
166-
bd := rukpakv1alpha1.BundleDeployment{}
167-
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &bd)
154+
err = c.Get(ctx, types.NamespacedName{Name: operator.Name}, operator)
168155
g.Expect(err).ToNot(HaveOccurred())
169-
g.Expect(len(bd.Status.Conditions)).To(Equal(2))
170-
g.Expect(bd.Status.Conditions[0].Reason).To(Equal("UnpackSuccessful"))
171-
g.Expect(bd.Status.Conditions[1].Reason).To(Equal("InstallationSucceeded"))
156+
cond := apimeta.FindStatusCondition(operator.Status.Conditions, operatorv1alpha1.TypeResolved)
157+
g.Expect(cond).ToNot(BeNil())
158+
g.Expect(cond.Status).To(Equal(metav1.ConditionTrue))
159+
g.Expect(cond.Reason).To(Equal(operatorv1alpha1.ReasonSuccess))
172160
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
173161
})
174162
AfterEach(func() {
175-
err := c.Delete(ctx, operatorCatalog)
163+
err := c.Delete(ctx, operator)
164+
Expect(err).ToNot(HaveOccurred())
165+
Eventually(func(g Gomega) {
166+
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &operatorv1alpha1.Operator{})
167+
Expect(errors.IsNotFound(err)).To(BeTrue())
168+
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
169+
170+
err = c.Delete(ctx, operatorCatalog)
171+
Expect(err).ToNot(HaveOccurred())
172+
Eventually(func(g Gomega) {
173+
err = c.Get(ctx, types.NamespacedName{Name: operatorCatalog.Name}, &catalogd.Catalog{})
174+
Expect(errors.IsNotFound(err)).To(BeTrue())
175+
}).WithTimeout(defaultTimeout).WithPolling(defaultPoll).Should(Succeed())
176+
177+
// speed up delete without waiting for gc
178+
err = c.DeleteAllOf(ctx, &catalogd.BundleMetadata{})
176179
Expect(err).ToNot(HaveOccurred())
177-
err = c.Delete(ctx, operator)
180+
err = c.DeleteAllOf(ctx, &catalogd.Package{})
178181
Expect(err).ToNot(HaveOccurred())
182+
183+
Eventually(func(g Gomega) {
184+
// ensure resource cleanup
185+
packages := &catalogd.PackageList{}
186+
err = c.List(ctx, packages)
187+
Expect(err).To(BeNil())
188+
Expect(packages.Items).To(BeEmpty())
189+
190+
bmd := &catalogd.BundleMetadataList{}
191+
err = c.List(ctx, bmd)
192+
Expect(err).To(BeNil())
193+
Expect(bmd.Items).To(BeEmpty())
194+
195+
err = c.Get(ctx, types.NamespacedName{Name: operatorName}, &rukpakv1alpha1.BundleDeployment{})
196+
Expect(errors.IsNotFound(err)).To(BeTrue())
197+
}).WithTimeout(5 * time.Minute).WithPolling(defaultPoll).Should(Succeed())
179198
})
180199
})
181200
})

0 commit comments

Comments
 (0)