@@ -10,6 +10,7 @@ import (
10
10
catalogd "github.com/operator-framework/catalogd/pkg/apis/core/v1beta1"
11
11
operatorv1alpha1 "github.com/operator-framework/operator-controller/api/v1alpha1"
12
12
rukpakv1alpha1 "github.com/operator-framework/rukpak/api/v1alpha1"
13
+ "k8s.io/apimachinery/pkg/api/errors"
13
14
apimeta "k8s.io/apimachinery/pkg/api/meta"
14
15
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
16
"k8s.io/apimachinery/pkg/types"
@@ -52,30 +53,35 @@ var _ = Describe("Operator Install", func() {
52
53
Image : & catalogd.ImageSource {
53
54
// (TODO): Set up a local image registry, and build and store a test catalog in it
54
55
// 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",
56
57
},
57
58
},
58
59
},
59
60
}
61
+ })
62
+ It ("resolves the specified package with correct bundle path" , func () {
60
63
err := c .Create (ctx , operatorCatalog )
61
64
Expect (err ).ToNot (HaveOccurred ())
62
65
Eventually (func (g Gomega ) {
63
66
err = c .Get (ctx , types.NamespacedName {Name : "test-catalog" }, operatorCatalog )
64
67
g .Expect (err ).ToNot (HaveOccurred ())
65
68
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" ))
67
74
}).WithTimeout (5 * time .Minute ).WithPolling (defaultPoll ).Should (Succeed ())
68
- })
69
- It ("resolves the specified package with correct bundle path" , func () {
75
+
70
76
By ("creating the Operator resource" )
71
- err : = c .Create (ctx , operator )
77
+ err = c .Create (ctx , operator )
72
78
Expect (err ).ToNot (HaveOccurred ())
73
79
74
80
By ("eventually reporting a successful resolution and bundle path" )
75
81
Eventually (func (g Gomega ) {
76
82
err = c .Get (ctx , types.NamespacedName {Name : operator .Name }, operator )
77
83
g .Expect (err ).ToNot (HaveOccurred ())
78
- g . Expect ( len ( operator . Status . Conditions )). To ( Equal ( 2 ))
84
+
79
85
cond := apimeta .FindStatusCondition (operator .Status .Conditions , operatorv1alpha1 .TypeResolved )
80
86
g .Expect (cond ).ToNot (BeNil ())
81
87
g .Expect (cond .Status ).To (Equal (metav1 .ConditionTrue ))
@@ -97,17 +103,98 @@ var _ = Describe("Operator Install", func() {
97
103
bd := rukpakv1alpha1.BundleDeployment {}
98
104
err = c .Get (ctx , types.NamespacedName {Name : operatorName }, & bd )
99
105
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 ))
116
+ }).WithTimeout (defaultTimeout ).WithPolling (defaultPoll ).Should (Succeed ())
117
+ })
118
+ 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
+
125
+ By ("creating the Operator resource" )
126
+ err := c .Create (ctx , operator )
127
+ Expect (err ).ToNot (HaveOccurred ())
128
+
129
+ By ("failing to find Operator during resolution" )
130
+ Eventually (func (g Gomega ) {
131
+ err = c .Get (ctx , types.NamespacedName {Name : operator .Name }, operator )
132
+ g .Expect (err ).ToNot (HaveOccurred ())
133
+ cond := apimeta .FindStatusCondition (operator .Status .Conditions , operatorv1alpha1 .TypeResolved )
134
+ g .Expect (cond ).ToNot (BeNil ())
135
+ g .Expect (cond .Status ).To (Equal (metav1 .ConditionFalse ))
136
+ g .Expect (cond .Reason ).To (Equal (operatorv1alpha1 .ReasonResolutionFailed ))
137
+ g .Expect (cond .Message ).To (Equal (fmt .Sprintf ("package '%s' not found" , pkgName )))
103
138
}).WithTimeout (defaultTimeout ).WithPolling (defaultPoll ).Should (Succeed ())
104
139
140
+ By ("creating an Operator catalog with the desired package" )
141
+ err = c .Create (ctx , operatorCatalog )
142
+ Expect (err ).ToNot (HaveOccurred ())
143
+ Eventually (func (g Gomega ) {
144
+ err = c .Get (ctx , types.NamespacedName {Name : operatorCatalog .Name }, operatorCatalog )
145
+ g .Expect (err ).ToNot (HaveOccurred ())
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 ))
150
+ }).WithTimeout (5 * time .Minute ).WithPolling (defaultPoll ).Should (Succeed ())
151
+
152
+ By ("eventually resolving the package successfully" )
153
+ Eventually (func (g Gomega ) {
154
+ err = c .Get (ctx , types.NamespacedName {Name : operator .Name }, operator )
155
+ g .Expect (err ).ToNot (HaveOccurred ())
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 ))
160
+ }).WithTimeout (defaultTimeout ).WithPolling (defaultPoll ).Should (Succeed ())
105
161
})
106
162
AfterEach (func () {
107
- 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 {})
108
179
Expect (err ).ToNot (HaveOccurred ())
109
- err = c .Delete (ctx , operator )
180
+ err = c .DeleteAllOf (ctx , & catalogd. Package {} )
110
181
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 ())
111
198
})
112
199
})
113
200
})
0 commit comments