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