diff --git a/tests/release/const.go b/tests/release/const.go new file mode 100644 index 000000000..7476cc163 --- /dev/null +++ b/tests/release/const.go @@ -0,0 +1,50 @@ +package constants + +import ( + "github.com/redhat-appstudio/e2e-tests/pkg/utils" + corev1 "k8s.io/api/core/v1" + "time" +) + +const ( + ApplicationNameDefault string = "appstudio" + ReleaseStrategyPolicyDefault string = "mvp-policy" + ReleaseStrategyPolicy string = "policy" + + RedhatAppstudioUserSecret string = "hacbs-release-tests-token" + HacbsReleaseTestsTokenSecret string = "redhat-appstudio-registry-pull-secret" + PublicSecretNameAuth string = "cosign-public-key" + ReleasePipelineServiceAccountDefault string = "release-service-account" + + SourceReleasePlanName string = "source-releaseplan" + TargetReleasePlanAdmissionName string = "demo" + ReleasePvcName string = "release-pvc" + ReleaseEnvironment string = "production" + + ReleaseCreationTimeout = 5 * time.Minute + ReleasePipelineRunCreationTimeout = 10 * time.Minute + ReleasePipelineRunCompletionTimeout = 20 * time.Minute + DefaultInterval = 100 * time.Millisecond + + // Pipelines constants + ComponentName string = "dc-metro-map" + GitSourceComponentUrl string = "https://github.com/scoheb/dc-metro-map" + AdditionalComponentName string = "simple-python" + AdditionalGitSourceComponentUrl string = "https://github.com/devfile-samples/devfile-sample-python-basic" + ReleasedImagePushRepo string = "quay.io/redhat-appstudio-qe/dcmetromap" + AdditionalReleasedImagePushRepo string = "quay.io/redhat-appstudio-qe/simplepython" + PyxisStageImagesApiEndpoint string = "https://pyxis.preprod.api.redhat.com/v1/images/id/" + + // Service constants + ApplicationName string = "application" +) + +var ManagednamespaceSecret = []corev1.ObjectReference{ + {Name: RedhatAppstudioUserSecret}, +} + +// Pipelines variables +var ( + RelSvcCatalogURL string = utils.GetEnv("RELEASE_SERVICE_CATALOG_URL", "https://github.com/redhat-appstudio/release-service-catalog") + RelSvcCatalogRevision string = utils.GetEnv("RELEASE_SERVICE_CATALOG_REVISION", "main") +) diff --git a/tests/release/pipelines/const.go b/tests/release/pipelines/const.go deleted file mode 100644 index 75464a284..000000000 --- a/tests/release/pipelines/const.go +++ /dev/null @@ -1,49 +0,0 @@ -package pipelines - -import ( - "time" - - "github.com/redhat-appstudio/e2e-tests/pkg/constants" - "github.com/redhat-appstudio/e2e-tests/pkg/utils" - corev1 "k8s.io/api/core/v1" -) - -const ( - serviceAccount = constants.DefaultPipelineServiceAccount - applicationNameDefault string = "appstudio" - componentName string = "dc-metro-map" - releaseStrategyPolicyDefault string = "mvp-policy" - releaseStrategyServiceAccountDefault string = "release-service-account" - sourceReleasePlanName string = "source-releaseplan" - targetReleasePlanAdmissionName string = "demo" - releasePvcName string = "release-pvc" - releaseEnvironment string = "production" - redhatAppstudioUserSecret string = "hacbs-release-tests-token" - hacbsReleaseTestsTokenSecret string = "redhat-appstudio-registry-pull-secret" - publicSecretNameAuth string = "cosign-public-key" - gitSourceComponentUrl string = "https://github.com/scoheb/dc-metro-map" - releasedImagePushRepo string = "quay.io/redhat-appstudio-qe/dcmetromap" - additionalReleasedImagePushRepo string = "quay.io/redhat-appstudio-qe/simplepython" - - additionalComponentName string = "simple-python" - additionalGitSourceComponentUrl string = "https://github.com/devfile-samples/devfile-sample-python-basic" - pyxisStageImagesApiEndpoint string = "https://pyxis.preprod.api.redhat.com/v1/images/id/" - snapshotCreationTimeout = 5 * time.Minute - releaseCreationTimeout = 5 * time.Minute - releasePipelineRunCreationTimeout = 10 * time.Minute - releasePipelineRunCompletionTimeout = 20 * time.Minute - avgControllerQueryTimeout = 5 * time.Minute - releaseDeploymentTimeout = 10 * time.Minute - releaseFinishedTimeout = 5 * time.Minute - - defaultInterval = 100 * time.Millisecond -) - -var ( - relSvcCatalogURL string = utils.GetEnv("RELEASE_SERVICE_CATALOG_URL", "https://github.com/redhat-appstudio/release-service-catalog") - relSvcCatalogRevision string = utils.GetEnv("RELEASE_SERVICE_CATALOG_REVISION", "main") -) - -var managednamespaceSecret = []corev1.ObjectReference{ - {Name: redhatAppstudioUserSecret}, -} diff --git a/tests/release/pipelines/fbc_release.go b/tests/release/pipelines/fbc_release.go index aab59c9bb..4e6118512 100644 --- a/tests/release/pipelines/fbc_release.go +++ b/tests/release/pipelines/fbc_release.go @@ -15,6 +15,8 @@ import ( "github.com/redhat-appstudio/e2e-tests/pkg/framework" "github.com/redhat-appstudio/e2e-tests/pkg/utils" "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" + releaseConst "github.com/redhat-appstudio/e2e-tests/tests/release" + releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" tektonutils "github.com/redhat-appstudio/release-service/tekton/utils" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" @@ -43,9 +45,6 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[RHTAPREL-373]fbc happy path e2 var managedWorkspace = os.Getenv(constants.RELEASE_MANAGED_WORKSPACE_ENV) var devNamespace = devWorkspace + "-tenant" var managedNamespace = managedWorkspace + "-tenant" - var releasePipelineRunCompletionTimeout = 20 * time.Minute - var releaseCreationTimeout = 5 * time.Minute - var defaultInterval = 100 * time.Millisecond var err error var devFw *framework.Framework @@ -114,8 +113,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[RHTAPREL-373]fbc happy path e2 _, err = managedFw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(fbcReleasePlanAdmissionName, managedNamespace, "", devNamespace, fbcEnterpriseContractPolicyName, fbcServiceAccountName, []string{fbcApplicationName}, true, &tektonutils.PipelineRef{ Resolver: "git", Params: []tektonutils.Param{ - {Name: "url", Value: relSvcCatalogURL}, - {Name: "revision", Value: relSvcCatalogRevision}, + {Name: "url", Value: releaseConst.RelSvcCatalogURL}, + {Name: "revision", Value: releaseConst.RelSvcCatalogRevision}, {Name: "pathInRepo", Value: relSvcCatalogPathInRepo}, }, }, &runtime.RawExtension{ @@ -123,7 +122,6 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[RHTAPREL-373]fbc happy path e2 }) Expect(err).NotTo(HaveOccurred()) - defaultEcPolicySpec := ecp.EnterpriseContractPolicySpec{ Description: "Red Hat's enterprise requirements", PublicKey: "k8s://openshift-pipelines/public-key", @@ -138,10 +136,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[RHTAPREL-373]fbc happy path e2 Include: []string{"@slsa3"}, }, } - _, err = managedFw.AsKubeDeveloper.TektonController.CreateEnterpriseContractPolicy(fbcEnterpriseContractPolicyName, managedNamespace, defaultEcPolicySpec) Expect(err).NotTo(HaveOccurred()) - }) AfterAll(func() { @@ -177,7 +173,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[RHTAPREL-373]fbc happy path e2 GinkgoWriter.Println("Release PR: ", releasePr.Name) Expect(tekton.HasPipelineRunSucceeded(releasePr)).To(BeTrue(), fmt.Sprintf("release pipelinerun %s/%s did not succeed", releasePr.GetNamespace(), releasePr.GetName())) return nil - }, releasePipelineRunCompletionTimeout, defaultInterval).Should(Succeed(), "timed out when waiting for release pipelinerun to succeed") + }, releaseConst.ReleasePipelineRunCompletionTimeout, releaseConst.DefaultInterval).Should(Succeed(), "timed out when waiting for release pipelinerun to succeed") }) It("verifies release CR completed and set succeeded.", func() { @@ -191,7 +187,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[RHTAPREL-373]fbc happy path e2 return fmt.Errorf("release %s/%s is not marked as finished yet", releaseCR.GetNamespace(), releaseCR.GetName()) } return nil - }, releaseCreationTimeout, defaultInterval).Should(Succeed()) + }, releaseConst.ReleaseCreationTimeout, releaseConst.DefaultInterval).Should(Succeed()) }) }) diff --git a/tests/release/pipelines/push_to_external_registry.go b/tests/release/pipelines/push_to_external_registry.go index a2e71024d..d3a4de172 100644 --- a/tests/release/pipelines/push_to_external_registry.go +++ b/tests/release/pipelines/push_to_external_registry.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "regexp" + "time" "github.com/devfile/library/v2/pkg/util" . "github.com/onsi/ginkgo/v2" @@ -18,6 +19,7 @@ import ( "github.com/redhat-appstudio/e2e-tests/pkg/utils" "github.com/redhat-appstudio/e2e-tests/pkg/utils/contract" "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" + releaseConst "github.com/redhat-appstudio/e2e-tests/tests/release" releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" tektonutils "github.com/redhat-appstudio/release-service/tekton/utils" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" @@ -35,6 +37,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu AfterEach(framework.ReportFailure(&fw)) var err error var devNamespace, managedNamespace, compName, additionalCompName string + var avgControllerQueryTimeout = 5 * time.Minute + var imageIDs []string var pyxisKeyDecoded, pyxisCertDecoded []byte var releasePR1, releasePR2 *v1beta1.PipelineRun @@ -47,7 +51,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu var componentDetected, additionalComponentDetected appservice.ComponentDetectionDescription BeforeAll(func() { - fw, err = framework.NewFramework("push-pyxis") + fw, err = framework.NewFramework(utils.GetGeneratedNamespace("push-pyxis")) Expect(err).NotTo(HaveOccurred()) devNamespace = fw.UserNamespace managedNamespace = utils.GetGeneratedNamespace("push-pyxis-managed") @@ -65,11 +69,11 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu Expect(certPyxisStage).ToNot(BeEmpty()) // Create secret for the release registry repo "hacbs-release-tests". - _, err = fw.AsKubeAdmin.CommonController.CreateRegistryAuthSecret(redhatAppstudioUserSecret, managedNamespace, sourceAuthJson) + _, err = fw.AsKubeAdmin.CommonController.CreateRegistryAuthSecret(releaseConst.RedhatAppstudioUserSecret, managedNamespace, sourceAuthJson) Expect(err).ToNot(HaveOccurred()) // Linking the build secret to the pipeline service account in dev namespace. - err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(devNamespace, hacbsReleaseTestsTokenSecret, serviceAccount, true) + err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(devNamespace, releaseConst.HacbsReleaseTestsTokenSecret, constants.DefaultPipelineServiceAccount, true) Expect(err).ToNot(HaveOccurred()) publicKey, err := fw.AsKubeAdmin.TektonController.GetTektonChainsPublicKey() @@ -97,13 +101,13 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu Expect(err).ToNot(HaveOccurred()) Expect(fw.AsKubeAdmin.TektonController.CreateOrUpdateSigningSecret( - publicKey, publicSecretNameAuth, managedNamespace)).To(Succeed()) + publicKey, releaseConst.PublicSecretNameAuth, managedNamespace)).To(Succeed()) defaultECP, err := fw.AsKubeAdmin.TektonController.GetEnterpriseContractPolicy("default", "enterprise-contract-service") Expect(err).NotTo(HaveOccurred()) - policy := contract.PolicySpecWithSourceConfig(defaultECP.Spec, ecp.SourceConfig{Include: []string{"minimal", "slsa3"}}) + policy := contract.PolicySpecWithSourceConfig(defaultECP.Spec, ecp.SourceConfig{Include: []string{"@minimal", "@slsa3"}}) - managedServiceAccount, err := fw.AsKubeAdmin.CommonController.CreateServiceAccount(releaseStrategyServiceAccountDefault, managedNamespace, managednamespaceSecret, nil) + managedServiceAccount, err := fw.AsKubeAdmin.CommonController.CreateServiceAccount(releaseConst.ReleasePipelineServiceAccountDefault, managedNamespace, releaseConst.ManagednamespaceSecret, nil) Expect(err).NotTo(HaveOccurred()) _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePipelineRoleBindingForServiceAccount(devNamespace, managedServiceAccount) @@ -111,12 +115,11 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePipelineRoleBindingForServiceAccount(managedNamespace, managedServiceAccount) Expect(err).NotTo(HaveOccurred()) - err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(managedNamespace, redhatAppstudioUserSecret, releaseStrategyServiceAccountDefault, true) + err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(managedNamespace, releaseConst.RedhatAppstudioUserSecret, releaseConst.ReleasePipelineServiceAccountDefault, true) Expect(err).ToNot(HaveOccurred()) // using cdq since git ref is not known - compName = componentName - cdq, err := fw.AsKubeAdmin.HasController.CreateComponentDetectionQuery(compName, devNamespace, gitSourceComponentUrl, "", "", "", false) + cdq, err := fw.AsKubeAdmin.HasController.CreateComponentDetectionQuery(releaseConst.ComponentName, devNamespace, releaseConst.GitSourceComponentUrl, "", "", "", false) Expect(err).NotTo(HaveOccurred()) Expect(cdq.Status.ComponentDetected).To(HaveLen(1), "Expected length of the detected Components was not 1") @@ -126,8 +129,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu } // using cdq since git ref is not known - additionalCompName = additionalComponentName - cdq, err = fw.AsKubeAdmin.HasController.CreateComponentDetectionQuery(additionalCompName, devNamespace, additionalGitSourceComponentUrl, "", "", "", false) + additionalCompName = releaseConst.AdditionalComponentName + cdq, err = fw.AsKubeAdmin.HasController.CreateComponentDetectionQuery(additionalCompName, devNamespace, releaseConst.AdditionalGitSourceComponentUrl, "", "", "", false) Expect(err).NotTo(HaveOccurred()) Expect(cdq.Status.ComponentDetected).To(HaveLen(1), "Expected length of the detected Components was not 1") @@ -136,7 +139,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu additionalComponentDetected = compDetected } - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(sourceReleasePlanName, devNamespace, applicationNameDefault, managedNamespace, "") + _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releaseConst.SourceReleasePlanName, devNamespace, releaseConst.ApplicationNameDefault, managedNamespace, "") Expect(err).NotTo(HaveOccurred()) data, err := json.Marshal(map[string]interface{}{ @@ -148,7 +151,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu "repository": "quay.io/" + utils.GetQuayIOOrganization() + "/dcmetromap", }, { - "name": additionalComponentName, + "name": releaseConst.AdditionalComponentName, //"repository": "quay.io/redhat-appstudio-qe/simplepython", "repository": "quay.io/" + utils.GetQuayIOOrganization() + "/simplepython", }, @@ -161,11 +164,11 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu }) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(targetReleasePlanAdmissionName, managedNamespace, releaseEnvironment, devNamespace, releaseStrategyPolicyDefault, releaseStrategyServiceAccountDefault, []string{applicationNameDefault}, true, &tektonutils.PipelineRef{ + _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(releaseConst.TargetReleasePlanAdmissionName, managedNamespace, releaseConst.ReleaseEnvironment, devNamespace, releaseConst.ReleaseStrategyPolicyDefault, releaseConst.ReleasePipelineServiceAccountDefault, []string{releaseConst.ApplicationNameDefault}, true, &tektonutils.PipelineRef{ Resolver: "git", Params: []tektonutils.Param{ - {Name: "url", Value: relSvcCatalogURL}, - {Name: "revision", Value: relSvcCatalogRevision}, + {Name: "url", Value: releaseConst.RelSvcCatalogURL}, + {Name: "revision", Value: releaseConst.RelSvcCatalogRevision}, {Name: "pathInRepo", Value: "pipelines/push-to-external-registry/push-to-external-registry.yaml"}, }, }, &runtime.RawExtension{ @@ -173,10 +176,10 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu }) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.TektonController.CreateEnterpriseContractPolicy(releaseStrategyPolicyDefault, managedNamespace, policy) + _, err = fw.AsKubeAdmin.TektonController.CreateEnterpriseContractPolicy(releaseConst.ReleaseStrategyPolicyDefault, managedNamespace, policy) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.TektonController.CreatePVCInAccessMode(releasePvcName, managedNamespace, corev1.ReadWriteOnce) + _, err = fw.AsKubeAdmin.TektonController.CreatePVCInAccessMode(releaseConst.ReleasePvcName, managedNamespace, corev1.ReadWriteOnce) Expect(err).NotTo(HaveOccurred()) _, err = fw.AsKubeAdmin.CommonController.CreateRole("role-release-service-account", managedNamespace, map[string][]string{ @@ -186,10 +189,10 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu }) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.CommonController.CreateRoleBinding("role-release-service-account-binding", managedNamespace, "ServiceAccount", releaseStrategyServiceAccountDefault, managedNamespace, "Role", "role-release-service-account", "rbac.authorization.k8s.io") + _, err = fw.AsKubeAdmin.CommonController.CreateRoleBinding("role-release-service-account-binding", managedNamespace, "ServiceAccount", releaseConst.ReleasePipelineServiceAccountDefault, managedNamespace, "Role", "role-release-service-account", "rbac.authorization.k8s.io") Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.HasController.CreateApplication(applicationNameDefault, devNamespace) + _, err = fw.AsKubeAdmin.HasController.CreateApplication(releaseConst.ApplicationNameDefault, devNamespace) Expect(err).NotTo(HaveOccurred()) }) @@ -207,14 +210,14 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu var _ = Describe("Post-release verification", func() { It("verifies that Component 1 can be created and build PipelineRun is created for it in dev namespace and succeeds", func() { - component1, err = fw.AsKubeAdmin.HasController.CreateComponent(componentDetected.ComponentStub, devNamespace, "", "", applicationNameDefault, true, map[string]string{}) + component1, err = fw.AsKubeAdmin.HasController.CreateComponent(componentDetected.ComponentStub, devNamespace, "", "", releaseConst.ApplicationNameDefault, true, map[string]string{}) Expect(err).NotTo(HaveOccurred()) Expect(fw.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component1, "", fw.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true})).To(Succeed()) }) It("verifies that Component 2 can be created and build PipelineRun is created for it in dev namespace and succeeds", func() { - component2, err = fw.AsKubeAdmin.HasController.CreateComponent(additionalComponentDetected.ComponentStub, devNamespace, "", "", applicationNameDefault, true, map[string]string{}) + component2, err = fw.AsKubeAdmin.HasController.CreateComponent(additionalComponentDetected.ComponentStub, devNamespace, "", "", releaseConst.ApplicationNameDefault, true, map[string]string{}) Expect(err).NotTo(HaveOccurred()) Expect(fw.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component2, "", fw.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true})).To(Succeed()) @@ -233,7 +236,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu return err } return nil - }, snapshotCreationTimeout, defaultInterval).Should(Succeed(), "timed out waiting for Snapshots to be created in %s namespace", devNamespace) + }, 5*time.Minute, releaseConst.DefaultInterval).Should(Succeed(), "timed out waiting for Snapshots to be created in %s namespace", devNamespace) }) It("tests that associated Release CR is created for each Component's Snapshot", func() { @@ -249,7 +252,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu return err } return nil - }, releaseCreationTimeout, defaultInterval).Should(Succeed(), "timed out waiting for Release CRs to be created in %s namespace", devNamespace) + }, releaseConst.ReleaseCreationTimeout, releaseConst.DefaultInterval).Should(Succeed(), "timed out waiting for Release CRs to be created in %s namespace", devNamespace) }) It("verifies that Release PipelineRun is triggered for each Release CR", func() { @@ -275,7 +278,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu return fmt.Errorf(errMsg) } return nil - }, releasePipelineRunCreationTimeout, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out waiting for a PipelineRun to start for each Release CR in %s namespace", managedNamespace)) + }, releaseConst.ReleasePipelineRunCreationTimeout, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out waiting for a PipelineRun to start for each Release CR in %s namespace", managedNamespace)) }) It("verifies a release PipelineRun for each component succeeded in managed namespace", func() { @@ -295,7 +298,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu return fmt.Errorf(errMsg) } return nil - }, releasePipelineRunCompletionTimeout, constants.PipelineRunPollingInterval).Should(Succeed()) + }, releaseConst.ReleasePipelineRunCompletionTimeout, constants.PipelineRunPollingInterval).Should(Succeed()) }) It("validate the result of task create-pyxis-image contains image ids", func() { @@ -328,7 +331,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu } return imageIDs - }, avgControllerQueryTimeout, defaultInterval).Should(HaveLen(2)) + }, avgControllerQueryTimeout, releaseConst.DefaultInterval).Should(HaveLen(2)) }) It("tests that associated Release CR has completed for each Component's Snapshot", func() { @@ -345,13 +348,13 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu return fmt.Errorf(errMsg) } return nil - }, releaseCreationTimeout, defaultInterval).Should(Succeed(), "timed out waiting for Release CRs to be created in %s namespace", devNamespace) + }, releaseConst.ReleaseCreationTimeout, releaseConst.DefaultInterval).Should(Succeed(), "timed out waiting for Release CRs to be created in %s namespace", devNamespace) }) It("validates that imageIds from task create-pyxis-image exist in Pyxis.", func() { for _, imageID := range imageIDs { Eventually(func() error { - body, err := fw.AsKubeAdmin.ReleaseController.GetPyxisImageByImageID(pyxisStageImagesApiEndpoint, imageID, + body, err := fw.AsKubeAdmin.ReleaseController.GetPyxisImageByImageID(releaseConst.PyxisStageImagesApiEndpoint, imageID, []byte(pyxisCertDecoded), []byte(pyxisKeyDecoded)) Expect(err).NotTo(HaveOccurred(), "failed to get response body") @@ -363,7 +366,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu } return nil - }, releaseCreationTimeout, defaultInterval).Should(Succeed()) + }, releaseConst.ReleaseCreationTimeout, releaseConst.DefaultInterval).Should(Succeed()) } }) }) diff --git a/tests/release/service/const.go b/tests/release/service/const.go deleted file mode 100644 index 2ff38a199..000000000 --- a/tests/release/service/const.go +++ /dev/null @@ -1,44 +0,0 @@ -package service - -import ( - "time" - - "github.com/redhat-appstudio/e2e-tests/pkg/constants" - corev1 "k8s.io/api/core/v1" -) - -const ( - snapshotName = "snapshot" - destinationReleasePlanAdmissionName = "sre-production" - releaseName = "release" - applicationName = "application" - serviceAccount = constants.DefaultPipelineServiceAccount - releaseStrategyPolicy = "policy" - verifyEnterpriseContractTaskName = "verify-enterprise-contract" - applicationNameDefault string = "appstudio" - componentName string = "dc-metro-map" - releaseEnvironment string = "production" - releaseStrategyPolicyDefault string = "mvp-policy" - releasePipelineServiceAccountDefault string = "release-service-account" - sourceReleasePlanName string = "source-releaseplan" - targetReleasePlanAdmissionName string = "demo" - releasePvcName string = "release-pvc" - redhatAppstudioUserSecret string = "hacbs-release-tests-token" - hacbsReleaseTestsTokenSecret string = "redhat-appstudio-registry-pull-secret" - publicSecretNameAuth string = "cosign-public-key" - gitSourceComponentUrl string = "https://github.com/scoheb/dc-metro-map" - releasedImagePushRepo string = "quay.io/redhat-appstudio-qe/dcmetromap" - cacheSyncTimeout = 1 * time.Minute - releaseCreationTimeout = 5 * time.Minute - releasePipelineRunCreationTimeout = 10 * time.Minute - releasePipelineRunCompletionTimeout = 20 * time.Minute - releasePlanOwnerReferencesTimeout = 1 * time.Minute - - defaultInterval = 100 * time.Millisecond - releaseDeploymentTimeout = 10 * time.Minute - releaseFinishedTimeout = 5 * time.Minute -) - -var managednamespaceSecret = []corev1.ObjectReference{ - {Name: redhatAppstudioUserSecret}, -} diff --git a/tests/release/service/happy_path.go b/tests/release/service/happy_path.go index 2ab4fb9fb..bc7ea2ee5 100644 --- a/tests/release/service/happy_path.go +++ b/tests/release/service/happy_path.go @@ -12,10 +12,12 @@ import ( . "github.com/onsi/gomega" appservice "github.com/redhat-appstudio/application-api/api/v1alpha1" "github.com/redhat-appstudio/e2e-tests/pkg/clients/has" + "github.com/redhat-appstudio/e2e-tests/pkg/constants" "github.com/redhat-appstudio/e2e-tests/pkg/framework" "github.com/redhat-appstudio/e2e-tests/pkg/utils" "github.com/redhat-appstudio/e2e-tests/pkg/utils/contract" "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" + releaseConst "github.com/redhat-appstudio/e2e-tests/tests/release" releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" corev1 "k8s.io/api/core/v1" ) @@ -27,25 +29,26 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe AfterEach(framework.ReportFailure(&fw)) var err error var compName string - var devNamespace string - var managedNamespace = utils.GetGeneratedNamespace("happy-path-service-managed") + var devNamespace, managedNamespace string + var verifyEnterpriseContractTaskName = "verify-enterprise-contract" + var releasedImagePushRepo = "quay.io/redhat-appstudio-qe/dcmetromap" var component *appservice.Component var releaseCR *releaseApi.Release BeforeAll(func() { // Initialize the tests controllers - fw, err = framework.NewFramework("happy-path-service") + fw, err = framework.NewFramework(utils.GetGeneratedNamespace("happy-path")) Expect(err).NotTo(HaveOccurred()) devNamespace = fw.UserNamespace - + managedNamespace = utils.GetGeneratedNamespace("happy-path-managed") _, err = fw.AsKubeAdmin.CommonController.CreateTestNamespace(managedNamespace) Expect(err).NotTo(HaveOccurred(), "Error when creating managedNamespace: %v", err) sourceAuthJson := utils.GetEnv("QUAY_TOKEN", "") Expect(sourceAuthJson).ToNot(BeEmpty()) - managedServiceAccount, err := fw.AsKubeAdmin.CommonController.CreateServiceAccount(releasePipelineServiceAccountDefault, managedNamespace, managednamespaceSecret, nil) + managedServiceAccount, err := fw.AsKubeAdmin.CommonController.CreateServiceAccount(releaseConst.ReleasePipelineServiceAccountDefault, managedNamespace, releaseConst.ManagednamespaceSecret, nil) Expect(err).NotTo(HaveOccurred()) _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePipelineRoleBindingForServiceAccount(devNamespace, managedServiceAccount) @@ -53,28 +56,27 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePipelineRoleBindingForServiceAccount(managedNamespace, managedServiceAccount) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.CommonController.CreateRegistryAuthSecret(redhatAppstudioUserSecret, managedNamespace, sourceAuthJson) + _, err = fw.AsKubeAdmin.CommonController.CreateRegistryAuthSecret(releaseConst.RedhatAppstudioUserSecret, managedNamespace, sourceAuthJson) Expect(err).ToNot(HaveOccurred()) - err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(devNamespace, hacbsReleaseTestsTokenSecret, serviceAccount, true) + err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(devNamespace, releaseConst.HacbsReleaseTestsTokenSecret, constants.DefaultPipelineServiceAccount, true) Expect(err).ToNot(HaveOccurred()) - err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(managedNamespace, redhatAppstudioUserSecret, serviceAccount, true) + err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(managedNamespace, releaseConst.RedhatAppstudioUserSecret, constants.DefaultPipelineServiceAccount, true) Expect(err).ToNot(HaveOccurred()) publicKey, err := fw.AsKubeAdmin.TektonController.GetTektonChainsPublicKey() Expect(err).ToNot(HaveOccurred()) Expect(fw.AsKubeAdmin.TektonController.CreateOrUpdateSigningSecret( - publicKey, publicSecretNameAuth, managedNamespace)).To(Succeed()) + publicKey, releaseConst.PublicSecretNameAuth, managedNamespace)).To(Succeed()) defaultECP, err := fw.AsKubeAdmin.TektonController.GetEnterpriseContractPolicy("default", "enterprise-contract-service") Expect(err).NotTo(HaveOccurred()) - policy := contract.PolicySpecWithSourceConfig(defaultECP.Spec, ecp.SourceConfig{Include: []string{"minimal"}}) + policy := contract.PolicySpecWithSourceConfig(defaultECP.Spec, ecp.SourceConfig{Include: []string{"@minimal"}, Exclude: []string{"cve"}}) // using cdq since git ref is not known - compName = componentName var componentDetected appservice.ComponentDetectionDescription - cdq, err := fw.AsKubeAdmin.HasController.CreateComponentDetectionQuery(compName, devNamespace, gitSourceComponentUrl, "", "", "", false) + cdq, err := fw.AsKubeAdmin.HasController.CreateComponentDetectionQuery(releaseConst.ComponentName, devNamespace, releaseConst.GitSourceComponentUrl, "", "", "", false) Expect(err).NotTo(HaveOccurred()) Expect(cdq.Status.ComponentDetected).To(HaveLen(1), "Expected length of the detected Components was not 1") @@ -83,13 +85,13 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe componentDetected = compDetected } - _, err = fw.AsKubeAdmin.HasController.CreateApplication(applicationNameDefault, devNamespace) + _, err = fw.AsKubeAdmin.HasController.CreateApplication(releaseConst.ApplicationNameDefault, devNamespace) Expect(err).NotTo(HaveOccurred()) - component, err = fw.AsKubeAdmin.HasController.CreateComponent(componentDetected.ComponentStub, devNamespace, "", "", applicationNameDefault, false, map[string]string{}) + component, err = fw.AsKubeAdmin.HasController.CreateComponent(componentDetected.ComponentStub, devNamespace, "", "", releaseConst.ApplicationNameDefault, false, map[string]string{}) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(sourceReleasePlanName, devNamespace, applicationNameDefault, managedNamespace, "") + _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releaseConst.SourceReleasePlanName, devNamespace, releaseConst.ApplicationNameDefault, managedNamespace, "") Expect(err).NotTo(HaveOccurred()) data, err := json.Marshal(map[string]interface{}{ @@ -104,7 +106,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe }) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(targetReleasePlanAdmissionName, managedNamespace, "", devNamespace, releaseStrategyPolicyDefault, releasePipelineServiceAccountDefault, []string{applicationNameDefault}, true, &tektonutils.PipelineRef{ + _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(releaseConst.TargetReleasePlanAdmissionName, managedNamespace, "", devNamespace, releaseConst.ReleaseStrategyPolicyDefault, releaseConst.ReleasePipelineServiceAccountDefault, []string{releaseConst.ApplicationNameDefault}, true, &tektonutils.PipelineRef{ Resolver: "git", Params: []tektonutils.Param{ {Name: "url", Value: "https://github.com/redhat-appstudio/release-service-catalog"}, @@ -116,10 +118,10 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe }) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.TektonController.CreateEnterpriseContractPolicy(releaseStrategyPolicyDefault, managedNamespace, policy) + _, err = fw.AsKubeAdmin.TektonController.CreateEnterpriseContractPolicy(releaseConst.ReleaseStrategyPolicyDefault, managedNamespace, policy) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.TektonController.CreatePVCInAccessMode(releasePvcName, managedNamespace, corev1.ReadWriteOnce) + _, err = fw.AsKubeAdmin.TektonController.CreatePVCInAccessMode(releaseConst.ReleasePvcName, managedNamespace, corev1.ReadWriteOnce) Expect(err).NotTo(HaveOccurred()) _, err = fw.AsKubeAdmin.CommonController.CreateRole("role-release-service-account", managedNamespace, map[string][]string{ @@ -129,7 +131,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe }) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.CommonController.CreateRoleBinding("role-release-service-account-binding", managedNamespace, "ServiceAccount", releasePipelineServiceAccountDefault, managedNamespace, "Role", "role-release-service-account", "rbac.authorization.k8s.io") + _, err = fw.AsKubeAdmin.CommonController.CreateRoleBinding("role-release-service-account-binding", managedNamespace, "ServiceAccount", releaseConst.ReleasePipelineServiceAccountDefault, managedNamespace, "Role", "role-release-service-account", "rbac.authorization.k8s.io") Expect(err).NotTo(HaveOccurred()) }) @@ -150,7 +152,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe Eventually(func() error { releaseCR, err = fw.AsKubeAdmin.ReleaseController.GetFirstReleaseInNamespace(devNamespace) return err - }, releaseCreationTimeout, defaultInterval).Should(Succeed()) + }, releaseConst.ReleaseCreationTimeout, releaseConst.DefaultInterval).Should(Succeed()) }) It("verifies that Release PipelineRun is triggered", func() { @@ -164,7 +166,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe return fmt.Errorf("pipelinerun %s/%s hasn't started yet", pr.GetNamespace(), pr.GetName()) } return nil - }, releasePipelineRunCreationTimeout, defaultInterval).Should(Succeed(), fmt.Sprintf("timed out waiting for a pipelinerun to start for a release %s/%s", releaseCR.GetName(), releaseCR.GetNamespace())) + }, releaseConst.ReleasePipelineRunCreationTimeout, releaseConst.DefaultInterval).Should(Succeed(), fmt.Sprintf("timed out waiting for a pipelinerun to start for a release %s/%s", releaseCR.GetName(), releaseCR.GetNamespace())) }) It("verifies that Release PipelineRun should eventually succeed", func() { @@ -176,7 +178,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe } Expect(tekton.HasPipelineRunSucceeded(pr)).To(BeTrue(), fmt.Sprintf("release pipelinerun %s/%s did not succeed", pr.GetNamespace(), pr.GetName())) return nil - }, releasePipelineRunCompletionTimeout, defaultInterval).Should(Succeed()) + }, releaseConst.ReleasePipelineRunCompletionTimeout, releaseConst.DefaultInterval).Should(Succeed()) }) It("verifies that Enterprise Contract Task has succeeded in the Release PipelineRun", func() { @@ -188,7 +190,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe GinkgoWriter.Printf("the status of the %s TaskRun on the release pipeline is: %v", verifyEnterpriseContractTaskName, ecTaskRunStatus.Status.Conditions) Expect(tekton.DidTaskSucceed(ecTaskRunStatus)).To(BeTrue()) return nil - }, releasePipelineRunCompletionTimeout, defaultInterval).Should(Succeed()) + }, releaseConst.ReleasePipelineRunCompletionTimeout, releaseConst.DefaultInterval).Should(Succeed()) }) It("verifies that a Release is marked as succeeded.", func() { @@ -201,7 +203,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe return fmt.Errorf("release %s/%s is not marked as finished yet", releaseCR.GetNamespace(), releaseCR.GetName()) } return nil - }, releaseCreationTimeout, defaultInterval).Should(Succeed()) + }, releaseConst.ReleaseCreationTimeout, releaseConst.DefaultInterval).Should(Succeed()) }) }) }) diff --git a/tests/release/service/happy_path_with_deployment.go b/tests/release/service/happy_path_with_deployment.go index 37796d4dd..e0784c8a1 100644 --- a/tests/release/service/happy_path_with_deployment.go +++ b/tests/release/service/happy_path_with_deployment.go @@ -3,22 +3,25 @@ package service import ( "fmt" "os" + "time" ecp "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" appservice "github.com/redhat-appstudio/application-api/api/v1alpha1" "github.com/redhat-appstudio/e2e-tests/pkg/clients/has" + "github.com/redhat-appstudio/e2e-tests/pkg/constants" "github.com/redhat-appstudio/e2e-tests/pkg/framework" "github.com/redhat-appstudio/e2e-tests/pkg/utils" - "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" "github.com/redhat-appstudio/e2e-tests/pkg/utils/contract" + "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" + releaseConst "github.com/redhat-appstudio/e2e-tests/tests/release" releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" tektonutils "github.com/redhat-appstudio/release-service/tekton/utils" corev1 "k8s.io/api/core/v1" ) -var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pending, Label("release-service", "withDeployment"), func() { +var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Label("release-service", "withDeployment"), func() { defer GinkgoRecover() // Initialize the tests controllers var fw *framework.Framework @@ -29,39 +32,42 @@ var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pend var component *appservice.Component var releaseCR *releaseApi.Release - var managedNamespace = utils.GetGeneratedNamespace("happy-path-with-depl-managed") + var managedNamespace string + var releaseEnvironment = "production" + var releaseDeploymentTimeout = 10 * time.Minute + var releaseFinishedTimeout = 5 * time.Minute BeforeAll(func() { - fw, err = framework.NewFramework("happy-path-with-depl") + fw, err = framework.NewFramework(utils.GetGeneratedNamespace("happy-depl")) Expect(err).NotTo(HaveOccurred()) devNamespace = fw.UserNamespace - + managedNamespace = utils.GetGeneratedNamespace("happy-depl-managed") _, err = fw.AsKubeAdmin.CommonController.CreateTestNamespace(managedNamespace) - Expect(err).NotTo(HaveOccurred(), "Error when creating managed namespace: %v", err) + Expect(err).NotTo(HaveOccurred(), "Error when creating managedNamespace: %v", err) sourceAuthJson := utils.GetEnv("QUAY_TOKEN", "") Expect(sourceAuthJson).ToNot(BeEmpty()) - _, err = fw.AsKubeAdmin.CommonController.CreateRegistryAuthSecret(redhatAppstudioUserSecret, managedNamespace, sourceAuthJson) + _, err = fw.AsKubeAdmin.CommonController.CreateRegistryAuthSecret(releaseConst.RedhatAppstudioUserSecret, managedNamespace, sourceAuthJson) Expect(err).ToNot(HaveOccurred()) - err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(devNamespace, hacbsReleaseTestsTokenSecret, serviceAccount, true) + err = fw.AsKubeAdmin.CommonController.LinkSecretToServiceAccount(devNamespace, releaseConst.HacbsReleaseTestsTokenSecret, constants.DefaultPipelineServiceAccount, true) Expect(err).ToNot(HaveOccurred()) publicKey, err := fw.AsKubeAdmin.TektonController.GetTektonChainsPublicKey() Expect(err).ToNot(HaveOccurred()) Expect(fw.AsKubeAdmin.TektonController.CreateOrUpdateSigningSecret( - publicKey, publicSecretNameAuth, managedNamespace)).To(Succeed()) + publicKey, releaseConst.PublicSecretNameAuth, managedNamespace)).To(Succeed()) defaultEcPolicy, err := fw.AsKubeAdmin.TektonController.GetEnterpriseContractPolicy("default", "enterprise-contract-service") Expect(err).NotTo(HaveOccurred()) - policy := contract.PolicySpecWithSourceConfig(defaultEcPolicy.Spec, ecp.SourceConfig{Include: []string{"minimal"}, Exclude: []string{"cve"}}) + policy := contract.PolicySpecWithSourceConfig(defaultEcPolicy.Spec, ecp.SourceConfig{Include: []string{"@minimal"}, Exclude: []string{"cve"}}) // using cdq since git ref is not known - compName = componentName + compName = releaseConst.ComponentName var componentDetected appservice.ComponentDetectionDescription - cdq, err := fw.AsKubeAdmin.HasController.CreateComponentDetectionQuery(compName, devNamespace, gitSourceComponentUrl, "", "", "", false) + cdq, err := fw.AsKubeAdmin.HasController.CreateComponentDetectionQuery(compName, devNamespace, releaseConst.GitSourceComponentUrl, "", "", "", false) Expect(err).NotTo(HaveOccurred()) Expect(cdq.Status.ComponentDetected).To(HaveLen(1), "Expected length of the detected Components was not 1") @@ -70,29 +76,29 @@ var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pend componentDetected = compDetected } - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(sourceReleasePlanName, devNamespace, applicationNameDefault, managedNamespace, "") + _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releaseConst.SourceReleasePlanName, devNamespace, releaseConst.ApplicationNameDefault, managedNamespace, "") Expect(err).NotTo(HaveOccurred()) _, err = fw.AsKubeAdmin.GitOpsController.CreatePocEnvironment(releaseEnvironment, managedNamespace) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(targetReleasePlanAdmissionName, managedNamespace, releaseEnvironment, devNamespace, releaseStrategyPolicyDefault, releasePipelineServiceAccountDefault, []string{applicationNameDefault}, true, &tektonutils.PipelineRef{ + _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(releaseConst.TargetReleasePlanAdmissionName, managedNamespace, releaseEnvironment, devNamespace, releaseConst.ReleaseStrategyPolicyDefault, releaseConst.ReleasePipelineServiceAccountDefault, []string{releaseConst.ApplicationNameDefault}, true, &tektonutils.PipelineRef{ Resolver: "git", Params: []tektonutils.Param{ {Name: "url", Value: "https://github.com/redhat-appstudio/release-service-catalog"}, {Name: "revision", Value: "main"}, {Name: "pathInRepo", Value: "pipelines/e2e/e2e.yaml"}, }, - }, nil ) + }, nil) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.TektonController.CreateEnterpriseContractPolicy(releaseStrategyPolicyDefault, managedNamespace, policy) + _, err = fw.AsKubeAdmin.TektonController.CreateEnterpriseContractPolicy(releaseConst.ReleaseStrategyPolicyDefault, managedNamespace, policy) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.TektonController.CreatePVCInAccessMode(releasePvcName, managedNamespace, corev1.ReadWriteOnce) + _, err = fw.AsKubeAdmin.TektonController.CreatePVCInAccessMode(releaseConst.ReleasePvcName, managedNamespace, corev1.ReadWriteOnce) Expect(err).NotTo(HaveOccurred()) - managedServiceAccount, err := fw.AsKubeAdmin.CommonController.CreateServiceAccount(releasePipelineServiceAccountDefault, managedNamespace, managednamespaceSecret, nil) + managedServiceAccount, err := fw.AsKubeAdmin.CommonController.CreateServiceAccount(releaseConst.ReleasePipelineServiceAccountDefault, managedNamespace, releaseConst.ManagednamespaceSecret, nil) Expect(err).NotTo(HaveOccurred()) _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePipelineRoleBindingForServiceAccount(devNamespace, managedServiceAccount) @@ -107,13 +113,13 @@ var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pend }) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.CommonController.CreateRoleBinding("role-release-service-account-binding", managedNamespace, "ServiceAccount", releasePipelineServiceAccountDefault, managedNamespace, "Role", "role-release-service-account", "rbac.authorization.k8s.io") + _, err = fw.AsKubeAdmin.CommonController.CreateRoleBinding("role-release-service-account-binding", managedNamespace, "ServiceAccount", releaseConst.ReleasePipelineServiceAccountDefault, managedNamespace, "Role", "role-release-service-account", "rbac.authorization.k8s.io") Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.HasController.CreateApplication(applicationNameDefault, devNamespace) + _, err = fw.AsKubeAdmin.HasController.CreateApplication(releaseConst.ApplicationNameDefault, devNamespace) Expect(err).NotTo(HaveOccurred()) - component, err = fw.AsKubeAdmin.HasController.CreateComponent(componentDetected.ComponentStub, devNamespace, "", "", applicationNameDefault, true, map[string]string{}) + component, err = fw.AsKubeAdmin.HasController.CreateComponent(componentDetected.ComponentStub, devNamespace, "", "", releaseConst.ApplicationNameDefault, true, map[string]string{}) Expect(err).NotTo(HaveOccurred()) workingDir, err := os.Getwd() @@ -130,7 +136,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pend args = []string{"775", "copy-application.sh"} Expect(utils.ExecuteCommandInASpecificDirectory("chmod", args, workingDir)).To(Succeed()) // Copying application in dev namespace to managed namespace - args = []string{managedNamespace, "-a", devNamespace + "/" + applicationNameDefault} + args = []string{managedNamespace, "-a", devNamespace + "/" + releaseConst.ApplicationNameDefault} Expect(utils.ExecuteCommandInASpecificDirectory("./copy-application.sh", args, workingDir)).To(Succeed()) }) @@ -153,7 +159,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pend Eventually(func() error { releaseCR, err = fw.AsKubeAdmin.ReleaseController.GetFirstReleaseInNamespace(devNamespace) return err - }, releaseCreationTimeout, defaultInterval).Should(Succeed()) + }, releaseConst.ReleaseCreationTimeout, releaseConst.DefaultInterval).Should(Succeed()) }) It("verifies that Release PipelineRun is triggered", func() { @@ -167,7 +173,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pend return fmt.Errorf("pipelinerun %s/%s hasn't started yet", pr.GetNamespace(), pr.GetName()) } return nil - }, releasePipelineRunCreationTimeout, defaultInterval).Should(Succeed(), fmt.Sprintf("timed out waiting for a pipelinerun to start for a release %s/%s", releaseCR.GetName(), releaseCR.GetNamespace())) + }, releaseConst.ReleasePipelineRunCreationTimeout, releaseConst.DefaultInterval).Should(Succeed(), fmt.Sprintf("timed out waiting for a pipelinerun to start for a release %s/%s", releaseCR.GetName(), releaseCR.GetNamespace())) }) It("verifies that Release PipelineRun should eventually succeed", func() { @@ -179,7 +185,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pend } Expect(tekton.HasPipelineRunSucceeded(pr)).To(BeTrue(), fmt.Sprintf("release pipelinerun %s/%s did not succeed", pr.GetNamespace(), pr.GetName())) return nil - }, releasePipelineRunCompletionTimeout, defaultInterval).Should(Succeed()) + }, releaseConst.ReleasePipelineRunCompletionTimeout, releaseConst.DefaultInterval).Should(Succeed()) }) // phase Deployed happens before phase Released It("tests a Release CR reports that the deployment was successful", func() { @@ -192,7 +198,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pend return fmt.Errorf("release %s/%s is not marked as deployed yet", releaseCR.GetNamespace(), releaseCR.GetName()) } return nil - }, releaseDeploymentTimeout, defaultInterval).Should(Succeed()) + }, releaseDeploymentTimeout, releaseConst.DefaultInterval).Should(Succeed()) }) It("tests a Release CR is marked as successfully deployed", func() { Eventually(func() error { @@ -204,7 +210,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("happy_path_with_deployment", Pend return fmt.Errorf("release %s/%s is not marked as finished yet", releaseCR.GetNamespace(), releaseCR.GetName()) } return nil - }, releaseFinishedTimeout, defaultInterval).Should(Succeed()) + }, releaseFinishedTimeout, releaseConst.DefaultInterval).Should(Succeed()) }) }) }) diff --git a/tests/release/service/missing_release_plan_and_admission.go b/tests/release/service/missing_release_plan_and_admission.go index 20710864d..02f5bcf36 100644 --- a/tests/release/service/missing_release_plan_and_admission.go +++ b/tests/release/service/missing_release_plan_and_admission.go @@ -6,10 +6,13 @@ import ( "github.com/redhat-appstudio/application-api/api/v1alpha1" tektonutils "github.com/redhat-appstudio/release-service/tekton/utils" + releaseConst "github.com/redhat-appstudio/e2e-tests/tests/release" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - + "github.com/redhat-appstudio/e2e-tests/pkg/constants" "github.com/redhat-appstudio/e2e-tests/pkg/framework" + "github.com/redhat-appstudio/e2e-tests/pkg/utils" releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" ) @@ -22,23 +25,27 @@ var _ = framework.ReleaseServiceSuiteDescribe("[HACBS-2360] Release CR fails whe var devNamespace, managedNamespace string var releaseCR *releaseApi.Release + var snapshotName = "snapshot" + var destinationReleasePlanAdmissionName = "sre-production" + var releaseName = "release" + AfterEach(framework.ReportFailure(&fw)) BeforeAll(func() { // Initialize the tests controllers - fw, err = framework.NewFramework("release-neg-rp-dev") + fw, err = framework.NewFramework(utils.GetGeneratedNamespace("neg-rp-dev")) Expect(err).NotTo(HaveOccurred()) devNamespace = fw.UserNamespace // Create the managed namespace - managedNamespace = "release-neg-rp-managed" + managedNamespace = utils.GetGeneratedNamespace("neg-rp-managed") _, err = fw.AsKubeAdmin.CommonController.CreateTestNamespace(managedNamespace) Expect(err).NotTo(HaveOccurred(), "Error when creating namespace '%s': %v", managedNamespace, err) - _, err = fw.AsKubeAdmin.IntegrationController.CreateSnapshotWithComponents(snapshotName, "", applicationName, devNamespace, []v1alpha1.SnapshotComponent{}) + _, err = fw.AsKubeAdmin.IntegrationController.CreateSnapshotWithComponents(snapshotName, "", releaseConst.ApplicationName, devNamespace, []v1alpha1.SnapshotComponent{}) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(destinationReleasePlanAdmissionName, managedNamespace, "", devNamespace, releaseStrategyPolicy, serviceAccount, []string{applicationName}, true, &tektonutils.PipelineRef{ + _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlanAdmission(destinationReleasePlanAdmissionName, managedNamespace, "", devNamespace, releaseConst.ReleaseStrategyPolicy, constants.DefaultPipelineServiceAccount, []string{releaseConst.ApplicationName}, true, &tektonutils.PipelineRef{ Resolver: "git", Params: []tektonutils.Param{ {Name: "url", Value: "https://github.com/redhat-appstudio/release-service-catalog"}, @@ -47,7 +54,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("[HACBS-2360] Release CR fails whe }, }, nil) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.ReleaseController.CreateRelease(releaseName, devNamespace, snapshotName, sourceReleasePlanName) + _, err = fw.AsKubeAdmin.ReleaseController.CreateRelease(releaseName, devNamespace, snapshotName, releaseConst.SourceReleasePlanName) Expect(err).NotTo(HaveOccurred()) }) @@ -67,7 +74,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("[HACBS-2360] Release CR fails whe strings.Contains(releaseCR.Status.Conditions[0].Message, "Release validation failed") } return false - }, releaseCreationTimeout, defaultInterval).Should(BeTrue()) + }, releaseConst.ReleaseCreationTimeout, releaseConst.DefaultInterval).Should(BeTrue()) }) It("missing ReleasePlanAdmission makes a Release CR set as failed in both IsReleased and IsValid with a proper message to user.", func() { Expect(fw.AsKubeAdmin.ReleaseController.DeleteReleasePlanAdmission(destinationReleasePlanAdmissionName, managedNamespace, false)).NotTo(HaveOccurred()) @@ -78,7 +85,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("[HACBS-2360] Release CR fails whe strings.Contains(releaseCR.Status.Conditions[0].Message, "Release validation failed") } return false - }, releaseCreationTimeout, defaultInterval).Should(BeTrue()) + }, releaseConst.ReleaseCreationTimeout, releaseConst.DefaultInterval).Should(BeTrue()) }) }) }) diff --git a/tests/release/service/release_plan_owner_ref.go b/tests/release/service/release_plan_owner_ref.go index 66454cd85..d95b48923 100644 --- a/tests/release/service/release_plan_owner_ref.go +++ b/tests/release/service/release_plan_owner_ref.go @@ -2,12 +2,15 @@ package service import ( "fmt" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "k8s.io/apimachinery/pkg/api/errors" "github.com/redhat-appstudio/e2e-tests/pkg/framework" + "github.com/redhat-appstudio/e2e-tests/pkg/utils" + releaseConst "github.com/redhat-appstudio/e2e-tests/tests/release" releaseApi "github.com/redhat-appstudio/release-service/api/v1alpha1" ) @@ -17,17 +20,18 @@ var _ = framework.ReleaseServiceSuiteDescribe("[HACBS-2469]test-releaseplan-owne var err error var devNamespace string var releasePlan *releaseApi.ReleasePlan + var releasePlanOwnerReferencesTimeout = 1 * time.Minute AfterEach(framework.ReportFailure(&fw)) BeforeAll(func() { - fw, err = framework.NewFramework("releaseplan-ownerref") + fw, err = framework.NewFramework(utils.GetGeneratedNamespace("rp-ownerref")) Expect(err).NotTo(HaveOccurred()) devNamespace = fw.UserNamespace - _, err = fw.AsKubeAdmin.HasController.CreateApplication(applicationNameDefault, devNamespace) + _, err = fw.AsKubeAdmin.HasController.CreateApplication(releaseConst.ApplicationNameDefault, devNamespace) Expect(err).NotTo(HaveOccurred()) - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(sourceReleasePlanName, devNamespace, applicationNameDefault, "managed", "true") + _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releaseConst.SourceReleasePlanName, devNamespace, releaseConst.ApplicationNameDefault, "managed", "true") Expect(err).NotTo(HaveOccurred()) }) @@ -40,7 +44,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("[HACBS-2469]test-releaseplan-owne var _ = Describe("ReleasePlan verification", Ordered, func() { It("verifies that the ReleasePlan has an owner reference for the application", func() { Eventually(func() error { - releasePlan, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlan(sourceReleasePlanName, devNamespace) + releasePlan, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlan(releaseConst.SourceReleasePlanName, devNamespace) Expect(err).NotTo(HaveOccurred()) if len(releasePlan.OwnerReferences) != 1 { @@ -48,22 +52,22 @@ var _ = framework.ReleaseServiceSuiteDescribe("[HACBS-2469]test-releaseplan-owne } ownerRef := releasePlan.OwnerReferences[0] - if ownerRef.Name != applicationNameDefault { - return fmt.Errorf("ReleasePlan %s have OwnerReference Name %s and it's not as expected in Application Name %s", releasePlan.Name, ownerRef.Name, applicationNameDefault) + if ownerRef.Name != releaseConst.ApplicationNameDefault { + return fmt.Errorf("ReleasePlan %s have OwnerReference Name %s and it's not as expected in Application Name %s", releasePlan.Name, ownerRef.Name, releaseConst.ApplicationNameDefault) } return nil - }, releasePlanOwnerReferencesTimeout, defaultInterval).Should(Succeed(), "timed out waiting for ReleasePlan OwnerReference to be set.") + }, releasePlanOwnerReferencesTimeout, releaseConst.DefaultInterval).Should(Succeed(), "timed out waiting for ReleasePlan OwnerReference to be set.") }) It("verifies that the ReleasePlan is deleted if the application is deleted", func() { - Expect(fw.AsKubeAdmin.HasController.DeleteApplication(applicationNameDefault, devNamespace, true)).To(Succeed()) + Expect(fw.AsKubeAdmin.HasController.DeleteApplication(releaseConst.ApplicationNameDefault, devNamespace, true)).To(Succeed()) Eventually(func() error { - releasePlan, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlan(sourceReleasePlanName, devNamespace) + releasePlan, err = fw.AsKubeAdmin.ReleaseController.GetReleasePlan(releaseConst.SourceReleasePlanName, devNamespace) if !errors.IsNotFound(err) { - return fmt.Errorf("ReleasePlan %s for application %s still not deleted\n", releasePlan.GetName(), applicationNameDefault) + return fmt.Errorf("ReleasePlan %s for application %s still not deleted\n", releasePlan.GetName(), releaseConst.ApplicationNameDefault) } return nil - }, cacheSyncTimeout, defaultInterval).Should(Succeed(), "timed out waiting for ReleasePlan to be deleted in %s namespace", devNamespace) + }, 1*time.Minute, releaseConst.DefaultInterval).Should(Succeed(), "timed out waiting for ReleasePlan to be deleted in %s namespace", devNamespace) }) }) })