diff --git a/tests/envtestutil/name_gen.go b/tests/envtestutil/name_gen.go index 44d39681282..de24301d023 100644 --- a/tests/envtestutil/name_gen.go +++ b/tests/envtestutil/name_gen.go @@ -16,5 +16,5 @@ func AppendRandomNameTo(base string) string { if len(base) > maxGeneratedNameLength { base = base[:maxGeneratedNameLength] } - return fmt.Sprintf("%s%s", base, utilrand.String(randomLength)) + return fmt.Sprintf("%s-%s", base, utilrand.String(randomLength)) } diff --git a/tests/integration/features/cleanup_int_test.go b/tests/integration/features/cleanup_int_test.go index 9e2d6103b03..54f17d1fb3d 100644 --- a/tests/integration/features/cleanup_int_test.go +++ b/tests/integration/features/cleanup_int_test.go @@ -28,14 +28,17 @@ var _ = Describe("feature cleanup", func() { ) var ( - dsci *dsciv1.DSCInitialization - namespace string - testFeature *feature.Feature + dsci *dsciv1.DSCInitialization + namespace string + testFeature *feature.Feature + objectCleaner *envtestutil.Cleaner ) BeforeEach(func(ctx context.Context) { + objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, fixtures.Timeout, fixtures.Interval) namespace = envtestutil.AppendRandomNameTo("test-secret-ownership") - dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace) + dsciName := envtestutil.AppendRandomNameTo("secret-dsci") + dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace) var errSecretCreation error testFeature, errSecretCreation = feature.Define(featureName). TargetNamespace(dsci.Spec.ApplicationsNamespace). @@ -54,6 +57,10 @@ var _ = Describe("feature cleanup", func() { }) + AfterEach(func(ctx context.Context) { + objectCleaner.DeleteAll(ctx, dsci) + }) + It("should successfully create resource and associated feature tracker", func(ctx context.Context) { // when Expect(testFeature.Apply(ctx)).Should(Succeed()) @@ -95,7 +102,8 @@ var _ = Describe("feature cleanup", func() { BeforeAll(func(ctx context.Context) { namespace = envtestutil.AppendRandomNameTo("test-conditional-cleanup") - dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace) + dsciName := envtestutil.AppendRandomNameTo("cleanup-dsci") + dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace) }) It("should create feature, apply resource and create feature tracker", func(ctx context.Context) { diff --git a/tests/integration/features/fixtures/cluster_test_fixtures.go b/tests/integration/features/fixtures/cluster_test_fixtures.go index 5105b5bda89..0dc13dc8255 100644 --- a/tests/integration/features/fixtures/cluster_test_fixtures.go +++ b/tests/integration/features/fixtures/cluster_test_fixtures.go @@ -107,14 +107,14 @@ func GetFeatureTracker(ctx context.Context, cli client.Client, appNamespace, fea return tracker, err } -func NewDSCInitialization(ctx context.Context, cli client.Client, ns string) *dsciv1.DSCInitialization { +func NewDSCInitialization(ctx context.Context, cli client.Client, dsciName, ns string) *dsciv1.DSCInitialization { dsci := &dsciv1.DSCInitialization{ TypeMeta: metav1.TypeMeta{ APIVersion: gvk.DSCInitialization.Version, Kind: gvk.DSCInitialization.Kind, }, ObjectMeta: metav1.ObjectMeta{ - Name: "default-dsci", + Name: dsciName, }, } diff --git a/tests/integration/features/manifests_int_test.go b/tests/integration/features/manifests_int_test.go index 196140a98d8..0575bcbfad7 100644 --- a/tests/integration/features/manifests_int_test.go +++ b/tests/integration/features/manifests_int_test.go @@ -29,18 +29,19 @@ var _ = Describe("Applying resources", func() { BeforeEach(func(ctx context.Context) { objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, fixtures.Timeout, fixtures.Interval) - nsName := envtestutil.AppendRandomNameTo("smcp-ns") + nsName := envtestutil.AppendRandomNameTo("ns-smcp") + dsciName := envtestutil.AppendRandomNameTo("dsci-smcp") var err error namespace, err = cluster.CreateNamespace(ctx, envTestClient, nsName) Expect(err).ToNot(HaveOccurred()) - dsci = fixtures.NewDSCInitialization(ctx, envTestClient, nsName) + dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, nsName) dsci.Spec.ServiceMesh.ControlPlane.Namespace = namespace.Name }) AfterEach(func(ctx context.Context) { - objectCleaner.DeleteAll(ctx, namespace) + objectCleaner.DeleteAll(ctx, namespace, dsci) }) It("should be able to process an embedded YAML file", func(ctx context.Context) { diff --git a/tests/integration/features/preconditions_int_test.go b/tests/integration/features/preconditions_int_test.go index dae5aacc5a9..b5d620b18e0 100644 --- a/tests/integration/features/preconditions_int_test.go +++ b/tests/integration/features/preconditions_int_test.go @@ -31,7 +31,12 @@ var _ = Describe("feature preconditions", func() { testFeatureName := "test-ns-creation" namespace = envtestutil.AppendRandomNameTo(testFeatureName) - dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace) + dsciName := envtestutil.AppendRandomNameTo(testFeatureName) + dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace) + }) + + AfterEach(func(ctx context.Context) { + objectCleaner.DeleteAll(ctx, dsci) }) It("should create namespace if it does not exist", func(ctx context.Context) { diff --git a/tests/integration/features/resources_int_test.go b/tests/integration/features/resources_int_test.go index 3068c511905..c8dc1219b1a 100644 --- a/tests/integration/features/resources_int_test.go +++ b/tests/integration/features/resources_int_test.go @@ -37,17 +37,18 @@ var _ = Describe("Applying and updating resources", func() { objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, fixtures.Timeout, fixtures.Interval) testNamespace = envtestutil.AppendRandomNameTo("test-namespace") + dsciName := envtestutil.AppendRandomNameTo("test-dsci") var err error namespace, err = cluster.CreateNamespace(ctx, envTestClient, testNamespace) Expect(err).ToNot(HaveOccurred()) - dsci = fixtures.NewDSCInitialization(ctx, envTestClient, testNamespace) + dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, testNamespace) dsci.Spec.ServiceMesh.ControlPlane.Namespace = namespace.Name }) AfterEach(func(ctx context.Context) { - objectCleaner.DeleteAll(ctx, namespace) + objectCleaner.DeleteAll(ctx, namespace, dsci) }) When("a feature is managed", func() { diff --git a/tests/integration/features/serverless_feature_test.go b/tests/integration/features/serverless_feature_test.go index 9258aa78d10..9e6db931dd3 100644 --- a/tests/integration/features/serverless_feature_test.go +++ b/tests/integration/features/serverless_feature_test.go @@ -40,7 +40,9 @@ var _ = Describe("Serverless feature", func() { Expect(err).ToNot(HaveOccurred()) objectCleaner = envtestutil.CreateCleaner(c, envTest.Config, fixtures.Timeout, fixtures.Interval) - dsci = fixtures.NewDSCInitialization(ctx, envTestClient, "default") + namespace := envtestutil.AppendRandomNameTo("ns-serverless") + dsciName := envtestutil.AppendRandomNameTo("dsci-serverless") + dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace) kserveComponent = &kserve.Kserve{} }) diff --git a/tests/integration/features/servicemesh_feature_test.go b/tests/integration/features/servicemesh_feature_test.go index 45a3bbc62b2..43c0a3b8d0b 100644 --- a/tests/integration/features/servicemesh_feature_test.go +++ b/tests/integration/features/servicemesh_feature_test.go @@ -38,8 +38,9 @@ var _ = Describe("Service Mesh setup", func() { objectCleaner = envtestutil.CreateCleaner(c, envTest.Config, fixtures.Timeout, fixtures.Interval) namespace := envtestutil.AppendRandomNameTo("service-mesh-settings") + dsciName := envtestutil.AppendRandomNameTo("service-mesh-settings") - dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace) + dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, namespace) Expect(err).ToNot(HaveOccurred()) }) @@ -172,7 +173,7 @@ var _ = Describe("Service Mesh setup", func() { BeforeEach(func(ctx context.Context) { smcpCrdObj = installServiceMeshCRD(ctx) objectCleaner = envtestutil.CreateCleaner(envTestClient, envTest.Config, fixtures.Timeout, fixtures.Interval) - dsci = fixtures.NewDSCInitialization(ctx, envTestClient, namespace) + dsci = fixtures.NewDSCInitialization(ctx, envTestClient, envtestutil.AppendRandomNameTo(namespace), namespace) serviceMeshSpec = dsci.Spec.ServiceMesh diff --git a/tests/integration/features/tracker_int_test.go b/tests/integration/features/tracker_int_test.go index 6a05096b790..370bfe25117 100644 --- a/tests/integration/features/tracker_int_test.go +++ b/tests/integration/features/tracker_int_test.go @@ -11,6 +11,7 @@ import ( featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1" "github.com/opendatahub-io/opendatahub-operator/v2/controllers/status" "github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature" + "github.com/opendatahub-io/opendatahub-operator/v2/tests/envtestutil" "github.com/opendatahub-io/opendatahub-operator/v2/tests/integration/features/fixtures" . "github.com/onsi/ginkgo/v2" @@ -20,14 +21,15 @@ import ( var _ = Describe("Feature tracking capability", func() { - const appNamespace = "default" - var ( - dsci *dsciv1.DSCInitialization + appNamespace string + dsci *dsciv1.DSCInitialization ) BeforeEach(func(ctx context.Context) { - dsci = fixtures.NewDSCInitialization(ctx, envTestClient, "default") + appNamespace = envtestutil.AppendRandomNameTo("app-namespace") + dsciName := envtestutil.AppendRandomNameTo("dsci-" + appNamespace) + dsci = fixtures.NewDSCInitialization(ctx, envTestClient, dsciName, appNamespace) }) Context("Reporting progress when applying Feature", func() { @@ -138,7 +140,7 @@ var _ = Describe("Feature tracking capability", func() { Expect(err).ToNot(HaveOccurred()) Expect(featureTracker.Spec.Source).To( MatchFields(IgnoreExtras, Fields{ - "Name": Equal("default-dsci"), + "Name": Equal(dsci.Name), "Type": Equal(featurev1.DSCIType), }), ) @@ -160,7 +162,7 @@ var _ = Describe("Feature tracking capability", func() { // then featureTracker, err := fixtures.GetFeatureTracker(ctx, envTestClient, appNamespace, "empty-feature") Expect(err).ToNot(HaveOccurred()) - Expect(featureTracker.Spec.AppNamespace).To(Equal("default")) + Expect(featureTracker.Spec.AppNamespace).To(Equal(dsci.Spec.ApplicationsNamespace)) }) })