@@ -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