Skip to content

Commit 8cc2c77

Browse files
committed
Fix: testCatalogName conflict and Explicitly set CollisionProtection to Prevent in GenerateRevision
1 parent 4355cde commit 8cc2c77

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

internal/operator-controller/applier/boxcutter.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ func (r *SimpleRevisionGenerator) GenerateRevision(
120120
sanitizedUnstructured(ctx, &unstr)
121121

122122
objs = append(objs, ocv1.ClusterExtensionRevisionObject{
123-
Object: unstr,
123+
Object: unstr,
124+
CollisionProtection: ocv1.CollisionProtectionPrevent,
124125
})
125126
}
126127

internal/operator-controller/applier/boxcutter_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func Test_SimpleRevisionGenerator_GenerateRevision(t *testing.T) {
199199
"spec": map[string]interface{}{},
200200
},
201201
},
202+
CollisionProtection: ocv1.CollisionProtectionPrevent,
202203
},
203204
{
204205
Object: unstructured.Unstructured{
@@ -227,6 +228,7 @@ func Test_SimpleRevisionGenerator_GenerateRevision(t *testing.T) {
227228
},
228229
},
229230
},
231+
CollisionProtection: ocv1.CollisionProtectionPrevent,
230232
},
231233
},
232234
},

internal/shared/util/testutils/artifacts.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/stretchr/testify/require"
1414
appsv1 "k8s.io/api/apps/v1"
1515
corev1 "k8s.io/api/core/v1"
16+
apierrors "k8s.io/apimachinery/pkg/api/errors"
1617
kubeclient "k8s.io/client-go/kubernetes"
1718
"k8s.io/client-go/rest"
1819
"k8s.io/utils/env"
@@ -71,9 +72,13 @@ func CollectTestArtifacts(t *testing.T, artifactName string, c client.Client, cf
7172
}
7273

7374
// get all cluster extension revisions save them to the artifact path.
75+
// Note: ClusterExtensionRevision is an experimental API and may not be available in all environments.
7476
clusterExtensionRevisions := ocv1.ClusterExtensionRevisionList{}
7577
if err := c.List(context.Background(), &clusterExtensionRevisions); err != nil {
76-
fmt.Printf("Failed to list cluster extensions: %v", err)
78+
// If the CRD doesn't exist (e.g., in non-experimental environments), skip this step silently
79+
if !apierrors.IsNotFound(err) && !strings.Contains(err.Error(), "no matches for kind") {
80+
fmt.Printf("Failed to list cluster extension revisions: %v\n", err)
81+
}
7782
}
7883
for _, cer := range clusterExtensionRevisions.Items {
7984
// Save cluster extension to artifact path

test/e2e/cluster_extension_install_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"os"
7+
"slices"
78
"testing"
89
"time"
910

@@ -197,7 +198,8 @@ func TestClusterExtensionInstallRegistryMultipleBundles(t *testing.T) {
197198
t.Log("When a cluster extension is installed from a catalog")
198199

199200
clusterExtension, extensionCatalog, sa, ns := TestInit(t)
200-
extraCatalog, err := CreateTestCatalog(context.Background(), "extra-test-catalog", os.Getenv(testCatalogRefEnvVar))
201+
extraCatalogName := fmt.Sprintf("extra-test-catalog-%s", rand.String(8))
202+
extraCatalog, err := CreateTestCatalog(context.Background(), extraCatalogName, os.Getenv(testCatalogRefEnvVar))
201203
require.NoError(t, err)
202204

203205
defer TestCleanup(t, extensionCatalog, clusterExtension, sa, ns)
@@ -238,7 +240,11 @@ func TestClusterExtensionInstallRegistryMultipleBundles(t *testing.T) {
238240
require.NotNil(ct, cond)
239241
require.Equal(ct, metav1.ConditionTrue, cond.Status)
240242
require.Equal(ct, ocv1.ReasonRetrying, cond.Reason)
241-
require.Contains(ct, cond.Message, "in multiple catalogs with the same priority [extra-test-catalog test-catalog]")
243+
// Catalog names are sorted alphabetically in the error message
244+
catalogs := []string{extensionCatalog.Name, extraCatalog.Name}
245+
slices.Sort(catalogs)
246+
expectedMessage := fmt.Sprintf("in multiple catalogs with the same priority %v", catalogs)
247+
require.Contains(ct, cond.Message, expectedMessage)
242248
}, pollDuration, pollInterval)
243249
}
244250

@@ -441,7 +447,7 @@ func TestClusterExtensionInstallReResolvesWhenCatalogIsPatched(t *testing.T) {
441447
// patch imageRef tag on test-catalog image with v2 image
442448
t.Log("By patching the catalog ImageRef to point to the v2 catalog")
443449
updatedCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:v2", os.Getenv("CLUSTER_REGISTRY_HOST"))
444-
err := patchTestCatalog(context.Background(), testCatalogName, updatedCatalogImage)
450+
err := patchTestCatalog(context.Background(), extensionCatalog.Name, updatedCatalogImage)
445451
require.NoError(t, err)
446452
require.EventuallyWithT(t, func(ct *assert.CollectT) {
447453
require.NoError(ct, c.Get(context.Background(), types.NamespacedName{Name: extensionCatalog.Name}, extensionCatalog))
@@ -474,8 +480,9 @@ func TestClusterExtensionInstallReResolvesWhenNewCatalog(t *testing.T) {
474480
require.NoError(t, err)
475481

476482
// create a test-catalog with latest image tag
483+
catalogName := fmt.Sprintf("test-catalog-%s", rand.String(8))
477484
latestCatalogImage := fmt.Sprintf("%s/e2e/test-catalog:latest", os.Getenv("CLUSTER_REGISTRY_HOST"))
478-
extensionCatalog, err := CreateTestCatalog(context.Background(), testCatalogName, latestCatalogImage)
485+
extensionCatalog, err := CreateTestCatalog(context.Background(), catalogName, latestCatalogImage)
479486
require.NoError(t, err)
480487
clusterExtensionName := fmt.Sprintf("clusterextension-%s", rand.String(8))
481488
clusterExtension := &ocv1.ClusterExtension{

test/helpers/helpers.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,17 +218,18 @@ func TestInit(t *testing.T) (*ocv1.ClusterExtension, *ocv1.ClusterCatalog, *core
218218

219219
func TestInitClusterExtensionClusterCatalog(t *testing.T) (*ocv1.ClusterExtension, *ocv1.ClusterCatalog) {
220220
ceName := fmt.Sprintf("clusterextension-%s", rand.String(8))
221+
catalogName := fmt.Sprintf("test-catalog-%s", rand.String(8))
221222

222223
ce := &ocv1.ClusterExtension{
223224
ObjectMeta: metav1.ObjectMeta{
224225
Name: ceName,
225226
},
226227
}
227228

228-
cc, err := CreateTestCatalog(context.Background(), testCatalogName, os.Getenv(testCatalogRefEnvVar))
229+
cc, err := CreateTestCatalog(context.Background(), catalogName, os.Getenv(testCatalogRefEnvVar))
229230
require.NoError(t, err)
230231

231-
ValidateCatalogUnpack(t)
232+
ValidateCatalogUnpackWithName(t, catalogName)
232233

233234
return ce, cc
234235
}
@@ -250,11 +251,18 @@ func TestInitServiceAccountNamespace(t *testing.T, clusterExtensionName string)
250251
return sa, ns
251252
}
252253

254+
// ValidateCatalogUnpack validates that the test catalog with the default name has unpacked successfully.
255+
// Deprecated: Use ValidateCatalogUnpackWithName for tests that use unique catalog names.
253256
func ValidateCatalogUnpack(t *testing.T) {
257+
ValidateCatalogUnpackWithName(t, testCatalogName)
258+
}
259+
260+
// ValidateCatalogUnpackWithName validates that a catalog with the given name has unpacked successfully.
261+
func ValidateCatalogUnpackWithName(t *testing.T, catalogName string) {
254262
catalog := &ocv1.ClusterCatalog{}
255263
t.Log("Ensuring ClusterCatalog has Status.Condition of Progressing with a status == True and reason == Succeeded")
256264
require.EventuallyWithT(t, func(ct *assert.CollectT) {
257-
err := c.Get(context.Background(), types.NamespacedName{Name: testCatalogName}, catalog)
265+
err := c.Get(context.Background(), types.NamespacedName{Name: catalogName}, catalog)
258266
require.NoError(ct, err)
259267
cond := apimeta.FindStatusCondition(catalog.Status.Conditions, ocv1.TypeProgressing)
260268
require.NotNil(ct, cond)
@@ -265,11 +273,11 @@ func ValidateCatalogUnpack(t *testing.T) {
265273
t.Log("Checking that catalog has the expected metadata label")
266274
require.NotNil(t, catalog.Labels)
267275
require.Contains(t, catalog.Labels, "olm.operatorframework.io/metadata.name")
268-
require.Equal(t, testCatalogName, catalog.Labels["olm.operatorframework.io/metadata.name"])
276+
require.Equal(t, catalogName, catalog.Labels["olm.operatorframework.io/metadata.name"])
269277

270278
t.Log("Ensuring ClusterCatalog has Status.Condition of Type = Serving with status == True")
271279
require.EventuallyWithT(t, func(ct *assert.CollectT) {
272-
err := c.Get(context.Background(), types.NamespacedName{Name: testCatalogName}, catalog)
280+
err := c.Get(context.Background(), types.NamespacedName{Name: catalogName}, catalog)
273281
require.NoError(ct, err)
274282
cond := apimeta.FindStatusCondition(catalog.Status.Conditions, ocv1.TypeServing)
275283
require.NotNil(ct, cond)

0 commit comments

Comments
 (0)