diff --git a/magefiles/rulesengine/repos/e2e_repo.go b/magefiles/rulesengine/repos/e2e_repo.go index 01f1e8ae4..0729a87b8 100644 --- a/magefiles/rulesengine/repos/e2e_repo.go +++ b/magefiles/rulesengine/repos/e2e_repo.go @@ -293,7 +293,7 @@ func CheckCmdFilesChanged(rctx *rulesengine.RuleCtx) bool { func ExecuteDefaultTestAction(rctx *rulesengine.RuleCtx) error { - rctx.LabelFilter = "!upgrade-create && !upgrade-verify && !upgrade-cleanup && !release-pipelines" + rctx.LabelFilter = "!upgrade-create && !upgrade-verify && !upgrade-cleanup && release-pipelines" return ExecuteTestAction(rctx) } diff --git a/pkg/clients/has/components.go b/pkg/clients/has/components.go index 7f7508d55..bfd843c5a 100644 --- a/pkg/clients/has/components.go +++ b/pkg/clients/has/components.go @@ -168,10 +168,10 @@ func (h *HasController) WaitForComponentPipelineToBeFinished(component *appservi } var prLogs string - if err = t.StorePipelineRun(pr); err != nil { + if err = t.StorePipelineRun(component.GetName(), pr); err != nil { GinkgoWriter.Printf("failed to store PipelineRun %s:%s: %s\n", pr.GetNamespace(), pr.GetName(), err.Error()) } - if prLogs, err = t.GetPipelineRunLogs(pr.Name, pr.Namespace); err != nil { + if prLogs, err = t.GetPipelineRunLogs(component.GetName(), pr.Name, pr.Namespace); err != nil { GinkgoWriter.Printf("failed to get logs for PipelineRun %s:%s: %s\n", pr.GetNamespace(), pr.GetName(), err.Error()) } diff --git a/pkg/clients/tekton/pipelineruns.go b/pkg/clients/tekton/pipelineruns.go index cf9d45e27..00193b1f5 100644 --- a/pkg/clients/tekton/pipelineruns.go +++ b/pkg/clients/tekton/pipelineruns.go @@ -70,7 +70,7 @@ func (t *TektonController) GetPipelineRun(pipelineRunName, namespace string) (*p } // GetPipelineRunLogs returns logs of a given pipelineRun. -func (t *TektonController) GetPipelineRunLogs(pipelineRunName, namespace string) (string, error) { +func (t *TektonController) GetPipelineRunLogs(prefix, pipelineRunName, namespace string) (string, error) { podClient := t.KubeInterface().CoreV1().Pods(namespace) podList, err := podClient.List(context.Background(), metav1.ListOptions{}) if err != nil { @@ -78,14 +78,14 @@ func (t *TektonController) GetPipelineRunLogs(pipelineRunName, namespace string) } podLog := "" for _, pod := range podList.Items { - if !strings.HasPrefix(pod.Name, pipelineRunName) { + if !strings.HasPrefix(pod.Name, prefix) { continue } for _, c := range pod.Spec.InitContainers { var err error var cLog string cLog, err = t.fetchContainerLog(pod.Name, c.Name, namespace) - podLog = podLog + fmt.Sprintf("\ninit container %s: \n", c.Name) + cLog + podLog = podLog + fmt.Sprintf("\n pod: %s | init container: %s\n", pod.Name, c.Name) + cLog if err != nil { return podLog, err } @@ -94,7 +94,7 @@ func (t *TektonController) GetPipelineRunLogs(pipelineRunName, namespace string) var err error var cLog string cLog, err = t.fetchContainerLog(pod.Name, c.Name, namespace) - podLog = podLog + fmt.Sprintf("\ncontainer %s: \n", c.Name) + cLog + podLog = podLog + fmt.Sprintf("\npod: %s | container %s: \n", pod.Name, c.Name) + cLog if err != nil { return podLog, err } @@ -215,7 +215,6 @@ func (t *TektonController) DeletePipelineRunIgnoreFinalizers(ns, name string) er return nil } - // DeleteAllPipelineRunsInASpecificNamespace deletes all PipelineRuns in a given namespace (removing the finalizers field, first) func (t *TektonController) DeleteAllPipelineRunsInASpecificNamespace(ns string) error { @@ -235,9 +234,9 @@ func (t *TektonController) DeleteAllPipelineRunsInASpecificNamespace(ns string) } // StorePipelineRun stores a given PipelineRun as an artifact. -func (t *TektonController) StorePipelineRun(pipelineRun *pipeline.PipelineRun) error { +func (t *TektonController) StorePipelineRun(prefix string, pipelineRun *pipeline.PipelineRun) error { artifacts := make(map[string][]byte) - pipelineRunLog, err := t.GetPipelineRunLogs(pipelineRun.Name, pipelineRun.Namespace) + pipelineRunLog, err := t.GetPipelineRunLogs(prefix, pipelineRun.Name, pipelineRun.Namespace) if err != nil { return err } @@ -265,7 +264,7 @@ func (t *TektonController) StoreAllPipelineRuns(namespace string) error { for _, pipelineRun := range pipelineRuns.Items { pipelineRun := pipelineRun - if err := t.StorePipelineRun(&pipelineRun); err != nil { + if err := t.StorePipelineRun(pipelineRun.GetName(), &pipelineRun); err != nil { return fmt.Errorf("got error storing PR: %v\n", err.Error()) } } diff --git a/pkg/utils/build/git.go b/pkg/utils/build/git.go index c3bee4538..231a0924a 100644 --- a/pkg/utils/build/git.go +++ b/pkg/utils/build/git.go @@ -4,9 +4,11 @@ import ( "fmt" "os" "strconv" + "strings" "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/utils" ) @@ -33,3 +35,22 @@ func ResolveGitDetails(repoUrlENV, repoRevisionENV string) (string, string, erro } return utils.GetEnv(repoUrlENV, defaultGitURL), utils.GetEnv(repoRevisionENV, defaultGitRevision), nil } + +func CleanupWebhooks(f *framework.Framework, repoName string) error { + hooks, err := f.AsKubeAdmin.CommonController.Github.ListRepoWebhooks(repoName) + if err != nil { + return err + } + for _, h := range hooks { + hookUrl := h.Config["url"].(string) + if strings.Contains(hookUrl, f.ClusterAppDomain) { + fmt.Printf("removing webhook URL: %s\n", hookUrl) + err = f.AsKubeAdmin.CommonController.Github.DeleteWebhook(repoName, h.GetID()) + if err != nil { + return err + } + break + } + } + return nil +} diff --git a/pkg/utils/build/task_results.go b/pkg/utils/build/task_results.go index 30e973308..80e5f9426 100644 --- a/pkg/utils/build/task_results.go +++ b/pkg/utils/build/task_results.go @@ -35,35 +35,9 @@ type Vulnerabilities struct { Low int `json:"low"` } -type PipelineBuildInfo struct { - runtime string - strategy string -} - -func GetPipelineBuildInfo(pr *pipeline.PipelineRun) PipelineBuildInfo { - labels := pr.GetLabels() - runtime := labels["pipelines.openshift.io/runtime"] - strategy := labels["pipelines.openshift.io/strategy"] - return PipelineBuildInfo{ - runtime: runtime, - strategy: strategy, - } -} - -func IsDockerBuild(pr *pipeline.PipelineRun) bool { - info := GetPipelineBuildInfo(pr) - return info.runtime == "generic" && info.strategy == "docker" -} - -func IsFBCBuild(pr *pipeline.PipelineRun) bool { - info := GetPipelineBuildInfo(pr) - return info.runtime == "fbc" && info.strategy == "fbc" -} - -func ValidateBuildPipelineTestResults(pipelineRun *pipeline.PipelineRun, c crclient.Client) error { +func ValidateBuildPipelineTestResults(pipelineRun *pipeline.PipelineRun, c crclient.Client, isFBCBuild bool) error { for _, taskName := range taskNames { // The inspect-image task is only required for FBC pipelines which we can infer by the component name - isFBCBuild := IsFBCBuild(pipelineRun) if !isFBCBuild && taskName == "inspect-image" { continue diff --git a/tests/build/build.go b/tests/build/build.go index 2d11909e6..f7146f2b9 100644 --- a/tests/build/build.go +++ b/tests/build/build.go @@ -110,7 +110,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser } // Delete created webhook from GitHub - cleanupWebhooks(f, helloWorldComponentGitSourceRepoName) + Expect(build.CleanupWebhooks(f, helloWorldComponentGitSourceRepoName)).ShouldNot(HaveOccurred()) }) @@ -913,7 +913,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser } // Delete created webhook from GitHub - cleanupWebhooks(f, secretLookupGitSourceRepoTwoName) + Expect(build.CleanupWebhooks(f, secretLookupGitSourceRepoTwoName)).ShouldNot(HaveOccurred()) }) When("two secrets are created", func() { @@ -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 + Expect(build.CleanupWebhooks(f, helloWorldComponentGitSourceCloneRepoName)).ShouldNot(HaveOccurred()) }) 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() { @@ -1510,10 +1410,8 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser //make the parent repo nudge the child repo if comp.repoName == componentDependenciesParentRepoName { componentObj.BuildNudgesRef = []string{ChildComponentDef.componentName} - comp.component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.ImageControllerAnnotationRequestPublicRepo), constants.DefaultDockerBuildPipelineBundle)) - } else { - comp.component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(constants.ImageControllerAnnotationRequestPublicRepo, constants.DefaultDockerBuildPipelineBundle)) } + comp.component, err = f.AsKubeAdmin.HasController.CreateComponent(componentObj, testNamespace, "", "", applicationName, true, utils.MergeMaps(utils.MergeMaps(constants.ComponentPaCRequestAnnotation, constants.ImageControllerAnnotationRequestPublicRepo), constants.DefaultDockerBuildPipelineBundle)) Expect(err).ShouldNot(HaveOccurred()) } }) @@ -1544,6 +1442,38 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser } Expect(parentFirstDigest).ShouldNot(BeEmpty()) }) + + It(fmt.Sprintf("the PipelineRun should eventually finish successfully for child component %s", ChildComponentDef.componentName), func() { + Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(ChildComponentDef.component, "", f.AsKubeAdmin.TektonController, &has.RetryOptions{Always: true, Retries: 2}, nil)).To(Succeed()) + }) + + It(fmt.Sprintf("should lead to a PaC PR creation for child component %s", ChildComponentDef.componentName), func() { + timeout = time.Second * 300 + interval := time.Second * 1 + + Eventually(func() bool { + prs, err := f.AsKubeAdmin.CommonController.Github.ListPullRequests(ChildComponentDef.repoName) + Expect(err).ShouldNot(HaveOccurred()) + + for _, pr := range prs { + if pr.Head.GetRef() == ChildComponentDef.pacBranchName { + prNumber = pr.GetNumber() + return true + } + } + return false + }, timeout, interval).Should(BeTrue(), fmt.Sprintf("timed out when waiting for PaC PR (branch name '%s') to be created in %s repository", ChildComponentDef.pacBranchName, ChildComponentDef.repoName)) + }) + + It(fmt.Sprintf("Merging the PaC PR should be successful for child component %s", ChildComponentDef.componentName), func() { + Eventually(func() error { + mergeResult, err = f.AsKubeAdmin.CommonController.Github.MergePullRequest(ChildComponentDef.repoName, prNumber) + return err + }, time.Minute).Should(BeNil(), fmt.Sprintf("error when merging PaC pull request #%d in repo %s", prNumber, ChildComponentDef.repoName)) + + mergeResultSha = mergeResult.GetSHA() + GinkgoWriter.Printf("merged result sha: %s for PR #%d\n", mergeResultSha, prNumber) + }) // Now we have an initial image we create a dockerfile in the child that references this new image // This is the file that will be updated by the nudge It("create dockerfile and yaml manifest that references build and distribution repositorys", func() { @@ -1603,7 +1533,6 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build-ser mergeResultSha = mergeResult.GetSHA() GinkgoWriter.Printf("merged result sha: %s for PR #%d\n", mergeResultSha, prNumber) - }) // Now the PR is merged this will kick off another build. The result of this build is what we want to update in dockerfile we created It(fmt.Sprintf("PR merge triggers PAC PipelineRun for parent component %s", ParentComponentDef.componentName), func() { @@ -1703,16 +1632,3 @@ func createBuildSecret(f *framework.Framework, secretName string, annotations ma } return nil } - -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/build/build_templates.go b/tests/build/build_templates.go index c8fa930f3..9d2707271 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,30 @@ 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 = kubeadminClient.CommonController.Github.DeleteRef(branches.RepoName, branches.PacBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + err = kubeadminClient.CommonController.Github.DeleteRef(branches.RepoName, branches.BaseBranchName) + if err != nil { + Expect(err.Error()).To(ContainSubstring("Reference does not exist")) + } + } + //Cleanup webhook when not running for build-definitions CI + if os.Getenv(constants.E2E_APPLICATIONS_NAMESPACE_ENV) == "" { + for _, branches := range pacAndBaseBranches { + Expect(build.CleanupWebhooks(f, branches.RepoName)).ShouldNot(HaveOccurred(), fmt.Sprintf("failed to cleanup webhooks for repo: %s", branches.RepoName)) + } + } }) 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 { @@ -313,7 +366,7 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", Expect(err).ShouldNot(HaveOccurred()) Expect(pr).ToNot(BeNil(), fmt.Sprintf("PipelineRun for the component %s/%s not found", testNamespace, componentNames[i])) - if build.IsFBCBuild(pr) { + if IsFBCBuild(gitUrl) { GinkgoWriter.Println("This is FBC build, which does not require source container build.") Skip(fmt.Sprintf("Skiping FBC build %s", pr.GetName())) return @@ -420,7 +473,7 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", It(fmt.Sprintf("should validate tekton taskrun test results for component with Git source URL %s", gitUrl), Label(buildTemplatesTestLabel), func() { pr, err := kubeadminClient.HasController.GetComponentPipelineRun(componentNames[i], applicationName, testNamespace, "") Expect(err).ShouldNot(HaveOccurred()) - Expect(build.ValidateBuildPipelineTestResults(pr, kubeadminClient.CommonController.KubeRest())).To(Succeed()) + Expect(build.ValidateBuildPipelineTestResults(pr, kubeadminClient.CommonController.KubeRest(), IsFBCBuild(gitUrl))).To(Succeed()) }) When(fmt.Sprintf("the container image for component with Git source URL %s is created and pushed to container registry", gitUrl), Label("sbom", "slow"), func() { @@ -601,16 +654,16 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", pr, err = kubeadminClient.TektonController.GetPipelineRun(pr.Name, pr.Namespace) Expect(err).NotTo(HaveOccurred()) GinkgoWriter.Printf("The PipelineRun %s in namespace %s has status.conditions: \n%#v\n", pr.Name, pr.Namespace, pr.Status.Conditions) - + // The UI uses this label to display additional information. Expect(pr.Labels["build.appstudio.redhat.com/pipeline"]).To(Equal("enterprise-contract")) // The UI uses this label to display additional information. - tr, err := kubeadminClient.TektonController.GetTaskRunFromPipelineRun(kubeadminClient.CommonController.KubeRest(), pr, "verify") + tr, err := kubeadminClient.TektonController.GetTaskRunFromPipelineRun(kubeadminClient.CommonController.KubeRest(), pr, "verify") Expect(err).NotTo(HaveOccurred()) - GinkgoWriter.Printf("The TaskRun %s of PipelineRun %s has status.conditions: \n%#v\n", tr.Name, pr.Name, tr.Status.Conditions) + GinkgoWriter.Printf("The TaskRun %s of PipelineRun %s has status.conditions: \n%#v\n", tr.Name, pr.Name, tr.Status.Conditions) Expect(tr.Labels["build.appstudio.redhat.com/pipeline"]).To(Equal("enterprise-contract")) - + logs, err := kubeadminClient.TektonController.GetTaskRunLogs(pr.Name, "verify", pr.Namespace) Expect(err).NotTo(HaveOccurred()) @@ -640,7 +693,7 @@ var _ = framework.BuildSuiteDescribe("Build templates E2E test", Label("build", 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"))) + kubeadminClient.TektonController, &has.RetryOptions{Retries: 0}, nil)).Should(MatchError(ContainSubstring("cloned repository contains symlink pointing outside of the cloned repository"))) }) }) }) diff --git a/tests/build/build_templates_scenarios.go b/tests/build/build_templates_scenarios.go index 44cd2f706..70e8b4a27 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,38 @@ 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 IsDockerBuild(gitUrl string) bool { + for _, componentScenario := range componentScenarios { + if utils.GetRepoName(componentScenario.GitURL) == utils.GetRepoName(gitUrl) && componentScenario.PipelineBundleName == "docker-build" { + return true + } + } + return false +} + +func IsFBCBuild(gitUrl string) bool { + for _, componentScenario := range componentScenarios { + if utils.GetRepoName(componentScenario.GitURL) == utils.GetRepoName(gitUrl) && componentScenario.PipelineBundleName == "fbc-builder" { + return true + } + } + return false +} + 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 acd19c9f2..0b700bbb8 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 0be076a29..88a46cda0 100644 --- a/tests/build/jvm-build.go +++ b/tests/build/jvm-build.go @@ -15,6 +15,7 @@ import ( "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/konflux-ci/e2e-tests/pkg/utils/build" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/redhat-appstudio/jvm-build-service/openshift-with-appstudio-test/e2e" @@ -30,19 +31,18 @@ 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") ) -// Marking the test as pending since jvm-build-service will be reworked -var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jvm-build-service"), Pending, func() { +var _ = framework.JVMBuildSuiteDescribe("JVM Build Service E2E tests", Label("jvm-build-service"), func() { var f *framework.Framework AfterEach(framework.ReportFailure(&f)) var err error 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 @@ -63,6 +63,17 @@ 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")) + } + Expect(build.CleanupWebhooks(f, utils.GetRepoName(testProjectGitUrl))).ShouldNot(HaveOccurred()) }) BeforeAll(func() { @@ -94,6 +105,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, @@ -101,12 +118,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 08b3f75fb..742cdc33c 100644 --- a/tests/build/multi-platform.go +++ b/tests/build/multi-platform.go @@ -10,6 +10,7 @@ import ( "time" "github.com/konflux-ci/e2e-tests/pkg/clients/has" + "github.com/konflux-ci/e2e-tests/pkg/utils/build" "golang.org/x/crypto/ssh" v1 "k8s.io/api/core/v1" @@ -53,7 +54,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 +69,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 +85,17 @@ 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")) + } + Expect(build.CleanupWebhooks(f, utils.GetRepoName(multiPlatformProjectGitUrl))).ShouldNot(HaveOccurred()) }) BeforeAll(func() { @@ -101,7 +113,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 +188,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 +211,17 @@ 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")) + } + Expect(build.CleanupWebhooks(f, utils.GetRepoName(multiPlatformProjectGitUrl))).ShouldNot(HaveOccurred()) }) BeforeAll(func() { @@ -221,7 +244,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 +281,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 +304,17 @@ 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")) + } + Expect(build.CleanupWebhooks(f, utils.GetRepoName(multiPlatformProjectGitUrl))).ShouldNot(HaveOccurred()) }) BeforeAll(func() { @@ -300,7 +334,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 +371,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 +394,17 @@ 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")) + } + Expect(build.CleanupWebhooks(f, utils.GetRepoName(multiPlatformProjectGitUrl))).ShouldNot(HaveOccurred()) }) BeforeAll(func() { @@ -380,7 +425,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 +462,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 +475,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 +488,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/build/source_build.go b/tests/build/source_build.go index f89d31608..eb88f34f7 100644 --- a/tests/build/source_build.go +++ b/tests/build/source_build.go @@ -29,12 +29,12 @@ func parseDockerfileUsedForBuild( // CheckParentSources checks the sources coming from parent image are all included in the built source image. // This check is applied to every build for which source build is enabled, then the several prerequisites // for including parent sources are handled as well. -func CheckParentSources(c client.Client, tektonController *tekton.TektonController, pr *pipeline.PipelineRun) { +func CheckParentSources(c client.Client, tektonController *tekton.TektonController, pr *pipeline.PipelineRun, gitUrl string) { buildResult, err := build.ReadSourceBuildResult(c, tektonController, pr) Expect(err).ShouldNot(HaveOccurred()) var baseImagesDigests []string - if build.IsDockerBuild(pr) { + if IsDockerBuild(gitUrl) { parsedDockerfile := parseDockerfileUsedForBuild(c, tektonController, pr) if parsedDockerfile.IsBuildFromScratch() { Expect(buildResult.BaseImageSourceIncluded).Should(BeFalse()) @@ -95,5 +95,5 @@ func CheckSourceImage(srcImage, gitUrl string, hub *framework.ControllerHub, pr Expect(filesExists).To(BeTrue()) c := hub.CommonController.KubeRest() - CheckParentSources(c, hub.TektonController, pr) + CheckParentSources(c, hub.TektonController, pr, gitUrl) } diff --git a/tests/integration-service/const.go b/tests/integration-service/const.go index f8f9cdb02..e4d48bd4c 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 b5af74bee..000000000 --- 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 83697b519..000000000 --- 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 90e320da9..40c0e6531 100644 --- a/tests/integration-service/status-reporting-to-pullrequest.go +++ b/tests/integration-service/status-reporting-to-pullrequest.go @@ -3,19 +3,23 @@ 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" + "github.com/konflux-ci/e2e-tests/pkg/utils/build" 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 +32,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 +63,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)) @@ -79,6 +88,7 @@ var _ = framework.IntegrationServiceSuiteDescribe("Status Reporting of Integrati if err != nil { Expect(err.Error()).To(ContainSubstring(referenceDoesntExist)) } + Expect(build.CleanupWebhooks(f, componentRepoNameForStatusReporting)).ShouldNot(HaveOccurred()) }) When("a new Component with specified custom branch is created", Label("custom-branch"), func() { @@ -117,6 +127,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 +183,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 +213,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 +225,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 +252,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 a1ef0bc44..6242331eb 100644 --- a/tests/konflux-demo/config/scenarios.go +++ b/tests/konflux-demo/config/scenarios.go @@ -15,7 +15,7 @@ var ApplicationSpecs = []ApplicationSpec{ ComponentSpec: ComponentSpec{ 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: "4df701406d34012034dd490fd38d779717582df7", GitSourceContext: "", GitSourceDefaultBranchName: "main", diff --git a/tests/konflux-demo/konflux-demo.go b/tests/konflux-demo/konflux-demo.go index 97a051315..baf2af66f 100644 --- a/tests/konflux-demo/konflux-demo.go +++ b/tests/konflux-demo/konflux-demo.go @@ -118,6 +118,7 @@ var _ = framework.KonfluxDemoSuiteDescribe(Label(devEnvTestLabel), func() { if err != nil { Expect(err.Error()).To(ContainSubstring("Reference does not exist")) } + Expect(build.CleanupWebhooks(fw, componentRepositoryName)).ShouldNot(HaveOccurred()) } }) @@ -274,7 +275,7 @@ var _ = framework.KonfluxDemoSuiteDescribe(Label(devEnvTestLabel), func() { It("should validate Tekton TaskRun test results successfully", func() { pipelineRun, err = fw.AsKubeAdmin.HasController.GetComponentPipelineRun(component.GetName(), appSpec.ApplicationName, fw.UserNamespace, headSHA) Expect(err).ShouldNot(HaveOccurred()) - Expect(build.ValidateBuildPipelineTestResults(pipelineRun, fw.AsKubeAdmin.CommonController.KubeRest())).To(Succeed()) + Expect(build.ValidateBuildPipelineTestResults(pipelineRun, fw.AsKubeAdmin.CommonController.KubeRest(), false)).To(Succeed()) }) It("should validate that the build pipelineRun is signed", func() { diff --git a/tests/release/const.go b/tests/release/const.go index ef49274cf..374894fb9 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 d6a42b0d2..9c190c227 100644 --- a/tests/release/pipelines/fbc_release.go +++ b/tests/release/pipelines/fbc_release.go @@ -11,6 +11,7 @@ import ( "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/konflux-ci/e2e-tests/pkg/utils/build" "github.com/konflux-ci/e2e-tests/pkg/utils/tekton" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" releaseapi "github.com/konflux-ci/release-service/api/v1alpha1" @@ -24,7 +25,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 +35,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 +46,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 +70,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 +91,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 +103,16 @@ 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")) + } + Expect(build.CleanupWebhooks(devFw, utils.GetRepoName(fbcSourceGitURL))).ShouldNot(HaveOccurred()) }) var _ = Describe("Post-release verification", func() { @@ -119,6 +132,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 +147,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 +158,16 @@ 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")) + } + Expect(build.CleanupWebhooks(devFw, utils.GetRepoName(fbcSourceGitURL))).ShouldNot(HaveOccurred()) }) var _ = Describe("FBC hotfix post-release verification", func() { @@ -163,6 +187,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 +202,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 +215,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 + Expect(build.CleanupWebhooks(devFw, utils.GetRepoName(fbcSourceGitURL))).ShouldNot(HaveOccurred()) }) var _ = Describe("FBC pre-GA post-release verification", func() { @@ -209,6 +245,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 +284,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 +316,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 d6d3a20f6..e29d88dcd 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 9e9fa82ae..250686b23 100644 --- a/tests/release/pipelines/push_to_external_registry.go +++ b/tests/release/pipelines/push_to_external_registry.go @@ -14,6 +14,7 @@ import ( "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/konflux-ci/e2e-tests/pkg/utils/build" "github.com/konflux-ci/e2e-tests/pkg/utils/contract" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" releaseApi "github.com/konflux-ci/release-service/api/v1alpha1" @@ -28,7 +29,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 +73,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 +129,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 + Expect(build.CleanupWebhooks(fw, releasecommon.DcMetroMapGitRepoName)).ShouldNot(HaveOccurred()) }) 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 2915ea7ba..d52a7bac0 100644 --- a/tests/release/pipelines/release_to_github.go +++ b/tests/release/pipelines/release_to_github.go @@ -13,6 +13,7 @@ import ( "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/konflux-ci/e2e-tests/pkg/utils/build" "github.com/konflux-ci/e2e-tests/pkg/utils/tekton" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" releaseapi "github.com/konflux-ci/release-service/api/v1alpha1" @@ -29,9 +30,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 +60,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 +109,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 +124,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 + Expect(build.CleanupWebhooks(devFw, sampRepo)).ShouldNot(HaveOccurred()) + }) var _ = Describe("Post-release verification", func() { diff --git a/tests/release/pipelines/rh_advisories.go b/tests/release/pipelines/rh_advisories.go index a12386809..ef91a2075 100644 --- a/tests/release/pipelines/rh_advisories.go +++ b/tests/release/pipelines/rh_advisories.go @@ -14,6 +14,7 @@ import ( "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/konflux-ci/e2e-tests/pkg/utils/build" "github.com/konflux-ci/e2e-tests/pkg/utils/tekton" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" releaseapi "github.com/konflux-ci/release-service/api/v1alpha1" @@ -56,6 +57,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 +105,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 +118,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 + Expect(build.CleanupWebhooks(devFw, utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl))).ShouldNot(HaveOccurred()) }) 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 c9f49658f..6c9024ffa 100644 --- a/tests/release/pipelines/rh_push_to_external_registry.go +++ b/tests/release/pipelines/rh_push_to_external_registry.go @@ -14,6 +14,7 @@ import ( "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/konflux-ci/e2e-tests/pkg/utils/build" "github.com/konflux-ci/e2e-tests/pkg/utils/contract" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" releaseApi "github.com/konflux-ci/release-service/api/v1alpha1" @@ -47,6 +48,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 +120,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 +151,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 +226,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 + Expect(build.CleanupWebhooks(fw, releasecommon.DcMetroMapGitRepoName)).ShouldNot(HaveOccurred()) + Expect(build.CleanupWebhooks(fw, utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl))).ShouldNot(HaveOccurred()) + }) 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 c5c6b38e1..cd455a67b 100644 --- a/tests/release/pipelines/rh_push_to_redhat_io.go +++ b/tests/release/pipelines/rh_push_to_redhat_io.go @@ -14,6 +14,7 @@ import ( "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/konflux-ci/e2e-tests/pkg/utils/build" "github.com/konflux-ci/e2e-tests/pkg/utils/tekton" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" releaseapi "github.com/konflux-ci/release-service/api/v1alpha1" @@ -57,6 +58,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 +108,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 +121,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 + Expect(build.CleanupWebhooks(devFw, utils.GetRepoName(releasecommon.AdditionalGitSourceComponentUrl))).ShouldNot(HaveOccurred()) }) 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 52ebca69b..3a126dcd1 100644 --- a/tests/release/pipelines/rhtap_service_push.go +++ b/tests/release/pipelines/rhtap_service_push.go @@ -5,17 +5,18 @@ 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/build" "github.com/konflux-ci/e2e-tests/pkg/utils/tekton" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" releaseapi "github.com/konflux-ci/release-service/api/v1alpha1" @@ -70,6 +71,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 +127,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 +162,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 + Expect(build.CleanupWebhooks(devFw, rhtapGitSourceRepoName)).ShouldNot(HaveOccurred()) }) var _ = Describe("Post-release verification", func() { @@ -237,7 +258,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 +316,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 +342,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 +370,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 47dbc836a..7b1d42891 100644 --- a/tests/release/pipelines/tenant_pipelines.go +++ b/tests/release/pipelines/tenant_pipelines.go @@ -8,18 +8,19 @@ 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" + "github.com/konflux-ci/e2e-tests/pkg/utils/build" 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 +35,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 +53,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 +70,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 +83,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 +95,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 + Expect(build.CleanupWebhooks(devFw, releasecommon.DcMetroMapGitRepoName)).ShouldNot(HaveOccurred()) }) var _ = Describe("Post-release verification", func() { diff --git a/tests/release/releaseLib.go b/tests/release/releaseLib.go index 1f6694905..d0f60b975 100644 --- a/tests/release/releaseLib.go +++ b/tests/release/releaseLib.go @@ -1,9 +1,11 @@ package common import ( + "fmt" "os" "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" @@ -26,7 +28,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 +42,15 @@ 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 } diff --git a/tests/release/service/happy_path.go b/tests/release/service/happy_path.go index f302e60c7..cfe38a13c 100644 --- a/tests/release/service/happy_path.go +++ b/tests/release/service/happy_path.go @@ -13,6 +13,7 @@ import ( "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/konflux-ci/e2e-tests/pkg/utils/build" "github.com/konflux-ci/e2e-tests/pkg/utils/contract" "github.com/konflux-ci/e2e-tests/pkg/utils/tekton" releasecommon "github.com/konflux-ci/e2e-tests/tests/release" @@ -29,7 +30,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,11 +76,11 @@ 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) - _, err = fw.AsKubeAdmin.ReleaseController.CreateReleasePlan(releasecommon.SourceReleasePlanName, devNamespace, releasecommon.ApplicationNameDefault, managedNamespace, "", nil, nil) Expect(err).NotTo(HaveOccurred()) + 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{}{ "components": []map[string]interface{}{ @@ -126,6 +127,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 + Expect(build.CleanupWebhooks(fw, releasecommon.DcMetroMapGitRepoName)).ShouldNot(HaveOccurred()) }) var _ = Describe("Post-release verification", func() {