diff --git a/magefiles/magefile.go b/magefiles/magefile.go index 096d721086..68f70cf352 100644 --- a/magefiles/magefile.go +++ b/magefiles/magefile.go @@ -316,7 +316,7 @@ func (ci CI) UnregisterSprayproxy() { } func RunE2ETests() error { - labelFilter := utils.GetEnv("E2E_TEST_SUITE_LABEL", "!upgrade-create && !upgrade-verify && !upgrade-cleanup && !release-pipelines") + labelFilter := utils.GetEnv("E2E_TEST_SUITE_LABEL", "!upgrade-create && !upgrade-verify && !upgrade-cleanup && release-pipelines") rctx := rulesengine.NewRuleCtx() rctx.Parallel = true diff --git a/tests/build/build.go b/tests/build/build.go index 2d11909e67..959b4842c7 100644 --- a/tests/build/build.go +++ b/tests/build/build.go @@ -1040,16 +1040,13 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser var componentObj appservice.ComponentSpec var component *appservice.Component - var timeout, interval time.Duration + invalidAnnotation := "foo" BeforeAll(func() { f, err = framework.NewFramework(utils.GetGeneratedNamespace("build-e2e")) Expect(err).ShouldNot(HaveOccurred()) testNamespace = f.UserNamespace - timeout = 5 * time.Minute - interval = 5 * time.Second - applicationName = fmt.Sprintf("build-suite-test-application-%s", util.GenerateRandomString(4)) _, err = f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace) Expect(err).NotTo(HaveOccurred()) @@ -1066,8 +1063,11 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser }) - When("component is created", func() { - var lastBuildStartTime string + When("component is created with invalid build request annotations", func() { + + invalidBuildAnnotation := map[string]string{ + controllers.BuildRequestAnnotationName: invalidAnnotation, + } BeforeAll(func() { componentObj = appservice.ComponentSpec{ @@ -1084,138 +1084,21 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser }, } - component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, constants.DefaultDockerBuildPipelineBundle) + component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, false, utils.MergeMaps(invalidBuildAnnotation, constants.DefaultDockerBuildPipelineBundle)) Expect(component).ToNot(BeNil()) Expect(err).ShouldNot(HaveOccurred()) }) - It("triggers a pipeline run", func() { - Eventually(func() error { - pr, err := f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "") - if err != nil { - GinkgoWriter.Printf("PipelineRun has not been created yet for the component %s/%s\n", testNamespace, componentName) - return err - } - if !pr.HasStarted() { - return fmt.Errorf("pipelinerun %s/%s hasn't started yet", pr.GetNamespace(), pr.GetName()) - } - return nil - }, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), fmt.Sprintf("timed out when waiting for the PipelineRun to start for the component %s/%s", testNamespace, componentName)) - }) - - It("component build status annotation is set correctly", func() { - var buildStatus *controllers.BuildStatus - - Eventually(func() (bool, error) { - component, err := f.AsKubeAdmin.HasController.GetComponent(componentName, testNamespace) - if err != nil { - GinkgoWriter.Printf("cannot get the component: %v\n", err) - return false, err - } - - buildStatusAnnotationValue := component.Annotations[controllers.BuildStatusAnnotationName] - GinkgoWriter.Printf(buildStatusAnnotationValueLoggingFormat, buildStatusAnnotationValue) - statusBytes := []byte(buildStatusAnnotationValue) - - err = json.Unmarshal(statusBytes, &buildStatus) - if err != nil { - GinkgoWriter.Printf("cannot unmarshal build status: %v\n", err) - return false, err - } - - if buildStatus.Simple != nil { - GinkgoWriter.Printf("buildStartTime: %s\n", buildStatus.Simple.BuildStartTime) - lastBuildStartTime = buildStatus.Simple.BuildStartTime - } else { - GinkgoWriter.Println("build status does not have simple field") - } - - return buildStatus.Simple != nil && buildStatus.Simple.BuildStartTime != "", nil - }, timeout, interval).Should(BeTrue(), "build status has unexpected content") - - //Expect pipelinerun count to be 1 - Eventually(func() error { - pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace) - if err != nil { - GinkgoWriter.Println("PiplelineRun has not been created yet") - return err - } - if len(pipelineRuns.Items) != 1 { - return fmt.Errorf("pipelinerun count in the namespace %s is not one, got pipelineruns %v", testNamespace, pipelineRuns.Items) - } - return nil - }, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), "timeout while waiting for first pipelinerun to start") - }) - - Specify("simple build can be triggered manually", func() { - // Wait 1 second before sending the second build request, so that we get different buildStatus.Simple.BuildStartTime timestamp - time.Sleep(1 * time.Second) - Expect(f.AsKubeAdmin.HasController.SetComponentAnnotation(componentName, controllers.BuildRequestAnnotationName, controllers.BuildRequestTriggerSimpleBuildAnnotationValue, testNamespace)).To(Succeed()) - }) - - It("another pipelineRun is triggered", func() { - //Expect pipelinerun count to be 2 - Eventually(func() error { - pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace) - if err != nil { - GinkgoWriter.Println("Second piplelineRun has not been created yet") - return err - } - if len(pipelineRuns.Items) != 2 { - return fmt.Errorf("pipelinerun count in the namespace %s is not two, got pipelineruns %v", testNamespace, pipelineRuns.Items) - } - return nil - }, time.Minute*5, constants.PipelineRunPollingInterval).Should(Succeed(), "timeout while waiting for second pipelinerun to start") - }) - - It("component build annotation is correct", func() { - var buildStatus *controllers.BuildStatus - - Eventually(func() (bool, error) { - component, err := f.AsKubeAdmin.HasController.GetComponent(componentName, testNamespace) - if err != nil { - GinkgoWriter.Printf("cannot get the component: %v\n", err) - return false, err - } - - buildStatusAnnotationValue := component.Annotations[controllers.BuildStatusAnnotationName] - GinkgoWriter.Printf(buildStatusAnnotationValueLoggingFormat, buildStatusAnnotationValue) - statusBytes := []byte(buildStatusAnnotationValue) - - err = json.Unmarshal(statusBytes, &buildStatus) - if err != nil { - GinkgoWriter.Printf("cannot unmarshal build status: %v\n", err) - return false, err - } - - if buildStatus.Simple != nil { - GinkgoWriter.Printf("buildStartTime: %s\n", buildStatus.Simple.BuildStartTime) - } else { - GinkgoWriter.Println("build status does not have simple field") - } - - return buildStatus.Simple != nil && buildStatus.Simple.BuildStartTime != lastBuildStartTime, nil - }, timeout, interval).Should(BeTrue(), "build status has unexpected content") - }) - It("handles invalid request annotation", func() { - invalidAnnotation := "foo" expectedInvalidAnnotationMessage := fmt.Sprintf("unexpected build request: %s", invalidAnnotation) - Expect(f.AsKubeAdmin.HasController.SetComponentAnnotation(componentName, controllers.BuildRequestAnnotationName, invalidAnnotation, testNamespace)).To(Succeed()) - - // Waiting for 2 minute to see if any more pipelinerun is triggered - Consistently(func() (bool, error) { - pipelineRuns, err := f.AsKubeAdmin.HasController.GetAllPipelineRunsForApplication(applicationName, testNamespace) - if err != nil { - return false, err - } - if len(pipelineRuns.Items) != 2 { - return false, fmt.Errorf("pipelinerun count in the namespace %s is not two, got pipelineruns %v", testNamespace, pipelineRuns.Items) - } - return true, nil - }, time.Minute*2, constants.PipelineRunPollingInterval).Should(BeTrue(), "timeout while checking if any more pipelinerun is triggered") + // Waiting for 1 minute to see if any pipelinerun is triggered + Consistently(func() bool { + _, err := f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "") + Expect(err).To(HaveOccurred()) + return strings.Contains(err.Error(), "no pipelinerun found") + }, time.Minute*1, constants.PipelineRunPollingInterval).Should(BeTrue(), "timeout while checking if any pipelinerun is triggered") buildStatus := &controllers.BuildStatus{} Eventually(func() error { @@ -1286,7 +1169,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser Describe("A secret with dummy quay.io credentials is created in the testing namespace", Ordered, func() { - var applicationName, componentName, testNamespace string + var applicationName, componentName, testNamespace, pacBranchName, componentBaseBranchName string var timeout time.Duration var err error var pr *pipeline.PipelineRun @@ -1332,19 +1215,25 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser Expect(err).ToNot(HaveOccurred()) componentName = "build-suite-test-secret-overriding" + pacBranchName = constants.PaCPullRequestBranchPrefix + componentName + componentBaseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + err = f.AsKubeAdmin.CommonController.Github.CreateRef(helloWorldComponentGitSourceCloneRepoName, "main", helloWorldComponentCloneRevision, componentBaseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + componentObj := appservice.ComponentSpec{ ComponentName: componentName, Application: applicationName, Source: appservice.ComponentSource{ ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ - URL: helloWorldComponentGitSourceURL, + URL: helloWorldComponentGitSourceCloneURL, + Revision: componentBaseBranchName, DockerfileURL: constants.DockerFilePath, }, }, }, } - _, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, constants.DefaultDockerBuildPipelineBundle) + _, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.DefaultDockerBuildPipelineBundle)) Expect(err).NotTo(HaveOccurred()) }) @@ -1355,6 +1244,17 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser Expect(f.AsKubeAdmin.TektonController.DeleteAllPipelineRunsInASpecificNamespace(testNamespace)).To(Succeed()) Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue()) } + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(helloWorldComponentGitSourceCloneRepoName, pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(helloWorldComponentGitSourceCloneRepoName, componentBaseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + // Delete created webhook from GitHub + cleanupWebhooks(f, helloWorldComponentGitSourceCloneRepoName) }) It("should override the shared secret", func() { @@ -1372,7 +1272,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser pr, err = f.AsKubeAdmin.HasController.GetComponentPipelineRun(componentName, applicationName, testNamespace, "") Expect(err).ShouldNot(HaveOccurred()) - Expect(pr.Spec.Workspaces).To(HaveLen(1)) + Expect(pr.Spec.Workspaces).To(HaveLen(2)) }) It("should not be possible to push to quay.io repo (PipelineRun should fail)", func() { diff --git a/tests/build/build_templates.go b/tests/build/build_templates.go index c8fa930f31..2f4760d8d8 100644 --- a/tests/build/build_templates.go +++ b/tests/build/build_templates.go @@ -12,6 +12,7 @@ import ( "github.com/konflux-ci/application-api/api/v1alpha1" appservice "github.com/konflux-ci/application-api/api/v1alpha1" + "github.com/konflux-ci/e2e-tests/pkg/clients/common" "github.com/konflux-ci/e2e-tests/pkg/clients/has" kubeapi "github.com/konflux-ci/e2e-tests/pkg/clients/kubernetes" "github.com/konflux-ci/e2e-tests/pkg/constants" @@ -42,10 +43,20 @@ var ( const pipelineCompletionRetries = 2 +type TestBranches struct { + RepoName string + BranchName string + PacBranchName string + BaseBranchName string +} + +var pacAndBaseBranches []TestBranches + // CreateComponent creates a component from a test repository URL and returns the component's name -func CreateComponent(ctrl *has.HasController, gitUrl, revision, applicationName, componentName, namespace string) string { +func CreateComponent(commonCtrl *common.SuiteController, ctrl *has.HasController, gitUrl, revision, applicationName, componentName, namespace string) string { var err error var buildPipelineAnnotation map[string]string + var baseBranchName, pacBranchName string contextDir, dockerfilePath, pipelineBundleName, enableHermetic, prefetchInput, checkAdditionalTags := GetComponentScenarioDetailsFromGitUrl(gitUrl) Expect(pipelineBundleName).ShouldNot(BeEmpty()) if pipelineBundleName == "docker-build" { @@ -82,13 +93,38 @@ func CreateComponent(ctrl *has.HasController, gitUrl, revision, applicationName, } } + baseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + pacBranchName = constants.PaCPullRequestBranchPrefix + componentName + + if revision == gitRepoContainsSymlinkBranchName { + revision = symlinkBranchRevision + err = commonCtrl.Github.CreateRef(utils.GetRepoName(gitUrl), gitRepoContainsSymlinkBranchName, revision, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + pacAndBaseBranches = append(pacAndBaseBranches, TestBranches{ + RepoName: utils.GetRepoName(gitUrl), + BranchName: gitRepoContainsSymlinkBranchName, + PacBranchName: pacBranchName, + BaseBranchName: baseBranchName, + }) + } else { + revision = GetGitRevision(gitUrl) + err = commonCtrl.Github.CreateRef(utils.GetRepoName(gitUrl), "main", revision, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + pacAndBaseBranches = append(pacAndBaseBranches, TestBranches{ + RepoName: utils.GetRepoName(gitUrl), + BranchName: "main", + PacBranchName: pacBranchName, + BaseBranchName: baseBranchName, + }) + } + componentObj := appservice.ComponentSpec{ ComponentName: componentName, Source: appservice.ComponentSource{ ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ URL: gitUrl, - Revision: revision, + Revision: baseBranchName, Context: contextDir, DockerfileURL: dockerfilePath, }, @@ -103,7 +139,7 @@ func CreateComponent(ctrl *has.HasController, gitUrl, revision, applicationName, "build.appstudio.openshift.io/pipeline": fmt.Sprintf(`{"name":"docker-build", "bundle": "%s"}`, customSourceBuildBundle), } } - c, err := ctrl.CreateComponent(componentObj, namespace, "", "", applicationName, false, buildPipelineAnnotation) + c, err := ctrl.CreateComponent(componentObj, namespace, "", "", applicationName, false, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, buildPipelineAnnotation)) Expect(err).ShouldNot(HaveOccurred()) return c.Name } @@ -141,7 +177,7 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", defer GinkgoRecover() Describe("HACBS pipelines", Ordered, Label("pipeline"), func() { - var applicationName, componentName, symlinkComponentName, testNamespace string + var applicationName, componentName, symlinkComponentName, symlinkPRunName, testNamespace string var kubeadminClient *framework.ControllerHub var pipelineRunsWithE2eFinalizer []string @@ -182,7 +218,7 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", for _, gitUrl := range componentUrls { gitUrl := gitUrl componentName = fmt.Sprintf("%s-%s", "test-comp", util.GenerateRandomString(4)) - name := CreateComponent(kubeadminClient.HasController, gitUrl, "", applicationName, componentName, testNamespace) + name := CreateComponent(kubeadminClient.CommonController, kubeadminClient.HasController, gitUrl, "", applicationName, componentName, testNamespace) Expect(name).ShouldNot(BeEmpty()) componentNames = append(componentNames, name) } @@ -190,7 +226,7 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", // Create component for the repo containing symlink symlinkComponentName = fmt.Sprintf("%s-%s", "test-symlink-comp", util.GenerateRandomString(4)) symlinkComponentName = CreateComponent( - kubeadminClient.HasController, pythonComponentGitSourceURL, gitRepoContainsSymlinkBranchName, + kubeadminClient.CommonController, kubeadminClient.HasController, pythonComponentGitSourceURL, gitRepoContainsSymlinkBranchName, applicationName, symlinkComponentName, testNamespace) }) @@ -224,13 +260,24 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue()) } } + //Cleanup pac and base branches + for _, branches := range pacAndBaseBranches { + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(branches.RepoName, branches.PacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(branches.RepoName, branches.BaseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + } }) It(fmt.Sprintf("triggers PipelineRun for symlink component with source URL %s", pythonComponentGitSourceURL), Label(buildTemplatesTestLabel, sourceBuildTestLabel), func() { timeout := time.Minute * 5 - prName := WaitForPipelineRunStarts(kubeadminClient, applicationName, symlinkComponentName, testNamespace, timeout) - Expect(prName).ShouldNot(BeEmpty()) - pipelineRunsWithE2eFinalizer = append(pipelineRunsWithE2eFinalizer, prName) + symlinkPRunName = WaitForPipelineRunStarts(kubeadminClient, applicationName, symlinkComponentName, testNamespace, timeout) + Expect(symlinkPRunName).ShouldNot(BeEmpty()) + pipelineRunsWithE2eFinalizer = append(pipelineRunsWithE2eFinalizer, symlinkPRunName) }) for i, gitUrl := range componentUrls { @@ -637,10 +684,13 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", } It(fmt.Sprintf("pipelineRun should fail for symlink component with Git source URL %s", pythonComponentGitSourceURL), Label(buildTemplatesTestLabel, sourceBuildTestLabel), func() { - component, err := kubeadminClient.HasController.GetComponent(symlinkComponentName, testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - Expect(kubeadminClient.HasController.WaitForComponentPipelineToBeFinished(component, "", - kubeadminClient.TektonController, &has.RetryOptions{Retries: pipelineCompletionRetries}, nil)).Should(MatchError(ContainSubstring("cloned repository contains symlink pointing outside of the cloned repository"))) + pipelineRunTimeout := int(time.Duration(10) * time.Minute) + Expect(f.AsKubeAdmin.TektonController.WatchPipelineRun(symlinkPRunName, testNamespace, pipelineRunTimeout)).To(Succeed()) + pr, err := f.AsKubeAdmin.TektonController.GetPipelineRun(symlinkPRunName, testNamespace) + Expect(err).ShouldNot(HaveOccurred(), "failed to get pipelinerun %s", symlinkPRunName) + tr, err := f.AsKubeAdmin.TektonController.GetTaskRunStatus(f.AsKubeAdmin.CommonController.KubeRest(), pr, "clone-repository") + Expect(err).NotTo(HaveOccurred(), "failed to get taskrun for clone-repository") + Expect(tekton.DidTaskRunSucceed(tr)).To(BeFalse()) }) }) }) diff --git a/tests/build/build_templates_scenarios.go b/tests/build/build_templates_scenarios.go index 44cd2f7062..64eb94a61e 100644 --- a/tests/build/build_templates_scenarios.go +++ b/tests/build/build_templates_scenarios.go @@ -2,10 +2,12 @@ package build import ( "github.com/konflux-ci/e2e-tests/pkg/constants" + "github.com/konflux-ci/e2e-tests/pkg/utils" ) type ComponentScenarioSpec struct { GitURL string + Revision string ContextDir string DockerFilePath string PipelineBundleName string @@ -16,7 +18,8 @@ type ComponentScenarioSpec struct { var componentScenarios = []ComponentScenarioSpec{ { - GitURL: "https://github.com/redhat-appstudio-qe/devfile-sample-python-basic", + GitURL: "https://github.com/konflux-qe-bd/devfile-sample-python-basic", + Revision: "47fc22092005aabebce233a9b6eab994a8152bbd", ContextDir: ".", DockerFilePath: constants.DockerFilePath, PipelineBundleName: "docker-build", @@ -24,7 +27,8 @@ var componentScenarios = []ComponentScenarioSpec{ PrefetchInput: "", }, { - GitURL: "https://github.com/redhat-appstudio-qe/retrodep", + GitURL: "https://github.com/konflux-qe-bd/retrodep", + Revision: "d8e3195d1ab9dbee1f621e3b0625a589114ac80f", ContextDir: ".", DockerFilePath: "Dockerfile", PipelineBundleName: "docker-build", @@ -32,7 +36,8 @@ var componentScenarios = []ComponentScenarioSpec{ PrefetchInput: "gomod", }, { - GitURL: "https://github.com/cachito-testing/pip-e2e-test", + GitURL: "https://github.com/konflux-qe-bd/pip-e2e-test", + Revision: "1ecda839ba9ca55070d75c86c26a1bb07d777bba", ContextDir: ".", DockerFilePath: "Dockerfile", PipelineBundleName: "docker-build", @@ -41,7 +46,8 @@ var componentScenarios = []ComponentScenarioSpec{ CheckAdditionalTags: true, }, { - GitURL: "https://github.com/redhat-appstudio-qe/fbc-sample-repo", + GitURL: "https://github.com/konflux-qe-bd/fbc-sample-repo", + Revision: "8e374e107fecf03f3c64c528bb53798039661414", ContextDir: "4.13", DockerFilePath: "catalog.Dockerfile", PipelineBundleName: "fbc-builder", @@ -49,7 +55,8 @@ var componentScenarios = []ComponentScenarioSpec{ PrefetchInput: "", }, { - GitURL: "https://github.com/redhat-appstudio-qe/source-build-parent-image-with-digest-only", + GitURL: "https://github.com/konflux-qe-bd/source-build-parent-image-with-digest-only", + Revision: "a4f744581c0768eb84a4345f11d04090bb14bdff", ContextDir: ".", DockerFilePath: "Dockerfile", PipelineBundleName: "docker-build", @@ -57,7 +64,8 @@ var componentScenarios = []ComponentScenarioSpec{ PrefetchInput: "", }, { - GitURL: "https://github.com/redhat-appstudio-qe/source-build-use-latest-parent-image", + GitURL: "https://github.com/konflux-qe-bd/source-build-use-latest-parent-image", + Revision: "b4584ac47e1df84114a10debf262b6d40f6a95f8", ContextDir: ".", DockerFilePath: "Dockerfile", PipelineBundleName: "docker-build", @@ -65,7 +73,8 @@ var componentScenarios = []ComponentScenarioSpec{ PrefetchInput: "", }, { - GitURL: "https://github.com/redhat-appstudio-qe/source-build-parent-image-from-registry-rh-io", + GitURL: "https://github.com/konflux-qe-bd/source-build-parent-image-from-registry-rh-io", + Revision: "3f5dcac703a35dcb7b29312be72f86221d0f10ee", ContextDir: ".", DockerFilePath: "Dockerfile", PipelineBundleName: "docker-build", @@ -73,7 +82,8 @@ var componentScenarios = []ComponentScenarioSpec{ PrefetchInput: "", }, { - GitURL: "https://github.com/redhat-appstudio-qe/source-build-base-on-konflux-image", + GitURL: "https://github.com/konflux-qe-bd/source-build-base-on-konflux-image", + Revision: "86c4d160cfafb8976a23030d4bbc1216bfe8e14f", ContextDir: ".", DockerFilePath: "Dockerfile", PipelineBundleName: "docker-build", @@ -82,9 +92,20 @@ var componentScenarios = []ComponentScenarioSpec{ }, } +func GetGitRevision(gitUrl string) string { + for _, componentScenario := range componentScenarios { + //check repo name for both the giturls is same + if utils.GetRepoName(componentScenario.GitURL) == utils.GetRepoName(gitUrl) { + return componentScenario.Revision + } + } + return "" +} + func GetComponentScenarioDetailsFromGitUrl(gitUrl string) (string, string, string, bool, string, bool) { for _, componentScenario := range componentScenarios { - if componentScenario.GitURL == gitUrl { + //check repo name for both the giturls is same + if utils.GetRepoName(componentScenario.GitURL) == utils.GetRepoName(gitUrl) { return componentScenario.ContextDir, componentScenario.DockerFilePath, componentScenario.PipelineBundleName, componentScenario.EnableHermetic, componentScenario.PrefetchInput, componentScenario.CheckAdditionalTags } } diff --git a/tests/build/const.go b/tests/build/const.go index acd19c9f26..0b700bbb8e 100644 --- a/tests/build/const.go +++ b/tests/build/const.go @@ -12,8 +12,8 @@ const ( COMPONENT_REPO_URLS_ENV string = "COMPONENT_REPO_URLS" containerImageSource = "quay.io/redhat-appstudio-qe/busybox-loop@sha256:f698f1f2cf641fe9176d2a277c9052d872f6b1c39e56248a1dd259b96281dda9" - pythonComponentGitSourceURL = "https://github.com/redhat-appstudio-qe/devfile-sample-python-basic" gitRepoContainsSymlinkBranchName = "symlink" + symlinkBranchRevision = "27ecfca9c9dad35e4f07ebbcd706f31cb7ce849f" dummyPipelineBundleRef = "quay.io/redhat-appstudio-qe/dummy-pipeline-bundle@sha256:9805fc3f309af8f838622e49d3e7705d8364eb5c8287043d5725f3ef12232f24" buildTemplatesTestLabel = "build-templates-e2e" buildTemplatesKcpTestLabel = "build-templates-kcp-e2e" @@ -23,6 +23,9 @@ const ( helloWorldComponentDefaultBranch = "default" helloWorldComponentRevision = "d2d03e69de912e3827c29b4c5b71ffe8bcb5dad8" + helloWorldComponentGitSourceCloneRepoName = "devfile-sample-hello-world-clone" + helloWorldComponentCloneRevision = "bb1d243a9c030e715ac2a7829973d226816446c3" + multiComponentGitSourceRepoName = "sample-multi-component" multiComponentDefaultBranch = "main" multiComponentGitRevision = "0d1835404efb8ab7bb1ab5b5b82cda1ebfda4b25" @@ -49,18 +52,21 @@ const ( //Logging related buildStatusAnnotationValueLoggingFormat = "build status annotation value: %s\n" - noAppOrgName = "redhat-appstudio-qe-no-app" + noAppOrgName = "redhat-appstudio-qe-no-app" + pythonComponentRepoName = "devfile-sample-python-basic" ) var ( - additionalTags = []string{"test-tag1", "test-tag2"} - componentUrls = strings.Split(utils.GetEnv(COMPONENT_REPO_URLS_ENV, pythonComponentGitSourceURL), ",") //multiple urls - componentNames []string - gihubOrg = utils.GetEnv(constants.GITHUB_E2E_ORGANIZATION_ENV, "redhat-appstudio-qe") - helloWorldComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, helloWorldComponentGitSourceRepoName) - annotationsTestGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, annotationsTestGitSourceRepoName) - multiComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, multiComponentGitSourceRepoName) - multiComponentContextDirs = []string{"go-component", "python-component"} + additionalTags = []string{"test-tag1", "test-tag2"} + pythonComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, pythonComponentRepoName) + componentUrls = strings.Split(utils.GetEnv(COMPONENT_REPO_URLS_ENV, pythonComponentGitSourceURL), ",") //multiple urls + componentNames []string + gihubOrg = utils.GetEnv(constants.GITHUB_E2E_ORGANIZATION_ENV, "redhat-appstudio-qe") + helloWorldComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, helloWorldComponentGitSourceRepoName) + helloWorldComponentGitSourceCloneURL = fmt.Sprintf(githubUrlFormat, gihubOrg, helloWorldComponentGitSourceCloneRepoName) + annotationsTestGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, annotationsTestGitSourceRepoName) + multiComponentGitSourceURL = fmt.Sprintf(githubUrlFormat, gihubOrg, multiComponentGitSourceRepoName) + multiComponentContextDirs = []string{"go-component", "python-component"} secretLookupComponentOneGitSourceURL = fmt.Sprintf(githubUrlFormat, noAppOrgName, secretLookupGitSourceRepoOneName) secretLookupComponentTwoGitSourceURL = fmt.Sprintf(githubUrlFormat, noAppOrgName, secretLookupGitSourceRepoTwoName) diff --git a/tests/build/jvm-build.go b/tests/build/jvm-build.go index 46d3c11fb6..76aa1aace1 100644 --- a/tests/build/jvm-build.go +++ b/tests/build/jvm-build.go @@ -30,7 +30,7 @@ import ( ) var ( - testProjectGitUrl = utils.GetEnv("JVM_BUILD_SERVICE_TEST_REPO_URL", "https://github.com/redhat-appstudio-qe/hacbs-test-project") + testProjectGitUrl = utils.GetEnv("JVM_BUILD_SERVICE_TEST_REPO_URL", fmt.Sprintf("https://github.com/%s/hacbs-test-project", gihubOrg)) testProjectRevision = utils.GetEnv("JVM_BUILD_SERVICE_TEST_REPO_REVISION", "34da5a8f51fba6a8b7ec75a727d3c72ebb5e1274") ) @@ -41,7 +41,7 @@ var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jv defer GinkgoRecover() - var testNamespace, applicationName, componentName string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName string var component *appservice.Component var timeout, interval time.Duration var customJavaBuilderPipelineAnnotation map[string]string @@ -62,6 +62,16 @@ var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jv Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(testProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(testProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -93,6 +103,12 @@ var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jv componentName = fmt.Sprintf("jvm-build-suite-component-%s", util.GenerateRandomString(6)) + pacBranchName = constants.PaCPullRequestBranchPrefix + componentName + baseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + + err = f.AsKubeAdmin.CommonController.Github.CreateRef(utils.GetRepoName(testProjectGitUrl), "main", testProjectRevision, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + // Create a component with Git Source URL being defined componentObj := appservice.ComponentSpec{ ComponentName: componentName, @@ -100,12 +116,12 @@ var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jv ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ URL: testProjectGitUrl, - Revision: testProjectRevision, + Revision: baseBranchName, }, }, }, } - component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, customJavaBuilderPipelineAnnotation) + component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, customJavaBuilderPipelineAnnotation)) Expect(err).ShouldNot(HaveOccurred()) }) diff --git a/tests/build/multi-platform.go b/tests/build/multi-platform.go index 08b3f75fb4..83c151797a 100644 --- a/tests/build/multi-platform.go +++ b/tests/build/multi-platform.go @@ -53,7 +53,7 @@ const ( var ( IbmVpc = "us-east-default-vpc" - multiPlatformProjectGitUrl = utils.GetEnv("MULTI_PLATFORM_TEST_REPO_URL", "https://github.com/devfile-samples/devfile-sample-go-basic") + multiPlatformProjectGitUrl = utils.GetEnv("MULTI_PLATFORM_TEST_REPO_URL", fmt.Sprintf("https://github.com/%s/devfile-sample-go-basic", gihubOrg)) multiPlatformProjectRevision = utils.GetEnv("MULTI_PLATFORM_TEST_REPO_REVISION", "c713067b0e65fb3de50d1f7c457eb51c2ab0dbb0") timeout = 20 * time.Minute interval = 10 * time.Second @@ -68,7 +68,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Describe("aws host-pool allocation", Label("aws-host-pool"), func() { - var testNamespace, applicationName, componentName, multiPlatformSecretName, host, userDir string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName, multiPlatformSecretName, host, userDir string var component *appservice.Component AfterAll(func() { @@ -84,6 +84,16 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -101,7 +111,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E err = createSecretForHostPool(f) Expect(err).ShouldNot(HaveOccurred()) - component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "ARM64") + component, applicationName, componentName, pacBranchName, baseBranchName = createApplicationAndComponent(f, testNamespace, "ARM64") }) When("the Component with multi-platform-build is created", func() { @@ -176,7 +186,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E }) }) Describe("aws dynamic allocation", Label("aws-dynamic"), func() { - var testNamespace, applicationName, componentName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string var component *appservice.Component AfterAll(func() { @@ -199,6 +209,16 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -221,7 +241,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E err = createSecretsForDynamicInstance(f) Expect(err).ShouldNot(HaveOccurred()) - component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "ARM64") + component, applicationName, componentName, pacBranchName, baseBranchName = createApplicationAndComponent(f, testNamespace, "ARM64") }) When("the Component with multi-platform-build is created", func() { @@ -258,7 +278,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E }) // TODO: Enable the test after https://issues.redhat.com/browse/KFLUXBUGS-1179 is fixed Describe("ibm system z dynamic allocation", Label("ibmz-dynamic"), Pending, func() { - var testNamespace, applicationName, componentName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string var component *appservice.Component AfterAll(func() { @@ -281,6 +301,16 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -300,7 +330,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E err = createSecretsForIbmDynamicInstance(f) Expect(err).ShouldNot(HaveOccurred()) - component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "S390X") + component, applicationName, componentName, pacBranchName, baseBranchName = createApplicationAndComponent(f, testNamespace, "S390X") }) When("the Component with multi-platform-build is created", func() { @@ -337,7 +367,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E }) // TODO: Enable the test after https://issues.redhat.com/browse/KFLUXBUGS-1179 is fixed Describe("ibm power pc dynamic allocation", Label("ibmp-dynamic"), Pending, func() { - var testNamespace, applicationName, componentName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string + var testNamespace, applicationName, componentName, pacBranchName, baseBranchName, multiPlatformSecretName, multiPlatformTaskName, dynamicInstanceTag, instanceId string var component *appservice.Component AfterAll(func() { @@ -360,6 +390,16 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E Expect(f.AsKubeAdmin.CommonController.StoreAllPods(testNamespace)).To(Succeed()) Expect(f.AsKubeAdmin.TektonController.StoreAllPipelineRuns(testNamespace)).To(Succeed()) } + + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = f.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(multiPlatformProjectGitUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) BeforeAll(func() { @@ -380,7 +420,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E err = createSecretsForIbmDynamicInstance(f) Expect(err).ShouldNot(HaveOccurred()) - component, applicationName, componentName = createApplicationAndComponent(f, testNamespace, "PPC64LE") + component, applicationName, componentName, pacBranchName, baseBranchName = createApplicationAndComponent(f, testNamespace, "PPC64LE") }) When("the Component with multi-platform-build is created", func() { @@ -417,7 +457,7 @@ var _ = framework.MultiPlatformBuildSuiteDescribe("Multi Platform Controller E2E }) }) -func createApplicationAndComponent(f *framework.Framework, testNamespace, platform string) (component *appservice.Component, applicationName, componentName string) { +func createApplicationAndComponent(f *framework.Framework, testNamespace, platform string) (component *appservice.Component, applicationName, componentName, pacBranchName, baseBranchName string) { applicationName = fmt.Sprintf("multi-platform-suite-application-%s", util.GenerateRandomString(4)) _, err := f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace) Expect(err).NotTo(HaveOccurred()) @@ -430,6 +470,12 @@ func createApplicationAndComponent(f *framework.Framework, testNamespace, platfo "build.appstudio.openshift.io/pipeline": fmt.Sprintf(`{"name":"buildah-remote-pipeline", "bundle": "%s"}`, customBuildahRemotePipeline), } + pacBranchName = constants.PaCPullRequestBranchPrefix + componentName + baseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + + err = f.AsKubeAdmin.CommonController.Github.CreateRef(utils.GetRepoName(multiPlatformProjectGitUrl), "main", multiPlatformProjectRevision, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + // Create a component with Git Source URL being defined componentObj := appservice.ComponentSpec{ ComponentName: componentName, @@ -437,13 +483,13 @@ func createApplicationAndComponent(f *framework.Framework, testNamespace, platfo ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ URL: multiPlatformProjectGitUrl, - Revision: multiPlatformProjectRevision, + Revision: baseBranchName, DockerfileURL: constants.DockerFilePath, }, }, }, } - component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, buildPipelineAnnotation) + component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, buildPipelineAnnotation)) Expect(err).ShouldNot(HaveOccurred()) return } diff --git a/tests/integration-service/const.go b/tests/integration-service/const.go index f8f9cdb025..e4d48bd4c9 100644 --- a/tests/integration-service/const.go +++ b/tests/integration-service/const.go @@ -8,8 +8,6 @@ import ( ) const ( - componentRepoURL = "https://github.com/redhat-appstudio-qe/hacbs-test-project" - EnvironmentName = "development" gitURL = "https://github.com/konflux-ci/integration-examples.git" revision = "ab868616ab02be79b6abdf85dcd2a3aef321ff14" diff --git a/tests/integration-service/integration-with-env.go b/tests/integration-service/integration-with-env.go deleted file mode 100644 index b5af74beea..0000000000 --- a/tests/integration-service/integration-with-env.go +++ /dev/null @@ -1,179 +0,0 @@ -package integration - -import ( - "fmt" - "strings" - "time" - - "github.com/codeready-toolchain/api/api/v1alpha1" - "github.com/konflux-ci/e2e-tests/pkg/clients/has" - "github.com/konflux-ci/e2e-tests/pkg/framework" - "github.com/konflux-ci/e2e-tests/pkg/utils" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - - appstudioApi "github.com/konflux-ci/application-api/api/v1alpha1" - integrationv1beta2 "github.com/konflux-ci/integration-service/api/v1beta2" - intgteststat "github.com/konflux-ci/integration-service/pkg/integrationteststatus" - k8sErrors "k8s.io/apimachinery/pkg/api/errors" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = framework.IntegrationServiceSuiteDescribe("Integration Service E2E tests", Label("integration-service", "integration-env"), func() { - defer GinkgoRecover() - - var f *framework.Framework - var err error - - var applicationName, componentName, testNamespace string - var integrationTestScenario *integrationv1beta2.IntegrationTestScenario - var timeout, interval time.Duration - var originalComponent *appstudioApi.Component - var pipelineRun, integrationPipelineRun *pipeline.PipelineRun - var snapshot *appstudioApi.Snapshot - var spaceRequest *v1alpha1.SpaceRequest - - AfterEach(framework.ReportFailure(&f)) - - Describe("with happy path for general flow of Integration service with ephemeral environment", Ordered, func() { - BeforeAll(func() { - // Initialize the tests controllers - f, err = framework.NewFramework(utils.GetGeneratedNamespace("integration-env")) - Expect(err).NotTo(HaveOccurred()) - testNamespace = f.UserNamespace - - applicationName = createApp(*f, testNamespace) - componentName, originalComponent = createComponent(*f, testNamespace, applicationName) - integrationTestScenario, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathIntegrationPipelineWithEnv) - Expect(err).ShouldNot(HaveOccurred()) - }) - - AfterAll(func() { - if !CurrentSpecReport().Failed() { - Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue()) - } - }) - - When("a new Component is created", func() { - It("triggers a build PipelineRun", Label("integration-service"), func() { - pipelineRun, err = f.AsKubeDeveloper.IntegrationController.GetBuildPipelineRun(componentName, applicationName, testNamespace, false, "") - Expect(err).ShouldNot(HaveOccurred()) - }) - - It("verifies if the build PipelineRun contains the finalizer", Label("integration-service"), func() { - Eventually(func() error { - pipelineRun, err = f.AsKubeDeveloper.IntegrationController.GetBuildPipelineRun(componentName, applicationName, testNamespace, false, "") - Expect(err).ShouldNot(HaveOccurred()) - if !controllerutil.ContainsFinalizer(pipelineRun, pipelinerunFinalizerByIntegrationService) { - return fmt.Errorf("build pipelineRun %s/%s doesn't contain the finalizer: %s yet", pipelineRun.GetNamespace(), pipelineRun.GetName(), pipelinerunFinalizerByIntegrationService) - } - return nil - }, 1*time.Minute, 1*time.Second).Should(Succeed(), "timeout when waiting for finalizer to be added") - }) - - It("waits for build PipelineRun to succeed", Label("integration-service"), func() { - Expect(pipelineRun.Annotations[snapshotAnnotation]).To(Equal("")) - Expect(f.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(originalComponent, "", - f.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, pipelineRun)).To(Succeed()) - }) - }) - - When("the build pipelineRun run succeeded", func() { - It("checks if the BuildPipelineRun have the annotation of chains signed", func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForBuildPipelineRunToGetAnnotated(testNamespace, applicationName, componentName, chainsSignedAnnotation)).To(Succeed()) - }) - - It("checks if the Snapshot is created", func() { - snapshot, err = f.AsKubeDeveloper.IntegrationController.WaitForSnapshotToGetCreated("", "", componentName, testNamespace) - - }) - - It("checks if the Build PipelineRun got annotated with Snapshot name", func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForBuildPipelineRunToGetAnnotated(testNamespace, applicationName, componentName, snapshotAnnotation)).To(Succeed()) - }) - - It("verifies that the finalizer has been removed from the build pipelinerun", func() { - timeout := "60s" - interval := "1s" - Eventually(func() error { - pipelineRun, err := f.AsKubeDeveloper.IntegrationController.GetBuildPipelineRun(componentName, applicationName, testNamespace, false, "") - if err != nil { - if k8sErrors.IsNotFound(err) { - return nil - } - return fmt.Errorf("error getting PipelineRun: %v", err) - } - if pipelineRun == nil || pipelineRun.Name == "" { - return nil - } - if controllerutil.ContainsFinalizer(pipelineRun, pipelinerunFinalizerByIntegrationService) { - return fmt.Errorf("build PipelineRun %s/%s still contains the finalizer: %s", pipelineRun.GetNamespace(), pipelineRun.GetName(), pipelinerunFinalizerByIntegrationService) - } - return nil - }, timeout, interval).Should(Succeed(), "timeout when waiting for finalizer to be removed") - }) - - It(fmt.Sprintf("checks if CronJob %s exists", spaceRequestCronJobName), func() { - spaceRequestCleanerCronJob, err := f.AsKubeAdmin.CommonController.GetCronJob(spaceRequestCronJobNamespace, spaceRequestCronJobName) - Expect(err).ShouldNot(HaveOccurred()) - Expect(strings.Contains(spaceRequestCleanerCronJob.Name, spaceRequestCronJobName)).Should(BeTrue()) - }) - - It("checks if all of the integrationPipelineRuns passed", Label("slow"), func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForAllIntegrationPipelinesToBeFinished(testNamespace, applicationName, snapshot)).To(Succeed()) - }) - - It("checks if space request is created in namespace", func() { - spaceRequestsList, err := f.AsKubeAdmin.GitOpsController.GetSpaceRequests(testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - - Expect(spaceRequestsList.Items).To(HaveLen(1), "Expected spaceRequestsList.Items to have at least one item") - spaceRequest = &spaceRequestsList.Items[0] - Expect(strings.Contains(spaceRequest.Name, spaceRequestNamePrefix)).Should(BeTrue()) - }) - - It("checks if the passed status of integration test is reported in the Snapshot", func() { - timeout = time.Second * 240 - interval = time.Second * 5 - Eventually(func() error { - snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - - statusDetail, err := f.AsKubeDeveloper.IntegrationController.GetIntegrationTestStatusDetailFromSnapshot(snapshot, integrationTestScenario.Name) - Expect(err).ToNot(HaveOccurred()) - - if statusDetail.Status != intgteststat.IntegrationTestStatusTestPassed { - return fmt.Errorf("test status for scenario: %s, doesn't have expected value %s, within the snapshot: %s", integrationTestScenario.Name, intgteststat.IntegrationTestStatusTestPassed, snapshot.Name) - } - return nil - }, timeout, interval).Should(Succeed()) - }) - - It("checks if the finalizer was removed from all of the related Integration pipelineRuns", func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForFinalizerToGetRemovedFromAllIntegrationPipelineRuns(testNamespace, applicationName, snapshot)).To(Succeed()) - }) - - It("checks that when deleting integration test scenario pipelineRun, spaceRequest is deleted too", func() { - integrationPipelineRun, err = f.AsKubeAdmin.IntegrationController.GetIntegrationPipelineRun(integrationTestScenario.Name, snapshot.Name, testNamespace) - Expect(err).ToNot(HaveOccurred()) - Expect(f.AsKubeDeveloper.TektonController.DeletePipelineRun(integrationPipelineRun.Name, integrationPipelineRun.Namespace)).To(Succeed()) - - timeout = time.Second * 200 - interval = time.Second * 5 - Eventually(func() error { - currentSpaceRequest, err := f.AsKubeAdmin.GitOpsController.GetSpaceRequest(testNamespace, spaceRequest.Name) - if err != nil { - if k8sErrors.IsNotFound(err) { - return nil - } - return fmt.Errorf("failed to get %s/%s spaceRequest: %+v", currentSpaceRequest.Namespace, currentSpaceRequest.Name, err) - } - return fmt.Errorf("spaceRequest %s/%s still exists", currentSpaceRequest.Namespace, currentSpaceRequest.Name) - }, timeout, interval).Should(Succeed()) - - }) - }) - }) -}) diff --git a/tests/integration-service/integration.go b/tests/integration-service/integration.go deleted file mode 100644 index 83697b519d..0000000000 --- a/tests/integration-service/integration.go +++ /dev/null @@ -1,380 +0,0 @@ -package integration - -import ( - "fmt" - "time" - - "github.com/konflux-ci/operator-toolkit/metadata" - - "github.com/devfile/library/v2/pkg/util" - "github.com/konflux-ci/e2e-tests/pkg/clients/has" - "github.com/konflux-ci/e2e-tests/pkg/constants" - "github.com/konflux-ci/e2e-tests/pkg/framework" - "github.com/konflux-ci/e2e-tests/pkg/utils" - pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - - integrationv1beta2 "github.com/konflux-ci/integration-service/api/v1beta2" - intgteststat "github.com/konflux-ci/integration-service/pkg/integrationteststatus" - - appstudioApi "github.com/konflux-ci/application-api/api/v1alpha1" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" -) - -var _ = framework.IntegrationServiceSuiteDescribe("Integration Service E2E tests", Label("integration-service"), func() { - defer GinkgoRecover() - - var f *framework.Framework - var err error - - var applicationName, componentName, testNamespace string - var integrationTestScenario *integrationv1beta2.IntegrationTestScenario - var newIntegrationTestScenario *integrationv1beta2.IntegrationTestScenario - var timeout, interval time.Duration - var originalComponent *appstudioApi.Component - var pipelineRun *pipeline.PipelineRun - var snapshot *appstudioApi.Snapshot - var snapshotPush *appstudioApi.Snapshot - AfterEach(framework.ReportFailure(&f)) - - Describe("with happy path for general flow of Integration service", Ordered, func() { - BeforeAll(func() { - // Initialize the tests controllers - f, err = framework.NewFramework(utils.GetGeneratedNamespace("integration1")) - Expect(err).NotTo(HaveOccurred()) - testNamespace = f.UserNamespace - - applicationName = createApp(*f, testNamespace) - componentName, originalComponent = createComponent(*f, testNamespace, applicationName) - integrationTestScenario, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathInRepoPass) - Expect(err).ShouldNot(HaveOccurred()) - }) - - AfterAll(func() { - if !CurrentSpecReport().Failed() { - cleanup(*f, testNamespace, applicationName, componentName) - - Expect(f.AsKubeAdmin.IntegrationController.DeleteSnapshot(snapshotPush, testNamespace)).To(Succeed()) - } - }) - - When("a new Component is created", func() { - It("triggers a build PipelineRun", Label("integration-service"), func() { - pipelineRun, err = f.AsKubeDeveloper.IntegrationController.GetBuildPipelineRun(componentName, applicationName, testNamespace, false, "") - Expect(err).ShouldNot(HaveOccurred()) - }) - - It("verifies if the build PipelineRun contains the finalizer", Label("integration-service"), func() { - Eventually(func() error { - pipelineRun, err = f.AsKubeDeveloper.IntegrationController.GetBuildPipelineRun(componentName, applicationName, testNamespace, false, "") - Expect(err).ShouldNot(HaveOccurred()) - if !controllerutil.ContainsFinalizer(pipelineRun, pipelinerunFinalizerByIntegrationService) { - return fmt.Errorf("build pipelineRun %s/%s doesn't contain the finalizer: %s yet", pipelineRun.GetNamespace(), pipelineRun.GetName(), pipelinerunFinalizerByIntegrationService) - } - return nil - }, 1*time.Minute, 1*time.Second).Should(Succeed(), "timeout when waiting for finalizer to be added") - }) - - It("waits for build PipelineRun to succeed", Label("integration-service"), func() { - Expect(pipelineRun.Annotations[snapshotAnnotation]).To(Equal("")) - Expect(f.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(originalComponent, "", - f.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, pipelineRun)).To(Succeed()) - }) - }) - - When("the build pipelineRun run succeeded", func() { - It("checks if the BuildPipelineRun have the annotation of chains signed", func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForBuildPipelineRunToGetAnnotated(testNamespace, applicationName, componentName, chainsSignedAnnotation)).To(Succeed()) - }) - - It("checks if the Snapshot is created", func() { - snapshot, err = f.AsKubeDeveloper.IntegrationController.WaitForSnapshotToGetCreated("", "", componentName, testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - }) - - It("checks if the Build PipelineRun got annotated with Snapshot name", func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForBuildPipelineRunToGetAnnotated(testNamespace, applicationName, componentName, snapshotAnnotation)).To(Succeed()) - }) - - It("verifies that the finalizer has been removed from the build pipelinerun", func() { - timeout := "60s" - interval := "1s" - Eventually(func() error { - pipelineRun, err = f.AsKubeDeveloper.IntegrationController.GetBuildPipelineRun(componentName, applicationName, testNamespace, false, "") - Expect(err).ShouldNot(HaveOccurred()) - if controllerutil.ContainsFinalizer(pipelineRun, pipelinerunFinalizerByIntegrationService) { - return fmt.Errorf("build pipelineRun %s/%s still contains the finalizer: %s", pipelineRun.GetNamespace(), pipelineRun.GetName(), pipelinerunFinalizerByIntegrationService) - } - return nil - }, timeout, interval).Should(Succeed(), "timeout when waiting for finalizer to be removed") - }) - - It("checks if all of the integrationPipelineRuns passed", Label("slow"), func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForAllIntegrationPipelinesToBeFinished(testNamespace, applicationName, snapshot)).To(Succeed()) - }) - - It("checks if the passed status of integration test is reported in the Snapshot", func() { - timeout = time.Second * 240 - interval = time.Second * 5 - Eventually(func() error { - snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - - statusDetail, err := f.AsKubeDeveloper.IntegrationController.GetIntegrationTestStatusDetailFromSnapshot(snapshot, integrationTestScenario.Name) - Expect(err).ToNot(HaveOccurred()) - - if statusDetail.Status != intgteststat.IntegrationTestStatusTestPassed { - return fmt.Errorf("test status for scenario: %s, doesn't have expected value %s, within the snapshot: %s", integrationTestScenario.Name, intgteststat.IntegrationTestStatusTestPassed, snapshot.Name) - } - return nil - }, timeout, interval).Should(Succeed()) - }) - - It("checks if the finalizer was removed from all of the related Integration pipelineRuns", func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForFinalizerToGetRemovedFromAllIntegrationPipelineRuns(testNamespace, applicationName, snapshot)).To(Succeed()) - }) - }) - - It("creates a ReleasePlan", func() { - _, err = f.AsKubeAdmin.ReleaseController.CreateReleasePlan(autoReleasePlan, testNamespace, applicationName, targetReleaseNamespace, "", nil, nil) - Expect(err).ShouldNot(HaveOccurred()) - testScenarios, err := f.AsKubeAdmin.IntegrationController.GetIntegrationTestScenarios(applicationName, testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - for _, testScenario := range *testScenarios { - GinkgoWriter.Printf("IntegrationTestScenario %s is found\n", testScenario.Name) - } - }) - - It("creates an snapshot of push event", func() { - sampleImage := "quay.io/redhat-appstudio/sample-image@sha256:841328df1b9f8c4087adbdcfec6cc99ac8308805dea83f6d415d6fb8d40227c1" - snapshotPush, err = f.AsKubeAdmin.IntegrationController.CreateSnapshotWithImage(componentName, applicationName, testNamespace, sampleImage) - Expect(err).ShouldNot(HaveOccurred()) - }) - - When("An snapshot of push event is created", func() { - It("checks if the global candidate is updated after push event", func() { - timeout = time.Second * 600 - interval = time.Second * 10 - Eventually(func() error { - snapshotPush, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshotPush.Name, "", "", testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - - component, err := f.AsKubeAdmin.HasController.GetComponentByApplicationName(applicationName, testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - Expect(component.Spec.ContainerImage).ToNot(Equal(originalComponent.Spec.ContainerImage)) - return nil - - }, timeout, interval).Should(Succeed(), fmt.Sprintf("time out when waiting for updating the global candidate in %s namespace", testNamespace)) - }) - - It("checks if all of the integrationPipelineRuns created by push event passed", Label("slow"), func() { - Expect(f.AsKubeAdmin.IntegrationController.WaitForAllIntegrationPipelinesToBeFinished(testNamespace, applicationName, snapshotPush)).To(Succeed(), "Error when waiting for one of the integration pipelines to finish in %s namespace", testNamespace) - }) - - It("checks if a Release is created successfully", func() { - timeout = time.Second * 60 - interval = time.Second * 5 - Eventually(func() error { - _, err := f.AsKubeAdmin.ReleaseController.GetReleases(testNamespace) - return err - }, timeout, interval).Should(Succeed(), fmt.Sprintf("time out when waiting for release created for snapshot %s/%s", snapshotPush.GetNamespace(), snapshotPush.GetName())) - }) - }) - }) - - Describe("with an integration test fail", Ordered, func() { - BeforeAll(func() { - // Initialize the tests controllers - f, err = framework.NewFramework(utils.GetGeneratedNamespace("integration2")) - Expect(err).NotTo(HaveOccurred()) - testNamespace = f.UserNamespace - - applicationName = createApp(*f, testNamespace) - componentName, originalComponent = createComponent(*f, testNamespace, applicationName) - - integrationTestScenario, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathInRepoFail) - Expect(err).ShouldNot(HaveOccurred()) - }) - - AfterAll(func() { - if !CurrentSpecReport().Failed() { - cleanup(*f, testNamespace, applicationName, componentName) - - } - }) - - It("triggers a build PipelineRun", Label("integration-service"), func() { - pipelineRun, err = f.AsKubeDeveloper.IntegrationController.GetBuildPipelineRun(componentName, applicationName, testNamespace, false, "") - Expect(pipelineRun.Annotations[snapshotAnnotation]).To(Equal("")) - Expect(f.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(originalComponent, "", f.AsKubeAdmin.TektonController, - &has.RetryOptions{Retries: 2, Always: true}, pipelineRun)).To(Succeed()) - - }) - - It("checks if the BuildPipelineRun have the annotation of chains signed", func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForBuildPipelineRunToGetAnnotated(testNamespace, applicationName, componentName, chainsSignedAnnotation)).To(Succeed()) - }) - - It("checks if the Snapshot is created", func() { - snapshot, err = f.AsKubeDeveloper.IntegrationController.WaitForSnapshotToGetCreated("", pipelineRun.Name, componentName, testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - }) - - It("checks if the Build PipelineRun got annotated with Snapshot name", func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForBuildPipelineRunToGetAnnotated(testNamespace, applicationName, componentName, snapshotAnnotation)).To(Succeed()) - }) - - It("checks if all of the integrationPipelineRuns finished", Label("slow"), func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForAllIntegrationPipelinesToBeFinished(testNamespace, applicationName, snapshot)).To(Succeed()) - }) - - It("checks if the failed status of integration test is reported in the Snapshot", func() { - Eventually(func() error { - snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - - statusDetail, err := f.AsKubeDeveloper.IntegrationController.GetIntegrationTestStatusDetailFromSnapshot(snapshot, integrationTestScenario.Name) - Expect(err).ToNot(HaveOccurred()) - - if statusDetail.Status != intgteststat.IntegrationTestStatusTestFail { - return fmt.Errorf("test status doesn't have expected value %s", intgteststat.IntegrationTestStatusTestFail) - } - return nil - }, timeout, interval).Should(Succeed()) - }) - - It("checks if snapshot is marked as failed", FlakeAttempts(3), func() { - snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - Expect(f.AsKubeAdmin.CommonController.HaveTestsSucceeded(snapshot)).To(BeFalse(), "expected tests to fail for snapshot %s/%s", snapshot.GetNamespace(), snapshot.GetName()) - }) - - It("checks if the finalizer was removed from all of the related Integration pipelineRuns", func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForFinalizerToGetRemovedFromAllIntegrationPipelineRuns(testNamespace, applicationName, snapshot)).To(Succeed()) - }) - - It("creates a new IntegrationTestScenario", func() { - newIntegrationTestScenario, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathInRepoPass) - Expect(err).ShouldNot(HaveOccurred()) - }) - - It("updates the Snapshot with the re-run label for the new scenario", FlakeAttempts(3), func() { - updatedSnapshot := snapshot.DeepCopy() - err := metadata.AddLabels(updatedSnapshot, map[string]string{snapshotRerunLabel: newIntegrationTestScenario.Name}) - Expect(err).ShouldNot(HaveOccurred()) - Expect(f.AsKubeAdmin.IntegrationController.PatchSnapshot(snapshot, updatedSnapshot)).Should(Succeed()) - Expect(metadata.GetLabelsWithPrefix(updatedSnapshot, snapshotRerunLabel)).NotTo(BeEmpty()) - }) - - When("An snapshot is updated with a re-run label for a given scenario", func() { - It("checks if the new integration pipelineRun started", Label("slow"), func() { - reRunPipelineRun, err := f.AsKubeDeveloper.IntegrationController.WaitForIntegrationPipelineToGetStarted(newIntegrationTestScenario.Name, snapshot.Name, testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - Expect(reRunPipelineRun).ShouldNot(BeNil()) - }) - - It("checks if the re-run label was removed from the Snapshot", func() { - Eventually(func() error { - snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) - if err != nil { - return fmt.Errorf("encountered error while getting Snapshot %s/%s: %w", snapshot.Name, snapshot.Namespace, err) - } - - if metadata.HasLabel(snapshot, snapshotRerunLabel) { - return fmt.Errorf("the Snapshot %s/%s shouldn't contain the %s label", snapshot.Name, snapshot.Namespace, snapshotRerunLabel) - } - return nil - }, timeout, interval).Should(Succeed()) - }) - - It("checks if all integration pipelineRuns finished successfully", Label("slow"), func() { - Expect(f.AsKubeDeveloper.IntegrationController.WaitForAllIntegrationPipelinesToBeFinished(testNamespace, applicationName, snapshot)).To(Succeed()) - }) - - It("checks if the name of the re-triggered pipelinerun is reported in the Snapshot", FlakeAttempts(3), func() { - Eventually(func(g Gomega) { - snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) - g.Expect(err).ShouldNot(HaveOccurred()) - - statusDetail, err := f.AsKubeDeveloper.IntegrationController.GetIntegrationTestStatusDetailFromSnapshot(snapshot, newIntegrationTestScenario.Name) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(statusDetail).NotTo(BeNil()) - - integrationPipelineRun, err := f.AsKubeDeveloper.IntegrationController.GetIntegrationPipelineRun(newIntegrationTestScenario.Name, snapshot.Name, testNamespace) - g.Expect(err).ToNot(HaveOccurred()) - g.Expect(integrationPipelineRun).NotTo(BeNil()) - - g.Expect(statusDetail.TestPipelineRunName).To(Equal(integrationPipelineRun.Name)) - }, timeout, interval).Should(Succeed()) - }) - - It("checks if snapshot is still marked as failed", func() { - snapshot, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshot.Name, "", "", testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - Expect(f.AsKubeAdmin.CommonController.HaveTestsSucceeded(snapshot)).To(BeFalse(), "expected tests to fail for snapshot %s/%s", snapshot.GetNamespace(), snapshot.GetName()) - }) - - }) - - It("creates an snapshot of push event", func() { - sampleImage := "quay.io/redhat-appstudio/sample-image@sha256:841328df1b9f8c4087adbdcfec6cc99ac8308805dea83f6d415d6fb8d40227c1" - snapshotPush, err = f.AsKubeAdmin.IntegrationController.CreateSnapshotWithImage(componentName, applicationName, testNamespace, sampleImage) - Expect(err).ShouldNot(HaveOccurred()) - }) - - When("An snapshot of push event is created", func() { - It("checks no Release CRs are created", func() { - releases, err := f.AsKubeAdmin.ReleaseController.GetReleases(testNamespace) - Expect(err).NotTo(HaveOccurred(), "Error when fetching the Releases") - Expect(releases.Items).To(BeEmpty(), "Expected no Release CRs to be present, but found some") - }) - }) - }) -}) - -func createApp(f framework.Framework, testNamespace string) string { - applicationName := fmt.Sprintf("integ-app-%s", util.GenerateRandomString(4)) - - _, err := f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace) - Expect(err).NotTo(HaveOccurred()) - - return applicationName -} - -func createComponent(f framework.Framework, testNamespace, applicationName string) (string, *appstudioApi.Component) { - - componentName := fmt.Sprintf("integration-suite-test-component-git-source-%s", util.GenerateRandomString(6)) - - componentObj := appstudioApi.ComponentSpec{ - ComponentName: componentName, - Application: applicationName, - Source: appstudioApi.ComponentSource{ - ComponentSourceUnion: appstudioApi.ComponentSourceUnion{ - GitSource: &appstudioApi.GitSource{ - URL: componentRepoURL, - }, - }, - }, - } - - originalComponent, err := f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, constants.DefaultDockerBuildPipelineBundle) - Expect(err).NotTo(HaveOccurred()) - - return componentName, originalComponent -} - -func cleanup(f framework.Framework, testNamespace, applicationName, componentName string) { - if !CurrentSpecReport().Failed() { - Expect(f.AsKubeAdmin.HasController.DeleteApplication(applicationName, testNamespace, false)).To(Succeed()) - Expect(f.AsKubeAdmin.HasController.DeleteComponent(componentName, testNamespace, false)).To(Succeed()) - integrationTestScenarios, err := f.AsKubeAdmin.IntegrationController.GetIntegrationTestScenarios(applicationName, testNamespace) - Expect(err).ShouldNot(HaveOccurred()) - - for _, testScenario := range *integrationTestScenarios { - Expect(f.AsKubeAdmin.IntegrationController.DeleteIntegrationTestScenario(&testScenario, testNamespace)).To(Succeed()) - } - Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue()) - } -} diff --git a/tests/integration-service/status-reporting-to-pullrequest.go b/tests/integration-service/status-reporting-to-pullrequest.go index 90e320da90..7d80eda71c 100644 --- a/tests/integration-service/status-reporting-to-pullrequest.go +++ b/tests/integration-service/status-reporting-to-pullrequest.go @@ -3,19 +3,22 @@ package integration import ( "fmt" "os" + "strings" "time" + "github.com/codeready-toolchain/api/api/v1alpha1" "github.com/devfile/library/v2/pkg/util" + appstudioApi "github.com/konflux-ci/application-api/api/v1alpha1" "github.com/konflux-ci/e2e-tests/pkg/clients/has" "github.com/konflux-ci/e2e-tests/pkg/constants" "github.com/konflux-ci/e2e-tests/pkg/framework" "github.com/konflux-ci/e2e-tests/pkg/utils" - - appstudioApi "github.com/konflux-ci/application-api/api/v1alpha1" integrationv1beta2 "github.com/konflux-ci/integration-service/api/v1beta2" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" + k8sErrors "k8s.io/apimachinery/pkg/api/errors" + "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" ) var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integration tests", Label("integration-service", "github-status-reporting"), func() { @@ -28,9 +31,11 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati var timeout, interval time.Duration var prHeadSha string var snapshot *appstudioApi.Snapshot + var snapshotPush *appstudioApi.Snapshot var component *appstudioApi.Component + var spaceRequest *v1alpha1.SpaceRequest var pipelineRun, testPipelinerun *pipeline.PipelineRun - var integrationTestScenarioPass, integrationTestScenarioFail *integrationv1beta2.IntegrationTestScenario + var integrationTestScenarioPass, integrationTestScenarioFail, integrationTestScenarioEnv *integrationv1beta2.IntegrationTestScenario var applicationName, componentName, componentBaseBranchName, pacBranchName, testNamespace string AfterEach(framework.ReportFailure(&f)) @@ -57,6 +62,9 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati integrationTestScenarioFail, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathInRepoFail) Expect(err).ShouldNot(HaveOccurred()) + integrationTestScenarioEnv, err = f.AsKubeAdmin.IntegrationController.CreateIntegrationTestScenario("", applicationName, testNamespace, gitURL, revision, pathIntegrationPipelineWithEnv) + Expect(err).ShouldNot(HaveOccurred()) + componentName = fmt.Sprintf("%s-%s", "test-component-pac", util.GenerateRandomString(6)) pacBranchName = constants.PaCPullRequestBranchPrefix + componentName componentBaseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) @@ -117,6 +125,16 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati It("does not contain an annotation with a Snapshot Name", func() { Expect(pipelineRun.Annotations[snapshotAnnotation]).To(Equal("")) }) + It("verifies if the build PipelineRun contains the finalizer", func() { + Eventually(func() error { + pipelineRun, err = f.AsKubeDeveloper.IntegrationController.GetBuildPipelineRun(componentName, applicationName, testNamespace, true, "") + Expect(err).ShouldNot(HaveOccurred()) + if !controllerutil.ContainsFinalizer(pipelineRun, pipelinerunFinalizerByIntegrationService) { + return fmt.Errorf("build pipelineRun %s/%s doesn't contain the finalizer: %s yet", pipelineRun.GetNamespace(), pipelineRun.GetName(), pipelinerunFinalizerByIntegrationService) + } + return nil + }, 1*time.Minute, 1*time.Second).Should(Succeed(), "timeout when waiting for finalizer to be added") + }) It("should lead to build PipelineRun finishing successfully", func() { Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component, "", f.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, pipelineRun)).To(Succeed()) @@ -163,6 +181,23 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati It("checks if the Build PipelineRun got annotated with Snapshot name", func() { Expect(f.AsKubeDeveloper.IntegrationController.WaitForBuildPipelineRunToGetAnnotated(testNamespace, applicationName, componentName, snapshotAnnotation)).To(Succeed()) }) + + It("verifies that the finalizer has been removed from the build pipelinerun", func() { + Eventually(func() error { + pipelineRun, err = f.AsKubeDeveloper.IntegrationController.GetBuildPipelineRun(componentName, applicationName, testNamespace, true, "") + Expect(err).ShouldNot(HaveOccurred()) + if controllerutil.ContainsFinalizer(pipelineRun, pipelinerunFinalizerByIntegrationService) { + return fmt.Errorf("build pipelineRun %s/%s still contains the finalizer: %s", pipelineRun.GetNamespace(), pipelineRun.GetName(), pipelinerunFinalizerByIntegrationService) + } + return nil + }, 60*time.Second, 1*time.Second).Should(Succeed(), "timeout when waiting for finalizer to be removed") + }) + + It(fmt.Sprintf("checks if CronJob %s exists", spaceRequestCronJobName), func() { + spaceRequestCleanerCronJob, err := f.AsKubeAdmin.CommonController.GetCronJob(spaceRequestCronJobNamespace, spaceRequestCronJobName) + Expect(err).ShouldNot(HaveOccurred()) + Expect(strings.Contains(spaceRequestCleanerCronJob.Name, spaceRequestCronJobName)).Should(BeTrue()) + }) }) When("the Snapshot was created", func() { @@ -176,6 +211,11 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati Expect(err).ToNot(HaveOccurred()) Expect(testPipelinerun.Labels[snapshotAnnotation]).To(ContainSubstring(snapshot.Name)) Expect(testPipelinerun.Labels[scenarioAnnotation]).To(ContainSubstring(integrationTestScenarioFail.Name)) + + testPipelinerun, err = f.AsKubeDeveloper.IntegrationController.WaitForIntegrationPipelineToGetStarted(integrationTestScenarioEnv.Name, snapshot.Name, testNamespace) + Expect(err).ToNot(HaveOccurred()) + Expect(testPipelinerun.Labels[snapshotAnnotation]).To(ContainSubstring(snapshot.Name)) + Expect(testPipelinerun.Labels[scenarioAnnotation]).To(ContainSubstring(integrationTestScenarioEnv.Name)) }) }) @@ -183,6 +223,16 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati It("should eventually complete successfully", func() { Expect(f.AsKubeAdmin.IntegrationController.WaitForIntegrationPipelineToBeFinished(integrationTestScenarioPass, snapshot, testNamespace)).To(Succeed(), fmt.Sprintf("Error when waiting for an integration pipelinerun for snapshot %s/%s to finish", testNamespace, snapshot.GetName())) Expect(f.AsKubeAdmin.IntegrationController.WaitForIntegrationPipelineToBeFinished(integrationTestScenarioFail, snapshot, testNamespace)).To(Succeed(), fmt.Sprintf("Error when waiting for an integration pipelinerun for snapshot %s/%s to finish", testNamespace, snapshot.GetName())) + Expect(f.AsKubeAdmin.IntegrationController.WaitForIntegrationPipelineToBeFinished(integrationTestScenarioEnv, snapshot, testNamespace)).To(Succeed(), fmt.Sprintf("Error when waiting for an integration pipelinerun for snapshot %s/%s to finish", testNamespace, snapshot.GetName())) + }) + + It("checks if space request is created in namespace", func() { + spaceRequestsList, err := f.AsKubeAdmin.GitOpsController.GetSpaceRequests(testNamespace) + Expect(err).ShouldNot(HaveOccurred()) + + Expect(spaceRequestsList.Items).To(HaveLen(1), "Expected spaceRequestsList.Items to have at least one item") + spaceRequest = &spaceRequestsList.Items[0] + Expect(strings.Contains(spaceRequest.Name, spaceRequestNamePrefix)).Should(BeTrue()) }) }) @@ -200,6 +250,99 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati It("eventually leads to the status reported at Checks tab for the failed Integration PipelineRun", func() { Expect(f.AsKubeAdmin.CommonController.Github.GetCheckRunConclusion(integrationTestScenarioFail.Name, componentRepoNameForStatusReporting, prHeadSha, prNumber)).To(Equal(constants.CheckrunConclusionFailure)) }) + + It("checks if the finalizer was removed from all of the related Integration pipelineRuns", func() { + Expect(f.AsKubeDeveloper.IntegrationController.WaitForFinalizerToGetRemovedFromAllIntegrationPipelineRuns(testNamespace, applicationName, snapshot)).To(Succeed()) + }) + + It("checks that when deleting integration test scenario pipelineRun, spaceRequest is deleted too", func() { + testPipelinerun, err = f.AsKubeAdmin.IntegrationController.GetIntegrationPipelineRun(integrationTestScenarioEnv.Name, snapshot.Name, testNamespace) + Expect(err).ToNot(HaveOccurred()) + Expect(f.AsKubeDeveloper.TektonController.DeletePipelineRun(testPipelinerun.Name, testPipelinerun.Namespace)).To(Succeed()) + + timeout = time.Second * 200 + interval = time.Second * 5 + Eventually(func() error { + currentSpaceRequest, err := f.AsKubeAdmin.GitOpsController.GetSpaceRequest(testNamespace, spaceRequest.Name) + if err != nil { + if k8sErrors.IsNotFound(err) { + return nil + } + return fmt.Errorf("failed to get %s/%s spaceRequest: %+v", currentSpaceRequest.Namespace, currentSpaceRequest.Name, err) + } + return fmt.Errorf("spaceRequest %s/%s still exists", currentSpaceRequest.Namespace, currentSpaceRequest.Name) + }, timeout, interval).Should(Succeed()) + + }) + }) + + It("creates a ReleasePlan", func() { + _, err = f.AsKubeAdmin.ReleaseController.CreateReleasePlan(autoReleasePlan, testNamespace, applicationName, targetReleaseNamespace, "", nil, nil) + Expect(err).ShouldNot(HaveOccurred()) + testScenarios, err := f.AsKubeAdmin.IntegrationController.GetIntegrationTestScenarios(applicationName, testNamespace) + Expect(err).ShouldNot(HaveOccurred()) + for _, testScenario := range *testScenarios { + GinkgoWriter.Printf("IntegrationTestScenario %s is found\n", testScenario.Name) + } + }) + + It("creates an snapshot of push event", func() { + sampleImage := "quay.io/redhat-appstudio/sample-image@sha256:841328df1b9f8c4087adbdcfec6cc99ac8308805dea83f6d415d6fb8d40227c1" + snapshotPush, err = f.AsKubeAdmin.IntegrationController.CreateSnapshotWithImage(componentName, applicationName, testNamespace, sampleImage) + Expect(err).ShouldNot(HaveOccurred()) + }) + + When("An snapshot of push event is created", func() { + It("checks if the global candidate is updated after push event", func() { + timeout = time.Second * 600 + interval = time.Second * 10 + Eventually(func() error { + snapshotPush, err = f.AsKubeAdmin.IntegrationController.GetSnapshot(snapshotPush.Name, "", "", testNamespace) + Expect(err).ShouldNot(HaveOccurred()) + + latestComponent, err := f.AsKubeAdmin.HasController.GetComponentByApplicationName(applicationName, testNamespace) + Expect(err).ShouldNot(HaveOccurred()) + Expect(latestComponent.Spec.ContainerImage).ToNot(Equal(component.Spec.ContainerImage)) + return nil + + }, timeout, interval).Should(Succeed(), fmt.Sprintf("time out when waiting for updating the global candidate in %s namespace", testNamespace)) + }) + + It("checks if all of the integrationPipelineRuns created by push event passed", Label("slow"), func() { + Expect(f.AsKubeAdmin.IntegrationController.WaitForAllIntegrationPipelinesToBeFinished(testNamespace, applicationName, snapshotPush)).To(Succeed(), "Error when waiting for one of the integration pipelines to finish in %s namespace", testNamespace) + }) + + It("checks if a Release is created successfully", func() { + timeout = time.Second * 60 + interval = time.Second * 5 + Eventually(func() error { + _, err := f.AsKubeAdmin.ReleaseController.GetReleases(testNamespace) + return err + }, timeout, interval).Should(Succeed(), fmt.Sprintf("time out when waiting for release created for snapshot %s/%s", snapshotPush.GetNamespace(), snapshotPush.GetName())) + }) }) }) }) + +func createApp(f framework.Framework, testNamespace string) string { + applicationName := fmt.Sprintf("integ-app-%s", util.GenerateRandomString(4)) + + _, err := f.AsKubeAdmin.HasController.CreateApplication(applicationName, testNamespace) + Expect(err).NotTo(HaveOccurred()) + + return applicationName +} + +func cleanup(f framework.Framework, testNamespace, applicationName, componentName string) { + if !CurrentSpecReport().Failed() { + Expect(f.AsKubeAdmin.HasController.DeleteApplication(applicationName, testNamespace, false)).To(Succeed()) + Expect(f.AsKubeAdmin.HasController.DeleteComponent(componentName, testNamespace, false)).To(Succeed()) + integrationTestScenarios, err := f.AsKubeAdmin.IntegrationController.GetIntegrationTestScenarios(applicationName, testNamespace) + Expect(err).ShouldNot(HaveOccurred()) + + for _, testScenario := range *integrationTestScenarios { + Expect(f.AsKubeAdmin.IntegrationController.DeleteIntegrationTestScenario(&testScenario, testNamespace)).To(Succeed()) + } + Expect(f.SandboxController.DeleteUserSignup(f.UserName)).To(BeTrue()) + } +} diff --git a/tests/konflux-demo/config/scenarios.go b/tests/konflux-demo/config/scenarios.go index 430dfde49b..9cf524ca6f 100644 --- a/tests/konflux-demo/config/scenarios.go +++ b/tests/konflux-demo/config/scenarios.go @@ -24,7 +24,7 @@ var TestScenarios = []TestSpec{ { Name: "konflux-demo-component", Language: "Java", - GitSourceUrl: fmt.Sprintf("https://github.com/%s/%s", utils.GetEnv(constants.GITHUB_E2E_ORGANIZATION_ENV, "redhat-appstudio-qe"), "hacbs-test-project"), + GitSourceUrl: fmt.Sprintf("https://github.com/%s/%s", utils.GetEnv(constants.GITHUB_E2E_ORGANIZATION_ENV, "redhat-appstudio-qe"), "hacbs-test-project-konflux-demo"), GitSourceRevision: "34da5a8f51fba6a8b7ec75a727d3c72ebb5e1274", GitSourceContext: "", GitSourceDefaultBranchName: "main", diff --git a/tests/release/const.go b/tests/release/const.go index ef49274cf7..374894fb97 100644 --- a/tests/release/const.go +++ b/tests/release/const.go @@ -1,8 +1,10 @@ package common import ( + "fmt" "time" + "github.com/konflux-ci/e2e-tests/pkg/constants" "github.com/konflux-ci/e2e-tests/pkg/utils" corev1 "k8s.io/api/core/v1" ) @@ -34,9 +36,11 @@ const ( // Pipelines constants ComponentName string = "dc-metro-map" - GitSourceComponentUrl string = "https://github.com/scoheb/dc-metro-map" + DcMetroMapGitRepoName string = "dc-metro-map" + DcMetroMapGitRevision string = "d49914874789147eb2de9bb6a12cd5d150bfff92" AdditionalComponentName string = "simple-python" - AdditionalGitSourceComponentUrl string = "https://github.com/devfile-samples/devfile-sample-python-basic" + AdditionalGitSourceComponentUrl string = "https://github.com/redhat-appstudio-qe/devfile-sample-python-basic-release" + AdditionalGitRevision string = "47fc22092005aabebce233a9b6eab994a8152bbd" 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/" @@ -50,6 +54,8 @@ const ( // Service constants ApplicationName string = "application" + + githubUrlFormat = "https://github.com/%s/%s" ) var ManagednamespaceSecret = []corev1.ObjectReference{ @@ -58,6 +64,8 @@ var ManagednamespaceSecret = []corev1.ObjectReference{ // Pipelines variables var ( - RelSvcCatalogURL string = utils.GetEnv("RELEASE_SERVICE_CATALOG_URL", "https://github.com/konflux-ci/release-service-catalog") - RelSvcCatalogRevision string = utils.GetEnv("RELEASE_SERVICE_CATALOG_REVISION", "staging") + githubOrg = utils.GetEnv(constants.GITHUB_E2E_ORGANIZATION_ENV, "redhat-appstudio-qe") + DcMetroMapGitSourceURL = fmt.Sprintf(githubUrlFormat, githubOrg, DcMetroMapGitRepoName) + RelSvcCatalogURL string = utils.GetEnv("RELEASE_SERVICE_CATALOG_URL", "https://github.com/konflux-ci/release-service-catalog") + RelSvcCatalogRevision string = utils.GetEnv("RELEASE_SERVICE_CATALOG_REVISION", "staging") ) diff --git a/tests/release/pipelines/fbc_release.go b/tests/release/pipelines/fbc_release.go index d6a42b0d21..b92c209cba 100644 --- a/tests/release/pipelines/fbc_release.go +++ b/tests/release/pipelines/fbc_release.go @@ -24,7 +24,8 @@ import ( const ( fbcServiceAccountName = "release-service-account" - fbcSourceGitURL = "https://github.com/redhat-appstudio-qe/fbc-sample-repo" + fbcSourceGitURL = "https://github.com/redhat-appstudio-qe/fbc-sample-repo-release" + fbcGitRevision = "8e374e107fecf03f3c64c528bb53798039661414" fbcDockerFilePath = "catalog.Dockerfile" targetPort = 50051 relSvcCatalogPathInRepo = "pipelines/fbc-release/fbc-release.yaml" @@ -33,7 +34,6 @@ const ( var snapshot *appservice.Snapshot var releaseCR *releaseapi.Release var buildPR *tektonv1.PipelineRun -var err error var devWorkspace = utils.GetEnv(constants.RELEASE_DEV_WORKSPACE_ENV, constants.DevReleaseTeam) var managedWorkspace = utils.GetEnv(constants.RELEASE_MANAGED_WORKSPACE_ENV, constants.ManagedReleaseTeam) var devFw *framework.Framework @@ -45,7 +45,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- var devNamespace = devWorkspace + "-tenant" var managedNamespace = managedWorkspace + "-tenant" - + var err error var issueId = "bz12345" var productName = "preGA-product" var productVersion = "v2" @@ -69,6 +69,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- Describe("with FBC happy path", Label("fbcHappyPath"), func() { var component *appservice.Component + var baseBranchName, pacBranchName string + BeforeAll(func() { devFw = releasecommon.NewFramework(devWorkspace) managedFw = releasecommon.NewFramework(managedWorkspace) @@ -88,7 +90,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- createFBCReleasePlanAdmission(fbcReleasePlanAdmissionName, *managedFw, devNamespace, managedNamespace, fbcApplicationName, fbcEnterpriseContractPolicyName, relSvcCatalogPathInRepo, "false", "", "", "", "") - component = releasecommon.CreateComponent(*devFw, devNamespace, fbcApplicationName, fbcComponentName, fbcSourceGitURL, "", "4.13", fbcDockerFilePath, constants.DefaultFbcBuilderPipelineBundle) + component, baseBranchName, pacBranchName = releasecommon.CreateComponent(*devFw, devNamespace, fbcApplicationName, fbcComponentName, fbcSourceGitURL, fbcGitRevision, "4.13", fbcDockerFilePath, constants.DefaultFbcBuilderPipelineBundle) createFBCEnterpriseContractPolicy(fbcEnterpriseContractPolicyName, *managedFw, devNamespace, managedNamespace) @@ -100,6 +102,15 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(fbcApplicationName, devNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcEnterpriseContractPolicyName, managedNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(fbcReleasePlanAdmissionName, managedNamespace, false)).NotTo(HaveOccurred()) + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(fbcSourceGitURL), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(fbcSourceGitURL), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) var _ = Describe("Post-release verification", func() { @@ -119,6 +130,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- Describe("with FBC hotfix process", Label("fbcHotfix"), func() { var component *appservice.Component + var baseBranchName, pacBranchName string BeforeAll(func() { devFw = releasecommon.NewFramework(devWorkspace) @@ -133,7 +145,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- createFBCReleasePlanAdmission(fbcHotfixRPAName, *managedFw, devNamespace, managedNamespace, fbcHotfixAppName, fbcHotfixECPolicyName, relSvcCatalogPathInRepo, "true", issueId, "false", "", "") - component = releasecommon.CreateComponent(*devFw, devNamespace, fbcHotfixAppName, fbcHotfixCompName, fbcSourceGitURL, "", "4.13", fbcDockerFilePath, constants.DefaultFbcBuilderPipelineBundle) + component, baseBranchName, pacBranchName = releasecommon.CreateComponent(*devFw, devNamespace, fbcHotfixAppName, fbcHotfixCompName, fbcSourceGitURL, fbcGitRevision, "4.13", fbcDockerFilePath, constants.DefaultFbcBuilderPipelineBundle) createFBCEnterpriseContractPolicy(fbcHotfixECPolicyName, *managedFw, devNamespace, managedNamespace) }) @@ -144,6 +156,15 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(fbcHotfixAppName, devNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcHotfixECPolicyName, managedNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(fbcHotfixRPAName, managedNamespace, false)).NotTo(HaveOccurred()) + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(fbcSourceGitURL), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(fbcSourceGitURL), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } }) var _ = Describe("FBC hotfix post-release verification", func() { @@ -163,6 +184,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- Describe("with FBC pre-GA process", Label("fbcPreGA"), func() { var component *appservice.Component + var baseBranchName, pacBranchName string BeforeAll(func() { devFw = releasecommon.NewFramework(devWorkspace) @@ -177,7 +199,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- createFBCReleasePlanAdmission(fbcPreGARPAName, *managedFw, devNamespace, managedNamespace, fbcPreGAAppName, fbcPreGAECPolicyName, relSvcCatalogPathInRepo, "false", issueId, "true", productName, productVersion) - component = releasecommon.CreateComponent(*devFw, devNamespace, fbcPreGAAppName, fbcPreGACompName, fbcSourceGitURL, "", "4.13", fbcDockerFilePath, constants.DefaultFbcBuilderPipelineBundle) + component, baseBranchName, pacBranchName = releasecommon.CreateComponent(*devFw, devNamespace, fbcPreGAAppName, fbcPreGACompName, fbcSourceGitURL, fbcGitRevision, "4.13", fbcDockerFilePath, constants.DefaultFbcBuilderPipelineBundle) createFBCEnterpriseContractPolicy(fbcPreGAECPolicyName, *managedFw, devNamespace, managedNamespace) }) @@ -190,6 +212,17 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(fbcPreGAECPolicyName, managedNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(fbcPreGARPAName, managedNamespace, false)).NotTo(HaveOccurred()) } + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(fbcSourceGitURL), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(fbcSourceGitURL), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + // Delete created webhook from GitHub + releasecommon.CleanupWebhooks(devFw, utils.GetRepoName(fbcSourceGitURL)) }) var _ = Describe("FBC pre-GA post-release verification", func() { @@ -209,6 +242,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("FBC e2e-tests", Label("release- }) func assertBuildPipelineRunSucceeded(devFw framework.Framework, devNamespace, managedNamespace, fbcAppName string, component *appservice.Component) { + var err error dFw := releasecommon.NewFramework(devWorkspace) devFw = *dFw // Create a ticker that ticks every 3 minutes @@ -247,6 +281,7 @@ func assertBuildPipelineRunSucceeded(devFw framework.Framework, devNamespace, ma } func assertReleasePipelineRunSucceeded(devFw, managedFw framework.Framework, devNamespace, managedNamespace, fbcAppName string, component *appservice.Component) { + var err error snapshot, err = devFw.AsKubeDeveloper.IntegrationController.WaitForSnapshotToGetCreated("", "", component.Name, devNamespace) Expect(err).ToNot(HaveOccurred()) GinkgoWriter.Println("snapshot: ", snapshot.Name) @@ -278,6 +313,7 @@ func assertReleasePipelineRunSucceeded(devFw, managedFw framework.Framework, dev } func assertReleaseCRSucceeded(devFw framework.Framework, devNamespace, managedNamespace, fbcAppName string, component *appservice.Component) { + var err error dFw := releasecommon.NewFramework(devWorkspace) Eventually(func() error { releaseCR, err = dFw.AsKubeDeveloper.ReleaseController.GetRelease("", snapshot.Name, devNamespace) diff --git a/tests/release/pipelines/multiarch_rh_advisories.go b/tests/release/pipelines/multiarch_rh_advisories.go index d6d3a20f6e..e29d88dcd6 100644 --- a/tests/release/pipelines/multiarch_rh_advisories.go +++ b/tests/release/pipelines/multiarch_rh_advisories.go @@ -269,7 +269,6 @@ func createMultiArchReleasePlan(multiarchReleasePlanName string, devFw framework Expect(err).NotTo(HaveOccurred()) } - func createMultiArchReleasePlanAdmission(multiarchRPAName string, managedFw framework.Framework, devNamespace, managedNamespace, multiarchAppName, multiarchECPName, pathInRepoValue string) { var err error @@ -277,9 +276,9 @@ func createMultiArchReleasePlanAdmission(multiarchRPAName string, managedFw fram "mapping": map[string]interface{}{ "components": []map[string]interface{}{ { - "name": multiarchComponentName, + "name": multiarchComponentName, "repository": "quay.io/redhat-pending/rhtap----konflux-release-e2e", - "tags": []string{"latest"}, + "tags": []string{"latest"}, "source": map[string]interface{}{ "git": map[string]interface{}{ "url": multiarchGitSourceURL, @@ -319,8 +318,9 @@ func createMultiArchReleasePlanAdmission(multiarchRPAName string, managedFw fram Expect(err).NotTo(HaveOccurred()) } -// preparePR function is to prepare a merged PR for triggerng a push event -func preparePR(devFw *framework.Framework, testBaseBranchName, testPRBranchName string) (int) { +// preparePR function is to prepare a merged PR for triggerng a push event +func preparePR(devFw *framework.Framework, testBaseBranchName, testPRBranchName string) int { + var err error //Create the ref, update the file, create the PR and merge the PR err = devFw.AsKubeAdmin.CommonController.Github.CreateRef(multiarchGitSourceRepoName, multiarchGitSrcDefaultBranch, multiarchGitSrcDefaultSHA, testBaseBranchName) Expect(err).ShouldNot(HaveOccurred()) @@ -328,16 +328,16 @@ func preparePR(devFw *framework.Framework, testBaseBranchName, testPRBranchName err = devFw.AsKubeAdmin.CommonController.Github.CreateRef(multiarchGitSourceRepoName, multiarchGitSrcDefaultBranch, multiarchGitSrcDefaultSHA, testPRBranchName) Expect(err).ShouldNot(HaveOccurred()) - // Update the pac configuration for "push" event + // Update the pac configuration for "push" event fileName := "multi-platform-test-prod-push.yaml" - fileResponse, err := devFw.AsKubeAdmin.CommonController.Github.GetFile(multiarchGitSourceRepoName, ".tekton/" + fileName, testPRBranchName) + fileResponse, err := devFw.AsKubeAdmin.CommonController.Github.GetFile(multiarchGitSourceRepoName, ".tekton/"+fileName, testPRBranchName) Expect(err).ShouldNot(HaveOccurred()) fileContent, err := fileResponse.GetContent() Expect(err).ShouldNot(HaveOccurred()) - fileContent = strings.ReplaceAll(fileContent, "[main]", "[" + testBaseBranchName + "]") - repoContentResponse, err := devFw.AsKubeAdmin.CommonController.Github.UpdateFile(multiarchGitSourceRepoName, ".tekton/" + fileName, fileContent, testPRBranchName, *fileResponse.SHA) + fileContent = strings.ReplaceAll(fileContent, "[main]", "["+testBaseBranchName+"]") + repoContentResponse, err := devFw.AsKubeAdmin.CommonController.Github.UpdateFile(multiarchGitSourceRepoName, ".tekton/"+fileName, fileContent, testPRBranchName, *fileResponse.SHA) Expect(err).ShouldNot(HaveOccurred()) pr, err := devFw.AsKubeAdmin.CommonController.Github.CreatePullRequest(multiarchGitSourceRepoName, "update pac configuration title", "update pac configuration body", testPRBranchName, testBaseBranchName) diff --git a/tests/release/pipelines/push_to_external_registry.go b/tests/release/pipelines/push_to_external_registry.go index 9e9fa82aec..79a3b4939c 100644 --- a/tests/release/pipelines/push_to_external_registry.go +++ b/tests/release/pipelines/push_to_external_registry.go @@ -28,7 +28,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("Push to external registry", Lab var fw *framework.Framework AfterEach(framework.ReportFailure(&fw)) var err error - var devNamespace, managedNamespace string + var devNamespace, managedNamespace, baseBranchName, pacBranchName string var component *appservice.Component var releaseCR *releaseApi.Release @@ -72,7 +72,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("Push to external registry", Lab _, err = fw.AsKubeAdmin.HasController.CreateApplication(releasecommon.ApplicationNameDefault, devNamespace) Expect(err).NotTo(HaveOccurred()) - component = releasecommon.CreateComponent(*fw, devNamespace, releasecommon.ApplicationNameDefault, releasecommon.ComponentName, releasecommon.GitSourceComponentUrl, "", ".", "Dockerfile", constants.DefaultDockerBuildPipelineBundle) + component, baseBranchName, pacBranchName = releasecommon.CreateComponent(*fw, devNamespace, releasecommon.ApplicationNameDefault, releasecommon.ComponentName, releasecommon.DcMetroMapGitSourceURL, releasecommon.DcMetroMapGitRevision, ".", "Dockerfile", constants.DefaultDockerBuildPipelineBundle) _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releasecommon.SourceReleasePlanName, devNamespace, releasecommon.ApplicationNameDefault, managedNamespace, "", nil, nil) Expect(err).NotTo(HaveOccurred()) @@ -128,6 +128,18 @@ var _ = framework.ReleasePipelinesSuiteDescribe("Push to external registry", Lab Expect(fw.AsKubeAdmin.CommonController.DeleteNamespace(managedNamespace)).NotTo(HaveOccurred()) Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue()) } + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = fw.AsKubeAdmin.CommonController.Github.DeleteRef(releasecommon.DcMetroMapGitRepoName, pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = fw.AsKubeAdmin.CommonController.Github.DeleteRef(releasecommon.DcMetroMapGitRepoName, baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + + // Delete created webhook from GitHub + releasecommon.CleanupWebhooks(fw, releasecommon.DcMetroMapGitRepoName) }) var _ = Describe("Post-release verification", func() { diff --git a/tests/release/pipelines/release_to_github.go b/tests/release/pipelines/release_to_github.go index 2915ea7ba7..1cb9e74955 100644 --- a/tests/release/pipelines/release_to_github.go +++ b/tests/release/pipelines/release_to_github.go @@ -29,9 +29,10 @@ import ( const ( sampServiceAccountName = "release-service-account" - sampSourceGitURL = "https://github.com/redhat-appstudio-qe/devfile-sample-go-basic" + sampSourceGitURL = "https://github.com/redhat-appstudio-qe/devfile-sample-go-basic-release" + sampGitRevision = "508445a786e84c01e84c8c46d9d2407642d02762" sampRepoOwner = "redhat-appstudio-qe" - sampRepo = "devfile-sample-go-basic" + sampRepo = "devfile-sample-go-basic-release" sampCatalogPathInRepo = "pipelines/release-to-github/release-to-github.yaml" ) @@ -58,6 +59,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for release-to-github var releasePR, buildPR *tektonv1.PipelineRun var gh *github.Github var sampReleaseURL string + var baseBranchName, pacBranchName string AfterEach(framework.ReportFailure(&devFw)) @@ -106,7 +108,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for release-to-github createGHReleasePlanAdmission(sampReleasePlanAdmissionName, *managedFw, devNamespace, managedNamespace, sampApplicationName, sampEnterpriseContractPolicyName, sampCatalogPathInRepo, "false", "", "", "", "") - component = releasecommon.CreateComponent(*devFw, devNamespace, sampApplicationName, sampComponentName, sampSourceGitURL, "", ".", "Dockerfile", constants.DefaultDockerBuildPipelineBundle) + component, baseBranchName, pacBranchName = releasecommon.CreateComponent(*devFw, devNamespace, sampApplicationName, sampComponentName, sampSourceGitURL, sampGitRevision, ".", "Dockerfile", constants.DefaultDockerBuildPipelineBundle) createGHEnterpriseContractPolicy(sampEnterpriseContractPolicyName, *managedFw, devNamespace, managedNamespace) }) @@ -121,6 +123,19 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for release-to-github if gh.CheckIfReleaseExist(sampRepoOwner, sampRepo, sampReleaseURL) { gh.DeleteRelease(sampRepoOwner, sampRepo, sampReleaseURL) } + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(sampRepo, pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(sampRepo, baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + + // Delete created webhook from GitHub + releasecommon.CleanupWebhooks(devFw, sampRepo) + }) var _ = Describe("Post-release verification", func() { diff --git a/tests/release/pipelines/rh_advisories.go b/tests/release/pipelines/rh_advisories.go index a123868094..8f15fabe86 100644 --- a/tests/release/pipelines/rh_advisories.go +++ b/tests/release/pipelines/rh_advisories.go @@ -56,6 +56,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rh-advisories pip var snapshot *appservice.Snapshot var releaseCR *releaseapi.Release var releasePR, buildPR *tektonv1.PipelineRun + var baseBranchName, pacBranchName string AfterEach(framework.ReportFailure(&devFw)) @@ -103,7 +104,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rh-advisories pip createADVSReleasePlan(advsReleasePlanName, *devFw, devNamespace, advsApplicationName, managedNamespace, "true") - component = releasecommon.CreateComponent(*devFw, devNamespace, advsApplicationName, advsComponentName, releasecommon.AdditionalGitSourceComponentUrl, "", ".", constants.DockerFilePath, constants.DefaultDockerBuildPipelineBundle) + component, baseBranchName, pacBranchName = releasecommon.CreateComponent(*devFw, devNamespace, advsApplicationName, advsComponentName, releasecommon.AdditionalGitSourceComponentUrl, releasecommon.AdditionalGitRevision, ".", constants.DockerFilePath, constants.DefaultDockerBuildPipelineBundle) createADVSReleasePlanAdmission(advsReleasePlanAdmissionName, *managedFw, devNamespace, managedNamespace, advsApplicationName, advsEnterpriseContractPolicyName, advsCatalogPathInRepo) @@ -116,6 +117,17 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rh-advisories pip Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(advsApplicationName, devNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(advsEnterpriseContractPolicyName, managedNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(advsReleasePlanAdmissionName, managedNamespace, false)).NotTo(HaveOccurred()) + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + // Delete created webhook from GitHub + releasecommon.CleanupWebhooks(devFw, utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl)) }) var _ = Describe("Post-release verification", func() { diff --git a/tests/release/pipelines/rh_push_to_external_registry.go b/tests/release/pipelines/rh_push_to_external_registry.go index c9f49658f7..fecb4ead1c 100644 --- a/tests/release/pipelines/rh_push_to_external_registry.go +++ b/tests/release/pipelines/rh_push_to_external_registry.go @@ -47,6 +47,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu var releaseCR1, releaseCR2 *releaseApi.Release var componentObj1, componentObj2 appservice.ComponentSpec + var baseBranchNameComp1, pacBranchNameComp1, baseBranchNameComp2, pacBranchNameComp2 string BeforeAll(func() { fw, err = framework.NewFramework(utils.GetGeneratedNamespace("push-pyxis")) @@ -118,13 +119,26 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu compName = releasecommon.ComponentName additionalCompName = releasecommon.AdditionalComponentName + pacBranchNameComp1 = constants.PaCPullRequestBranchPrefix + compName + pacBranchNameComp2 = constants.PaCPullRequestBranchPrefix + additionalCompName + + baseBranchNameComp1 = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + baseBranchNameComp2 = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + + err = devFw.AsKubeAdmin.CommonController.Github.CreateRef(releasecommon.DcMetroMapGitRepoName, "main", releasecommon.DcMetroMapGitRevision, baseBranchNameComp1) + Expect(err).ShouldNot(HaveOccurred()) + + err = devFw.AsKubeAdmin.CommonController.Github.CreateRef(utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl), "main", releasecommon.AdditionalGitRevision, baseBranchNameComp2) + Expect(err).ShouldNot(HaveOccurred()) + componentObj1 = appservice.ComponentSpec{ ComponentName: releasecommon.ComponentName, Application: releasecommon.ApplicationNameDefault, Source: appservice.ComponentSource{ ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ - URL: releasecommon.GitSourceComponentUrl, + URL: releasecommon.DcMetroMapGitSourceURL, + Revision: baseBranchNameComp1, }, }, }, @@ -136,6 +150,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ URL: releasecommon.AdditionalGitSourceComponentUrl, + Revision: baseBranchNameComp2, DockerfileURL: constants.DockerFilePath, }, }, @@ -210,19 +225,41 @@ var _ = framework.ReleasePipelinesSuiteDescribe("[HACBS-1571]test-release-e2e-pu Expect(fw.AsKubeAdmin.CommonController.DeleteNamespace(managedNamespace)).NotTo(HaveOccurred()) Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue()) } + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = fw.AsKubeAdmin.CommonController.Github.DeleteRef(releasecommon.DcMetroMapGitRepoName, pacBranchNameComp1) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = fw.AsKubeAdmin.CommonController.Github.DeleteRef(releasecommon.DcMetroMapGitRepoName, baseBranchNameComp1) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = fw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl), pacBranchNameComp2) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = fw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl), baseBranchNameComp2) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + + // Delete created webhook from GitHub + releasecommon.CleanupWebhooks(fw, releasecommon.DcMetroMapGitRepoName) + releasecommon.CleanupWebhooks(fw, utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl)) + }) 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(componentObj1, devNamespace, "", "", releasecommon.ApplicationNameDefault, true, constants.DefaultDockerBuildPipelineBundle) + component1, err = fw.AsKubeAdmin.HasController.CreateComponent(componentObj1, devNamespace, "", "", releasecommon.ApplicationNameDefault, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.DefaultDockerBuildPipelineBundle)) Expect(err).NotTo(HaveOccurred()) Expect(fw.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component1, "", fw.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, nil)).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(componentObj2, devNamespace, "", "", releasecommon.ApplicationNameDefault, true, constants.DefaultDockerBuildPipelineBundle) + component2, err = fw.AsKubeAdmin.HasController.CreateComponent(componentObj2, devNamespace, "", "", releasecommon.ApplicationNameDefault, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.DefaultDockerBuildPipelineBundle)) Expect(err).NotTo(HaveOccurred()) Expect(fw.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component2, "", fw.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, nil)).To(Succeed()) diff --git a/tests/release/pipelines/rh_push_to_redhat_io.go b/tests/release/pipelines/rh_push_to_redhat_io.go index c5c6b38e11..c2ce098f0f 100644 --- a/tests/release/pipelines/rh_push_to_redhat_io.go +++ b/tests/release/pipelines/rh_push_to_redhat_io.go @@ -57,6 +57,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rh-push-to-redhat var snapshot *appservice.Snapshot var releaseCR *releaseapi.Release var releasePR, buildPR *tektonv1.PipelineRun + var baseBranchName, pacBranchName string AfterEach(framework.ReportFailure(&devFw)) @@ -106,7 +107,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rh-push-to-redhat _, err = devFw.AsKubeDeveloper.ReleaseController.CreateReleasePlan(rhioReleasePlanName, devNamespace, rhioApplicationName, managedNamespace, "true", nil, nil) Expect(err).NotTo(HaveOccurred()) - testComponent = releasecommon.CreateComponent(*devFw, devNamespace, rhioApplicationName, rhioComponentName, releasecommon.AdditionalGitSourceComponentUrl, "", ".", constants.DockerFilePath, constants.DefaultDockerBuildPipelineBundle) + testComponent, baseBranchName, pacBranchName = releasecommon.CreateComponent(*devFw, devNamespace, rhioApplicationName, rhioComponentName, releasecommon.AdditionalGitSourceComponentUrl, releasecommon.AdditionalGitRevision, ".", constants.DockerFilePath, constants.DefaultDockerBuildPipelineBundle) createRHIOReleasePlanAdmission(rhioReleasePlanAdmissionName, *managedFw, devNamespace, managedNamespace, rhioApplicationName, rhioEnterpriseContractPolicyName, rhioCatalogPathInRepo) @@ -119,6 +120,18 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rh-push-to-redhat Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(rhioApplicationName, devNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(rhioEnterpriseContractPolicyName, managedNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(rhioReleasePlanAdmissionName, managedNamespace, false)).NotTo(HaveOccurred()) + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl), pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl), baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + + // Delete created webhook from GitHub + releasecommon.CleanupWebhooks(devFw, utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl)) }) var _ = Describe("Post-release verification", func() { diff --git a/tests/release/pipelines/rhtap_service_push.go b/tests/release/pipelines/rhtap_service_push.go index 52ebca69b4..4c07444091 100644 --- a/tests/release/pipelines/rhtap_service_push.go +++ b/tests/release/pipelines/rhtap_service_push.go @@ -5,16 +5,16 @@ import ( "encoding/json" "fmt" "os" - "time" "strings" + "time" "github.com/devfile/library/v2/pkg/util" ecp "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1" appservice "github.com/konflux-ci/application-api/api/v1alpha1" appstudioApi "github.com/konflux-ci/application-api/api/v1alpha1" + "github.com/konflux-ci/e2e-tests/pkg/clients/github" "github.com/konflux-ci/e2e-tests/pkg/constants" "github.com/konflux-ci/e2e-tests/pkg/framework" - "github.com/konflux-ci/e2e-tests/pkg/clients/github" "github.com/konflux-ci/e2e-tests/pkg/utils" "github.com/konflux-ci/e2e-tests/pkg/utils/tekton" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" @@ -70,6 +70,8 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rhtap-service-pus var releaseCR *releaseapi.Release var buildPR *tektonv1.PipelineRun + var baseBranchName, pacBranchName string + AfterEach(framework.ReportFailure(&devFw)) Describe("Rhtap-service-push happy path", Label("RhtapServicePush"), func() { @@ -124,22 +126,28 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rhtap-service-pus _, err = devFw.AsKubeDeveloper.ReleaseController.CreateReleasePlan(rhtapReleasePlanName, devNamespace, rhtapApplicationName, managedNamespace, "true", nil, nil) Expect(err).NotTo(HaveOccurred()) + pacBranchName = constants.PaCPullRequestBranchPrefix + rhtapComponentName + baseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + + err = devFw.AsKubeAdmin.CommonController.Github.CreateRef(rhtapGitSourceRepoName, rhtapGitSrcDefaultBranch, rhtapGitSrcDefaultSHA, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + componentObj := appstudioApi.ComponentSpec{ ComponentName: rhtapComponentName, Application: rhtapApplicationName, Source: appstudioApi.ComponentSource{ ComponentSourceUnion: appstudioApi.ComponentSourceUnion{ GitSource: &appstudioApi.GitSource{ - URL: rhtapGitSourceURL, - Revision: testBaseBranchName, - Context: ".", + URL: rhtapGitSourceURL, + Revision: baseBranchName, + Context: ".", DockerfileURL: constants.DockerFilePath, }, }, }, } // Create a component with Git Source URL, a specified git branch - rhtapComponent, err = devFw.AsKubeAdmin.HasController.CreateComponent(componentObj, devNamespace, "", "", rhtapApplicationName, true, constants.DefaultDockerBuildPipelineBundle) + rhtapComponent, err = devFw.AsKubeAdmin.HasController.CreateComponent(componentObj, devNamespace, "", "", rhtapApplicationName, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.DefaultDockerBuildPipelineBundle)) Expect(err).ShouldNot(HaveOccurred()) createRHTAPReleasePlanAdmission(rhtapReleasePlanAdmissionName, *managedFw, devNamespace, managedNamespace, rhtapApplicationName, rhtapEnterpriseContractPolicyName, rhtapCatalogPathInRepo) @@ -153,6 +161,18 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rhtap-service-pus Expect(devFw.AsKubeDeveloper.HasController.DeleteApplication(rhtapApplicationName, devNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.TektonController.DeleteEnterpriseContractPolicy(rhtapEnterpriseContractPolicyName, managedNamespace, false)).NotTo(HaveOccurred()) Expect(managedFw.AsKubeDeveloper.ReleaseController.DeleteReleasePlanAdmission(rhtapReleasePlanAdmissionName, managedNamespace, false)).NotTo(HaveOccurred()) + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(rhtapGitSourceRepoName, pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(rhtapGitSourceRepoName, baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + + // Delete created webhook from GitHub + releasecommon.CleanupWebhooks(devFw, rhtapGitSourceRepoName) }) var _ = Describe("Post-release verification", func() { @@ -237,7 +257,7 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rhtap-service-pus body := pr.Body GinkgoWriter.Printf("Body of PR #%d: %s \n", pr.GetNumber(), *body) - prLink := fmt.Sprintf(rhtapGitSourceURL + "/pull/%d", sourcePrNum) + prLink := fmt.Sprintf(rhtapGitSourceURL+"/pull/%d", sourcePrNum) GinkgoWriter.Printf("The source PR link: %s", prLink) if strings.Contains(*body, prLink) { GinkgoWriter.Printf("The source PR#%d is added to the PR of infra-deployments", sourcePrNum) @@ -295,9 +315,9 @@ func createRHTAPReleasePlanAdmission(rhtapRPAName string, managedFw framework.Fr "server": "stage", "secret": "pyxis", }, - "targetGHRepo": "hacbs-release/infra-deployments", - "githubAppID": "932323", - "githubAppInstallationID": "52284535", + "targetGHRepo": "hacbs-release/infra-deployments", + "githubAppID": "932323", + "githubAppInstallationID": "52284535", "infra-deployment-update-script": "sed -i -e 's|\\(https://github.com/hacbs-release/release-service/config/default?ref=\\)\\(.*\\)|\\1{{ revision }}|' -e 's/\\(newTag: \\).*/\\1{{ revision }}/' components/release/development/kustomization.yaml", "sign": map[string]interface{}{ "configMapName": "hacbs-signing-pipeline-config-redhatbeta2", @@ -321,6 +341,7 @@ func createRHTAPReleasePlanAdmission(rhtapRPAName string, managedFw framework.Fr // prepareMergedPR function is to prepare a merged PR in source repo for testing update-infra-deployments task func prepareMergedPR(devFw *framework.Framework, testBaseBranchName, testPRBranchName string) (int, string) { //Create the ref, add the file, create the PR and merge the PR + var err error err = devFw.AsKubeAdmin.CommonController.Github.CreateRef(rhtapGitSourceRepoName, rhtapGitSrcDefaultBranch, rhtapGitSrcDefaultSHA, testBaseBranchName) Expect(err).ShouldNot(HaveOccurred()) @@ -348,4 +369,3 @@ func prepareMergedPR(devFw *framework.Framework, testBaseBranchName, testPRBranc return pr.GetNumber(), mergeResultSha } - diff --git a/tests/release/pipelines/tenant_pipelines.go b/tests/release/pipelines/tenant_pipelines.go index 47dbc836ac..e4778719c7 100644 --- a/tests/release/pipelines/tenant_pipelines.go +++ b/tests/release/pipelines/tenant_pipelines.go @@ -8,18 +8,18 @@ import ( tektonutils "github.com/konflux-ci/release-service/tekton/utils" "k8s.io/apimachinery/pkg/runtime" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" appservice "github.com/konflux-ci/application-api/api/v1alpha1" "github.com/konflux-ci/e2e-tests/pkg/clients/has" "github.com/konflux-ci/e2e-tests/pkg/constants" "github.com/konflux-ci/e2e-tests/pkg/framework" "github.com/konflux-ci/e2e-tests/pkg/utils" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" releaseApi "github.com/konflux-ci/release-service/api/v1alpha1" - corev1 "k8s.io/api/core/v1" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) var _ = framework.ReleaseServiceSuiteDescribe("Release service tenant pipeline", Label("release-pipelines", "tenant"), func() { @@ -34,6 +34,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service tenant pipeline", var component *appservice.Component var releaseCR *releaseApi.Release + var baseBranchName, pacBranchName string BeforeAll(func() { // Initialize the tests controllers @@ -51,7 +52,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service tenant pipeline", _, err = fw.AsKubeAdmin.HasController.CreateApplication(releasecommon.ApplicationNameDefault, devNamespace) Expect(err).NotTo(HaveOccurred()) - component = releasecommon.CreateComponent(*fw, devNamespace, releasecommon.ApplicationNameDefault, releasecommon.ComponentName, releasecommon.GitSourceComponentUrl, "", ".", "Dockerfile", constants.DefaultDockerBuildPipelineBundle) + component, baseBranchName, pacBranchName = releasecommon.CreateComponent(*fw, devNamespace, releasecommon.ApplicationNameDefault, releasecommon.ComponentName, releasecommon.DcMetroMapGitSourceURL, releasecommon.DcMetroMapGitRevision, ".", "Dockerfile", constants.DefaultDockerBuildPipelineBundle) data, err := json.Marshal(map[string]interface{}{ "mapping": map[string]interface{}{ @@ -68,8 +69,8 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service tenant pipeline", tenantPipeline := &tektonutils.ParameterizedPipeline{} tenantPipeline.ServiceAccountName = constants.DefaultPipelineServiceAccount tenantPipeline.Timeouts = tektonv1.TimeoutFields{ - Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, - } + Pipeline: &metav1.Duration{Duration: 1 * time.Hour}, + } tenantPipeline.PipelineRef = tektonutils.PipelineRef{ Resolver: "git", @@ -81,8 +82,8 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service tenant pipeline", } _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releasecommon.SourceReleasePlanName, devNamespace, releasecommon.ApplicationNameDefault, "", "", &runtime.RawExtension{ - Raw: data, - }, tenantPipeline) + Raw: data, + }, tenantPipeline) Expect(err).NotTo(HaveOccurred()) _, err = fw.AsKubeAdmin.TektonController.CreatePVCInAccessMode(releasecommon.ReleasePvcName, devNamespace, corev1.ReadWriteOnce) @@ -93,6 +94,18 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service tenant pipeline", if !CurrentSpecReport().Failed() { Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue()) } + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(releasecommon.DcMetroMapGitRepoName, pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = devFw.AsKubeAdmin.CommonController.Github.DeleteRef(releasecommon.DcMetroMapGitRepoName, baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + + // Delete created webhook from GitHub + releasecommon.CleanupWebhooks(devFw, releasecommon.DcMetroMapGitRepoName) }) var _ = Describe("Post-release verification", func() { diff --git a/tests/release/releaseLib.go b/tests/release/releaseLib.go index 1f66949059..9f44e5b8ef 100644 --- a/tests/release/releaseLib.go +++ b/tests/release/releaseLib.go @@ -1,13 +1,17 @@ package common import ( + "fmt" "os" + "strings" "time" + "github.com/devfile/library/v2/pkg/util" appservice "github.com/konflux-ci/application-api/api/v1alpha1" "github.com/konflux-ci/e2e-tests/pkg/constants" "github.com/konflux-ci/e2e-tests/pkg/framework" "github.com/konflux-ci/e2e-tests/pkg/utils" + . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) @@ -26,7 +30,13 @@ func NewFramework(workspace string) *framework.Framework { return fw } -func CreateComponent(devFw framework.Framework, devNamespace, appName, compName, gitURL, gitRevision, contextDir, dockerFilePath string, buildPipelineBundle map[string]string) *appservice.Component { +func CreateComponent(devFw framework.Framework, devNamespace, appName, compName, gitURL, gitRevision, contextDir, dockerFilePath string, buildPipelineBundle map[string]string) (component *appservice.Component, baseBranchName, pacBranchName string) { + pacBranchName = constants.PaCPullRequestBranchPrefix + compName + baseBranchName = fmt.Sprintf("base-%s", util.GenerateRandomString(6)) + + err := devFw.AsKubeAdmin.CommonController.Github.CreateRef(utils.GetRepoName(gitURL), "main", gitRevision, baseBranchName) + Expect(err).ShouldNot(HaveOccurred()) + componentObj := appservice.ComponentSpec{ ComponentName: compName, Application: appName, @@ -34,14 +44,28 @@ func CreateComponent(devFw framework.Framework, devNamespace, appName, compName, ComponentSourceUnion: appservice.ComponentSourceUnion{ GitSource: &appservice.GitSource{ URL: gitURL, - Revision: gitRevision, + Revision: baseBranchName, Context: contextDir, DockerfileURL: dockerFilePath, }, }, }, } - component, err := devFw.AsKubeAdmin.HasController.CreateComponent(componentObj, devNamespace, "", "", appName, true, buildPipelineBundle) + + component, err = devFw.AsKubeAdmin.HasController.CreateComponent(componentObj, devNamespace, "", "", appName, true, utils.MergeMaps(constants.ComponentPaCRequestAnnotation, buildPipelineBundle)) Expect(err).NotTo(HaveOccurred()) - return component + return +} + +func CleanupWebhooks(f *framework.Framework, repoName string) { + hooks, err := f.AsKubeAdmin.CommonController.Github.ListRepoWebhooks(repoName) + Expect(err).NotTo(HaveOccurred()) + for _, h := range hooks { + hookUrl := h.Config["url"].(string) + if strings.Contains(hookUrl, f.ClusterAppDomain) { + GinkgoWriter.Printf("removing webhook URL: %s\n", hookUrl) + Expect(f.AsKubeAdmin.CommonController.Github.DeleteWebhook(repoName, h.GetID())).To(Succeed()) + break + } + } } diff --git a/tests/release/service/happy_path.go b/tests/release/service/happy_path.go index f302e60c73..8297c90138 100644 --- a/tests/release/service/happy_path.go +++ b/tests/release/service/happy_path.go @@ -29,7 +29,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe AfterEach(framework.ReportFailure(&fw)) var err error var compName string - var devNamespace, managedNamespace string + var devNamespace, managedNamespace, baseBranchName, pacBranchName string var verifyEnterpriseContractTaskName = "verify-enterprise-contract" var releasedImagePushRepo = "quay.io/redhat-appstudio-qe/dcmetromap" @@ -75,7 +75,7 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe _, err = fw.AsKubeAdmin.HasController.CreateApplication(releasecommon.ApplicationNameDefault, devNamespace) Expect(err).NotTo(HaveOccurred()) - component = releasecommon.CreateComponent(*fw, devNamespace, releasecommon.ApplicationNameDefault, releasecommon.ComponentName, releasecommon.GitSourceComponentUrl, "", ".", "Dockerfile", constants.DefaultDockerBuildPipelineBundle) + component, baseBranchName, pacBranchName = releasecommon.CreateComponent(*fw, devNamespace, releasecommon.ApplicationNameDefault, releasecommon.ComponentName, releasecommon.DcMetroMapGitSourceURL, releasecommon.DcMetroMapGitRevision, ".", "Dockerfile", constants.DefaultDockerBuildPipelineBundle) _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releasecommon.SourceReleasePlanName, devNamespace, releasecommon.ApplicationNameDefault, managedNamespace, "", nil, nil) Expect(err).NotTo(HaveOccurred()) @@ -126,6 +126,17 @@ var _ = framework.ReleaseServiceSuiteDescribe("Release service happy path", Labe Expect(fw.AsKubeAdmin.CommonController.DeleteNamespace(managedNamespace)).NotTo(HaveOccurred()) Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue()) } + // Delete new branches created by PaC and a testing branch used as a component's base branch + err = fw.AsKubeAdmin.CommonController.Github.DeleteRef(releasecommon.DcMetroMapGitRepoName, pacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = fw.AsKubeAdmin.CommonController.Github.DeleteRef(releasecommon.DcMetroMapGitRepoName, baseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + // Delete created webhook from GitHub + releasecommon.CleanupWebhooks(fw, releasecommon.DcMetroMapGitRepoName) }) var _ = Describe("Post-release verification", func() {