Skip to content

Commit 369bcce

Browse files
authored
add new e2e test - TestClusterExtensionInstallReResolvesWhenCatalogIsPatched (#1055)
Signed-off-by: yashoza19 <[email protected]>
1 parent 6e8e035 commit 369bcce

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

test/e2e/cluster_extension_install_test.go

+62
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,68 @@ func TestClusterExtensionInstallSuccessorVersion(t *testing.T) {
269269
}, pollDuration, pollInterval)
270270
}
271271

272+
func TestClusterExtensionInstallReResolvesWhenCatalogIsPatched(t *testing.T) {
273+
t.Log("When a cluster extension is installed from a catalog")
274+
t.Log("It resolves again when a catalog is patched with new ImageRef")
275+
clusterExtension, extensionCatalog := testInit(t)
276+
defer testCleanup(t, extensionCatalog, clusterExtension)
277+
defer getArtifactsOutput(t)
278+
279+
clusterExtension.Spec = ocv1alpha1.ClusterExtensionSpec{
280+
PackageName: "prometheus",
281+
InstallNamespace: "default",
282+
ServiceAccount: ocv1alpha1.ServiceAccountReference{
283+
Name: "default",
284+
},
285+
}
286+
t.Log("It resolves the specified package with correct bundle path")
287+
t.Log("By creating the ClusterExtension resource")
288+
require.NoError(t, c.Create(context.Background(), clusterExtension))
289+
290+
t.Log("By reporting a successful resolution and bundle path")
291+
require.EventuallyWithT(t, func(ct *assert.CollectT) {
292+
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
293+
assert.Len(ct, clusterExtension.Status.Conditions, len(conditionsets.ConditionTypes))
294+
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeResolved)
295+
if !assert.NotNil(ct, cond) {
296+
return
297+
}
298+
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
299+
assert.Equal(ct, ocv1alpha1.ReasonSuccess, cond.Reason)
300+
assert.Contains(ct, cond.Message, "resolved to")
301+
assert.Equal(ct, &ocv1alpha1.BundleMetadata{Name: "prometheus-operator.1.2.0", Version: "1.2.0"}, clusterExtension.Status.ResolvedBundle)
302+
}, pollDuration, pollInterval)
303+
304+
// patch imageRef tag on test-catalog image with v2 image
305+
t.Log("By patching the catalog ImageRef to point to the v2 catalog")
306+
updatedCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:v2", os.Getenv("LOCAL_REGISTRY_HOST"))
307+
err := patchTestCatalog(context.Background(), testCatalogName, updatedCatalogImage)
308+
require.NoError(t, err)
309+
require.EventuallyWithT(t, func(ct *assert.CollectT) {
310+
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: extensionCatalog.Name}, extensionCatalog))
311+
cond := apimeta.FindStatusCondition(extensionCatalog.Status.Conditions, catalogd.TypeUnpacked)
312+
if !assert.NotNil(ct, cond) {
313+
return
314+
}
315+
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
316+
assert.Equal(ct, catalogd.ReasonUnpackSuccessful, cond.Reason)
317+
}, pollDuration, pollInterval)
318+
319+
t.Log("By eventually reporting a successful resolution and bundle path")
320+
require.EventuallyWithT(t, func(ct *assert.CollectT) {
321+
assert.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: clusterExtension.Name}, clusterExtension))
322+
assert.Len(ct, clusterExtension.Status.Conditions, len(conditionsets.ConditionTypes))
323+
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeResolved)
324+
if !assert.NotNil(ct, cond) {
325+
return
326+
}
327+
assert.Equal(ct, metav1.ConditionTrue, cond.Status)
328+
assert.Equal(ct, ocv1alpha1.ReasonSuccess, cond.Reason)
329+
assert.Contains(ct, cond.Message, "resolved to")
330+
assert.Equal(ct, &ocv1alpha1.BundleMetadata{Name: "prometheus-operator.2.0.0", Version: "2.0.0"}, clusterExtension.Status.ResolvedBundle)
331+
}, pollDuration, pollInterval)
332+
}
333+
272334
func TestClusterExtensionInstallReResolvesWhenNewCatalog(t *testing.T) {
273335
t.Log("When a cluster extension is installed from a catalog")
274336
t.Log("It resolves again when a new catalog is available")

test/e2e/e2e_suite_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,26 @@ func createTestCatalog(ctx context.Context, name string, imageRef string) (*cata
6161
err := c.Create(ctx, catalog)
6262
return catalog, err
6363
}
64+
65+
// patchTestCatalog will patch the existing clusterCatalog on the test cluster, provided
66+
// the context, catalog name, and the image reference. It returns an error
67+
// if any errors occurred while updating the catalog.
68+
func patchTestCatalog(ctx context.Context, name string, newImageRef string) error {
69+
// Fetch the existing ClusterCatalog
70+
catalog := &catalogd.ClusterCatalog{}
71+
err := c.Get(ctx, client.ObjectKey{Name: name}, catalog)
72+
if err != nil {
73+
return err
74+
}
75+
76+
// Update the ImageRef
77+
catalog.Spec.Source.Image.Ref = newImageRef
78+
79+
// Patch the ClusterCatalog
80+
err = c.Update(ctx, catalog)
81+
if err != nil {
82+
return err
83+
}
84+
85+
return err
86+
}

0 commit comments

Comments
 (0)