@@ -10,6 +10,7 @@ import (
10
10
"testing"
11
11
"time"
12
12
13
+ "github.com/google/go-containerregistry/pkg/crane"
13
14
"github.com/stretchr/testify/assert"
14
15
"github.com/stretchr/testify/require"
15
16
"gopkg.in/yaml.v2"
@@ -94,7 +95,7 @@ func TestClusterExtensionInstallRegistry(t *testing.T) {
94
95
assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
95
96
assert .Equal (ct , ocv1alpha1 .ReasonSuccess , cond .Reason )
96
97
assert .Contains (ct , cond .Message , "resolved to" )
97
- assert .Equal (ct , & ocv1alpha1.BundleMetadata {Name : "prometheus-operator.2.0.0 " , Version : "2.0 .0" }, clusterExtension .Status .ResolvedBundle )
98
+ assert .Equal (ct , & ocv1alpha1.BundleMetadata {Name : "prometheus-operator.1. 2.0" , Version : "1.2 .0" }, clusterExtension .Status .ResolvedBundle )
98
99
}, pollDuration , pollInterval )
99
100
100
101
t .Log ("By eventually reporting a successful unpacked" )
@@ -123,75 +124,6 @@ func TestClusterExtensionInstallRegistry(t *testing.T) {
123
124
}, pollDuration , pollInterval )
124
125
}
125
126
126
- func TestClusterExtensionInstallReResolvesWhenNewCatalog (t * testing.T ) {
127
- t .Log ("When a cluster extension is installed from a catalog" )
128
- t .Log ("It resolves again when a new catalog is available" )
129
-
130
- clusterExtension , extensionCatalog := testInit (t )
131
- defer testCleanup (t , extensionCatalog , clusterExtension )
132
- defer getArtifactsOutput (t )
133
-
134
- pkgName := "prometheus"
135
- clusterExtension .Spec = ocv1alpha1.ClusterExtensionSpec {
136
- PackageName : pkgName ,
137
- InstallNamespace : "default" ,
138
- ServiceAccount : ocv1alpha1.ServiceAccountReference {
139
- Name : "default" ,
140
- },
141
- }
142
-
143
- t .Log ("By deleting the catalog first" )
144
- require .NoError (t , c .Delete (context .Background (), extensionCatalog ))
145
- require .EventuallyWithT (t , func (ct * assert.CollectT ) {
146
- err := c .Get (context .Background (), types.NamespacedName {Name : extensionCatalog .Name }, & catalogd.ClusterCatalog {})
147
- assert .True (ct , errors .IsNotFound (err ))
148
- }, pollDuration , pollInterval )
149
-
150
- t .Log ("By creating the ClusterExtension resource" )
151
- require .NoError (t , c .Create (context .Background (), clusterExtension ))
152
-
153
- // TODO: this isn't a good precondition because a missing package results in
154
- // exponential backoff retries. So we can't be sure that the re-reconcile is a result of
155
- // the catalog becoming available because it could also be a retry of the initial failed
156
- // resolution.
157
- t .Log ("By failing to find ClusterExtension during resolution" )
158
- require .EventuallyWithT (t , func (ct * assert.CollectT ) {
159
- assert .NoError (ct , c .Get (context .Background (), types.NamespacedName {Name : clusterExtension .Name }, clusterExtension ))
160
- cond := apimeta .FindStatusCondition (clusterExtension .Status .Conditions , ocv1alpha1 .TypeResolved )
161
- if ! assert .NotNil (ct , cond ) {
162
- return
163
- }
164
- assert .Equal (ct , metav1 .ConditionFalse , cond .Status )
165
- assert .Equal (ct , ocv1alpha1 .ReasonResolutionFailed , cond .Reason )
166
- assert .Contains (ct , cond .Message , fmt .Sprintf ("no package %q found" , pkgName ))
167
- }, pollDuration , pollInterval )
168
-
169
- t .Log ("By creating an ClusterExtension catalog with the desired package" )
170
- var err error
171
- extensionCatalog , err = createTestCatalog (context .Background (), testCatalogName , os .Getenv (testCatalogRefEnvVar ))
172
- require .NoError (t , err )
173
- require .EventuallyWithT (t , func (ct * assert.CollectT ) {
174
- assert .NoError (ct , c .Get (context .Background (), types.NamespacedName {Name : extensionCatalog .Name }, extensionCatalog ))
175
- cond := apimeta .FindStatusCondition (extensionCatalog .Status .Conditions , catalogd .TypeUnpacked )
176
- if ! assert .NotNil (ct , cond ) {
177
- return
178
- }
179
- assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
180
- assert .Equal (ct , catalogd .ReasonUnpackSuccessful , cond .Reason )
181
- }, pollDuration , pollInterval )
182
-
183
- t .Log ("By eventually resolving the package successfully" )
184
- require .EventuallyWithT (t , func (ct * assert.CollectT ) {
185
- assert .NoError (ct , c .Get (context .Background (), types.NamespacedName {Name : clusterExtension .Name }, clusterExtension ))
186
- cond := apimeta .FindStatusCondition (clusterExtension .Status .Conditions , ocv1alpha1 .TypeResolved )
187
- if ! assert .NotNil (ct , cond ) {
188
- return
189
- }
190
- assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
191
- assert .Equal (ct , ocv1alpha1 .ReasonSuccess , cond .Reason )
192
- }, pollDuration , pollInterval )
193
- }
194
-
195
127
func TestClusterExtensionBlockInstallNonSuccessorVersion (t * testing.T ) {
196
128
t .Log ("When a cluster extension is installed from a catalog" )
197
129
t .Log ("When resolving upgrade edges" )
@@ -337,6 +269,84 @@ func TestClusterExtensionInstallSuccessorVersion(t *testing.T) {
337
269
}, pollDuration , pollInterval )
338
270
}
339
271
272
+ func TestClusterExtensionInstallReResolvesWhenNewCatalog (t * testing.T ) {
273
+ t .Log ("When a cluster extension is installed from a catalog" )
274
+ t .Log ("It resolves again when a new catalog is available" )
275
+
276
+ // Tag the image with the new tag
277
+ var err error
278
+ v1Image := fmt .Sprintf ("%s/%s" , os .Getenv ("CLUSTER_REGISTRY_HOST" ), os .Getenv ("E2E_TEST_CATALOG_V1" ))
279
+ err = crane .Tag (v1Image , latestImageTag , crane .Insecure )
280
+ require .NoError (t , err )
281
+
282
+ // create a test-catalog with latest image tag
283
+ latestCatalogImage := fmt .Sprintf ("%s/e2e/test-catalog:latest" , os .Getenv ("LOCAL_REGISTRY_HOST" ))
284
+ extensionCatalog , err := createTestCatalog (context .Background (), testCatalogName , latestCatalogImage )
285
+ require .NoError (t , err )
286
+ clusterExtensionName := fmt .Sprintf ("clusterextension-%s" , rand .String (8 ))
287
+ clusterExtension := & ocv1alpha1.ClusterExtension {
288
+ ObjectMeta : metav1.ObjectMeta {
289
+ Name : clusterExtensionName ,
290
+ },
291
+ }
292
+ defer testCleanup (t , extensionCatalog , clusterExtension )
293
+ defer getArtifactsOutput (t )
294
+
295
+ clusterExtension .Spec = ocv1alpha1.ClusterExtensionSpec {
296
+ PackageName : "prometheus" ,
297
+ InstallNamespace : "default" ,
298
+ ServiceAccount : ocv1alpha1.ServiceAccountReference {
299
+ Name : "default" ,
300
+ },
301
+ }
302
+ t .Log ("It resolves the specified package with correct bundle path" )
303
+ t .Log ("By creating the ClusterExtension resource" )
304
+ require .NoError (t , c .Create (context .Background (), clusterExtension ))
305
+
306
+ t .Log ("By reporting a successful resolution and bundle path" )
307
+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
308
+ assert .NoError (ct , c .Get (context .Background (), types.NamespacedName {Name : clusterExtension .Name }, clusterExtension ))
309
+ assert .Len (ct , clusterExtension .Status .Conditions , len (conditionsets .ConditionTypes ))
310
+ cond := apimeta .FindStatusCondition (clusterExtension .Status .Conditions , ocv1alpha1 .TypeResolved )
311
+ if ! assert .NotNil (ct , cond ) {
312
+ return
313
+ }
314
+ assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
315
+ assert .Equal (ct , ocv1alpha1 .ReasonSuccess , cond .Reason )
316
+ assert .Contains (ct , cond .Message , "resolved to" )
317
+ assert .Equal (ct , & ocv1alpha1.BundleMetadata {Name : "prometheus-operator.1.2.0" , Version : "1.2.0" }, clusterExtension .Status .ResolvedBundle )
318
+ }, pollDuration , pollInterval )
319
+
320
+ // update tag on test-catalog image with v2 image
321
+ t .Log ("By updating the catalog tag to point to the v2 catalog" )
322
+ v2Image := fmt .Sprintf ("%s/%s" , os .Getenv ("CLUSTER_REGISTRY_HOST" ), os .Getenv ("E2E_TEST_CATALOG_V2" ))
323
+ err = crane .Tag (v2Image , latestImageTag , crane .Insecure )
324
+ require .NoError (t , err )
325
+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
326
+ assert .NoError (ct , c .Get (context .Background (), types.NamespacedName {Name : extensionCatalog .Name }, extensionCatalog ))
327
+ cond := apimeta .FindStatusCondition (extensionCatalog .Status .Conditions , catalogd .TypeUnpacked )
328
+ if ! assert .NotNil (ct , cond ) {
329
+ return
330
+ }
331
+ assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
332
+ assert .Equal (ct , catalogd .ReasonUnpackSuccessful , cond .Reason )
333
+ }, pollDuration , pollInterval )
334
+
335
+ t .Log ("By eventually reporting a successful resolution and bundle path" )
336
+ require .EventuallyWithT (t , func (ct * assert.CollectT ) {
337
+ assert .NoError (ct , c .Get (context .Background (), types.NamespacedName {Name : clusterExtension .Name }, clusterExtension ))
338
+ assert .Len (ct , clusterExtension .Status .Conditions , len (conditionsets .ConditionTypes ))
339
+ cond := apimeta .FindStatusCondition (clusterExtension .Status .Conditions , ocv1alpha1 .TypeResolved )
340
+ if ! assert .NotNil (ct , cond ) {
341
+ return
342
+ }
343
+ assert .Equal (ct , metav1 .ConditionTrue , cond .Status )
344
+ assert .Equal (ct , ocv1alpha1 .ReasonSuccess , cond .Reason )
345
+ assert .Contains (ct , cond .Message , "resolved to" )
346
+ assert .Equal (ct , & ocv1alpha1.BundleMetadata {Name : "prometheus-operator.2.0.0" , Version : "2.0.0" }, clusterExtension .Status .ResolvedBundle )
347
+ }, pollDuration , pollInterval )
348
+ }
349
+
340
350
// getArtifactsOutput gets all the artifacts from the test run and saves them to the artifact path.
341
351
// Currently it saves:
342
352
// - clusterextensions
0 commit comments