From b135d1dcba46d68345b7e61064a84a534b0616b3 Mon Sep 17 00:00:00 2001 From: aleskandro Date: Tue, 23 Jul 2024 18:03:26 -0400 Subject: [PATCH] Fix Makefile install-strategies target for non-cluster-scoped objects and E2E cases When objects are not cluster-scoped, like rolebindings or local build strategies, if the TEST_NAMESPACE variable is set, the objects should be applied to that given namespace. If not, apply to the current context's namespace. Some test cases were also implementing with an additional creation step for the same buildstrategies defined in the same folder recursively applied by the install-strategies target. This commit deletes those function calls to rely on the Makefile target for creating the non-cluster-scoped build strategies too. --- Makefile | 3 ++- test/e2e/v1alpha1/e2e_test.go | 16 ---------------- test/e2e/v1alpha1/validators_test.go | 13 ------------- test/e2e/v1beta1/e2e_test.go | 14 -------------- test/e2e/v1beta1/validators_test.go | 13 ------------- 5 files changed, 2 insertions(+), 57 deletions(-) diff --git a/Makefile b/Makefile index 794ea8cdc1..f45876f24d 100644 --- a/Makefile +++ b/Makefile @@ -274,7 +274,8 @@ install-controller-kind: install-apis .PHONY: install-strategies install-strategies: install-apis - kubectl apply -R -f samples/v1beta1/buildstrategy/ + [ -n "${TEST_NAMESPACE}" ] && ADDITIONAL_PARAMS="-n ${TEST_NAMESPACE}"; \ + kubectl apply $$ADDITIONAL_PARAMS -R -f samples/v1beta1/buildstrategy/ .PHONY: local local: install-strategies diff --git a/test/e2e/v1alpha1/e2e_test.go b/test/e2e/v1alpha1/e2e_test.go index f1d165384a..2b325ac075 100644 --- a/test/e2e/v1alpha1/e2e_test.go +++ b/test/e2e/v1alpha1/e2e_test.go @@ -140,17 +140,10 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) Context("when a heroku Buildpacks build is defined using a namespaced strategy", func() { - var buildStrategy *buildv1alpha1.BuildStrategy BeforeEach(func() { testID = generateTestID("buildpacks-v3-heroku-namespaced") - buildStrategy, err = buildStrategyTestData(testBuild.Namespace, "samples/v1alpha1/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_namespaced_cr.yaml") - Expect(err).ToNot(HaveOccurred()) - - err = testBuild.CreateBuildStrategy(buildStrategy) - Expect(err).ToNot(HaveOccurred()) - // create the build definition build = createBuild( testBuild, @@ -169,7 +162,6 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) AfterEach(func() { - err = testBuild.DeleteBuildStrategy(buildStrategy.Name) Expect(err).ToNot(HaveOccurred()) }) }) @@ -198,17 +190,10 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) Context("when a Buildpacks v3 build is defined using a namespaced strategy", func() { - var buildStrategy *buildv1alpha1.BuildStrategy BeforeEach(func() { testID = generateTestID("buildpacks-v3-namespaced") - buildStrategy, err = buildStrategyTestData(testBuild.Namespace, "samples/v1alpha1/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_namespaced_cr.yaml") - Expect(err).ToNot(HaveOccurred()) - - err = testBuild.CreateBuildStrategy(buildStrategy) - Expect(err).ToNot(HaveOccurred()) - // create the build definition build = createBuild( testBuild, @@ -226,7 +211,6 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) AfterEach(func() { - err = testBuild.DeleteBuildStrategy(buildStrategy.Name) Expect(err).ToNot(HaveOccurred()) }) }) diff --git a/test/e2e/v1alpha1/validators_test.go b/test/e2e/v1alpha1/validators_test.go index 4ec185782b..db433ddb14 100644 --- a/test/e2e/v1alpha1/validators_test.go +++ b/test/e2e/v1alpha1/validators_test.go @@ -292,19 +292,6 @@ func readAndDecode(filePath string) (runtime.Object, error) { return obj, err } -// buildStrategyTestData gets the us the BuildStrategy test data set up -func buildStrategyTestData(ns string, buildStrategyCRPath string) (*buildv1alpha1.BuildStrategy, error) { - obj, err := readAndDecode(buildStrategyCRPath) - if err != nil { - return nil, err - } - - buildStrategy := obj.(*buildv1alpha1.BuildStrategy) - buildStrategy.SetNamespace(ns) - - return buildStrategy, err -} - func buildTestData(namespace string, identifier string, filePath string) (*buildv1alpha1.Build, error) { obj, err := readAndDecode(filePath) if err != nil { diff --git a/test/e2e/v1beta1/e2e_test.go b/test/e2e/v1beta1/e2e_test.go index 573eca1494..4edb4d61c6 100644 --- a/test/e2e/v1beta1/e2e_test.go +++ b/test/e2e/v1beta1/e2e_test.go @@ -144,12 +144,6 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun BeforeEach(func() { testID = generateTestID("buildpacks-v3-heroku-namespaced") - buildStrategy, err = buildStrategyTestData(testBuild.Namespace, "samples/v1beta1/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3-heroku_namespaced_cr.yaml") - Expect(err).ToNot(HaveOccurred()) - - err = testBuild.CreateBuildStrategy(buildStrategy) - Expect(err).ToNot(HaveOccurred()) - // create the build definition build = createBuild( testBuild, @@ -197,17 +191,10 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) Context("when a Buildpacks v3 build is defined using a namespaced strategy", func() { - var buildStrategy *buildv1beta1.BuildStrategy BeforeEach(func() { testID = generateTestID("buildpacks-v3-namespaced") - buildStrategy, err = buildStrategyTestData(testBuild.Namespace, "samples/v1beta1/buildstrategy/buildpacks-v3/buildstrategy_buildpacks-v3_namespaced_cr.yaml") - Expect(err).ToNot(HaveOccurred()) - - err = testBuild.CreateBuildStrategy(buildStrategy) - Expect(err).ToNot(HaveOccurred()) - // create the build definition build = createBuild( testBuild, @@ -225,7 +212,6 @@ var _ = Describe("For a Kubernetes cluster with Tekton and build installed", fun }) AfterEach(func() { - err = testBuild.DeleteBuildStrategy(buildStrategy.Name) Expect(err).ToNot(HaveOccurred()) }) }) diff --git a/test/e2e/v1beta1/validators_test.go b/test/e2e/v1beta1/validators_test.go index 3e1c17c737..c80f27a324 100644 --- a/test/e2e/v1beta1/validators_test.go +++ b/test/e2e/v1beta1/validators_test.go @@ -294,19 +294,6 @@ func readAndDecode(filePath string) (runtime.Object, error) { return obj, err } -// buildStrategyTestData gets the us the BuildStrategy test data set up -func buildStrategyTestData(ns string, buildStrategyCRPath string) (*buildv1beta1.BuildStrategy, error) { - obj, err := readAndDecode(buildStrategyCRPath) - if err != nil { - return nil, err - } - - buildStrategy := obj.(*buildv1beta1.BuildStrategy) - buildStrategy.SetNamespace(ns) - - return buildStrategy, err -} - func buildTestData(namespace string, identifier string, filePath string) (*buildv1beta1.Build, error) { obj, err := readAndDecode(filePath) if err != nil {