diff --git a/go.sum b/go.sum index b0c4211837..99db8b8048 100644 --- a/go.sum +++ b/go.sum @@ -711,7 +711,6 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= diff --git a/pkg/utils/has/controller.go b/pkg/utils/has/controller.go index 86886e20de..de1e59742e 100644 --- a/pkg/utils/has/controller.go +++ b/pkg/utils/has/controller.go @@ -10,11 +10,13 @@ import ( "github.com/redhat-appstudio/e2e-tests/pkg/constants" "github.com/redhat-appstudio/e2e-tests/pkg/utils" + "github.com/redhat-appstudio/e2e-tests/pkg/utils/common" . "github.com/onsi/ginkgo/v2" routev1 "github.com/openshift/api/route/v1" appservice "github.com/redhat-appstudio/application-api/api/v1alpha1" kubeCl "github.com/redhat-appstudio/e2e-tests/pkg/apis/kubernetes" + "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" @@ -416,7 +418,7 @@ func (h *SuiteController) GetComponentService(componentName string, componentNam return service, nil } -func (h *SuiteController) WaitForComponentPipelineToBeFinished(componentName string, applicationName string, componentNamespace string, sha string) error { +func (h *SuiteController) WaitForComponentPipelineToBeFinished(c *common.SuiteController, componentName, applicationName, componentNamespace, sha string) error { return wait.PollImmediate(20*time.Second, 25*time.Minute, func() (done bool, err error) { pipelineRun, err := h.GetComponentPipelineRun(componentName, applicationName, componentNamespace, sha) @@ -429,7 +431,7 @@ func (h *SuiteController) WaitForComponentPipelineToBeFinished(componentName str GinkgoWriter.Printf("PipelineRun %s reason: %s\n", pipelineRun.Name, condition.Reason) if condition.Reason == "Failed" { - return false, fmt.Errorf("component %s pipeline failed", pipelineRun.Name) + return false, fmt.Errorf(tekton.GetFailedPipelineRunLogs(c, pipelineRun)) } if condition.Status == corev1.ConditionTrue { diff --git a/pkg/utils/tekton/pipelines.go b/pkg/utils/tekton/pipelines.go index 00e41b6e63..b22b2b9d38 100644 --- a/pkg/utils/tekton/pipelines.go +++ b/pkg/utils/tekton/pipelines.go @@ -5,6 +5,8 @@ import ( "strconv" "strings" + "github.com/redhat-appstudio/e2e-tests/pkg/utils" + "github.com/redhat-appstudio/e2e-tests/pkg/utils/common" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -143,3 +145,14 @@ func (p VerifyEnterpriseContract) Generate() *v1beta1.PipelineRun { }, } } + +// GetFailedPipelineRunLogs gets the logs of the pipelinerun failed task +func GetFailedPipelineRunLogs(c *common.SuiteController, pipelineRun *v1beta1.PipelineRun) string { + failMessage := fmt.Sprintf("Pipelinerun '%s' didn't succeed\n", pipelineRun.Name) + d := utils.GetFailedPipelineRunDetails(pipelineRun) + if d.FailedContainerName != "" { + logs, _ := c.GetContainerLogs(d.PodName, d.FailedContainerName, pipelineRun.Namespace) + failMessage += fmt.Sprintf("Logs from failed container '%s': \n%s", d.FailedContainerName, logs) + } + return failMessage +} diff --git a/tests/build/build.go b/tests/build/build.go index ca4ed52a4b..060a0c6ef1 100644 --- a/tests/build/build.go +++ b/tests/build/build.go @@ -11,6 +11,7 @@ import ( "github.com/google/go-github/v44/github" "github.com/redhat-appstudio/e2e-tests/pkg/utils/build" + "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" "github.com/devfile/library/pkg/util" "github.com/google/uuid" @@ -194,12 +195,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " } if !pipelineRun.GetStatusCondition().GetCondition(apis.ConditionSucceeded).IsTrue() { - failMessage := fmt.Sprintf("Pipelinerun '%s' didn't succeed\n", pipelineRun.Name) - d := utils.GetFailedPipelineRunDetails(pipelineRun) - if d.FailedContainerName != "" { - logs, _ := f.AsKubeAdmin.CommonController.GetContainerLogs(d.PodName, d.FailedContainerName, testNamespace) - failMessage += fmt.Sprintf("Logs from failed container '%s': \n%s", d.FailedContainerName, logs) - } + failMessage := tekton.GetFailedPipelineRunLogs(f.AsKubeAdmin.CommonController, pipelineRun) Fail(failMessage) } } @@ -272,12 +268,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " } if !pipelineRun.GetStatusCondition().GetCondition(apis.ConditionSucceeded).IsTrue() { - failMessage := fmt.Sprintf("Pipelinerun '%s' didn't succeed\n", pipelineRun.Name) - d := utils.GetFailedPipelineRunDetails(pipelineRun) - if d.FailedContainerName != "" { - logs, _ := f.AsKubeAdmin.CommonController.GetContainerLogs(d.PodName, d.FailedContainerName, testNamespace) - failMessage += fmt.Sprintf("Logs from failed container '%s': \n%s", d.FailedContainerName, logs) - } + failMessage := tekton.GetFailedPipelineRunLogs(f.AsKubeAdmin.CommonController, pipelineRun) Fail(failMessage) } } @@ -332,6 +323,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " return pipelineRun.HasStarted() }, timeout, interval).Should(BeTrue(), "timed out when waiting for the PipelineRun to start") }) + It("pipelineRun should eventually finish", func() { timeout = time.Minute * 50 interval = time.Second * 10 @@ -348,12 +340,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " } if !pipelineRun.GetStatusCondition().GetCondition(apis.ConditionSucceeded).IsTrue() { - failMessage := fmt.Sprintf("Pipelinerun '%s' didn't succeed\n", pipelineRun.Name) - d := utils.GetFailedPipelineRunDetails(pipelineRun) - if d.FailedContainerName != "" { - logs, _ := f.AsKubeAdmin.CommonController.GetContainerLogs(d.PodName, d.FailedContainerName, testNamespace) - failMessage += fmt.Sprintf("Logs from failed container '%s': \n%s", d.FailedContainerName, logs) - } + failMessage := tekton.GetFailedPipelineRunLogs(f.AsKubeAdmin.CommonController, pipelineRun) Fail(failMessage) } } @@ -483,12 +470,7 @@ var _ = framework.BuildSuiteDescribe("Build service E2E tests", Label("build", " } if !pipelineRun.GetStatusCondition().GetCondition(apis.ConditionSucceeded).IsTrue() { - failMessage := fmt.Sprintf("Pipelinerun '%s' didn't succeed\n", pipelineRun.Name) - d := utils.GetFailedPipelineRunDetails(pipelineRun) - if d.FailedContainerName != "" { - logs, _ := f.AsKubeAdmin.CommonController.GetContainerLogs(d.PodName, d.FailedContainerName, testNamespace) - failMessage += fmt.Sprintf("Logs from failed container '%s': \n%s", d.FailedContainerName, logs) - } + failMessage := tekton.GetFailedPipelineRunLogs(f.AsKubeAdmin.CommonController, pipelineRun) Fail(failMessage) } } diff --git a/tests/e2e-demos/e2e-demo.go b/tests/e2e-demos/e2e-demo.go index ac1148dbf4..3df93ba516 100644 --- a/tests/e2e-demos/e2e-demo.go +++ b/tests/e2e-demos/e2e-demo.go @@ -199,7 +199,11 @@ var _ = framework.E2ESuiteDescribe(Label("e2e-demo"), func() { err = fw.AsKubeDeveloper.HasController.KubeRest().Update(context.Background(), component) Expect(err).ShouldNot(HaveOccurred(), "failed to update component to trigger another pipeline build: %v", err) } - Expect(fw.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(component.Name, application.Name, namespace, "")).To(Succeed(), "Failed component pipeline %v", err) + + err := fw.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(fw.AsKubeAdmin.CommonController, component.Name, application.Name, namespace, "") + if err != nil { + Fail(fmt.Sprint(err)) + } }) It("finds the snapshot and checks if it is marked as successful", func() { diff --git a/tests/e2e-demos/multi-component.go b/tests/e2e-demos/multi-component.go index 02ce85379d..b558cd12c1 100644 --- a/tests/e2e-demos/multi-component.go +++ b/tests/e2e-demos/multi-component.go @@ -172,17 +172,17 @@ var _ = framework.E2ESuiteDescribe(Label("e2e-demo"), func() { // Start to watch the pipeline until is finished It("waits for all pipelines to be finished", func() { - err := fw.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(compNameGo, testSpecification.Tests[0].ApplicationName, namespace, "") + err := fw.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(fw.AsKubeAdmin.CommonController, compNameGo, testSpecification.Tests[0].ApplicationName, namespace, "") if err != nil { removeApplication = false + Fail(fmt.Sprint(err)) } - Expect(err).NotTo(HaveOccurred(), "Failed component pipeline %v", err) - err = fw.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(compNameNode, testSpecification.Tests[0].ApplicationName, namespace, "") + err = fw.AsKubeDeveloper.HasController.WaitForComponentPipelineToBeFinished(fw.AsKubeAdmin.CommonController, compNameNode, testSpecification.Tests[0].ApplicationName, namespace, "") if err != nil { removeApplication = false + Fail(fmt.Sprint(err)) } - Expect(err).NotTo(HaveOccurred(), "Failed component pipeline %v", err) }) It("finds the snapshot and checks if it is marked as successful for golang component", func() { diff --git a/tests/integration-service/integration.go b/tests/integration-service/integration.go index 36c9dab16d..96fd4d1671 100644 --- a/tests/integration-service/integration.go +++ b/tests/integration-service/integration.go @@ -9,6 +9,7 @@ import ( "github.com/google/uuid" "github.com/redhat-appstudio/e2e-tests/pkg/framework" "github.com/redhat-appstudio/e2e-tests/pkg/utils" + "github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton" appstudioApi "github.com/redhat-appstudio/application-api/api/v1alpha1" @@ -111,7 +112,7 @@ var _ = framework.IntegrationServiceSuiteDescribe("Integration Service E2E tests GinkgoWriter.Printf("PipelineRun %s Status.Conditions.Reason: %s\n", pipelineRun.Name, condition.Reason) if condition.Reason == "Failed" { - Fail(fmt.Sprintf("Pipelinerun %s has failed", pipelineRun.Name)) + Fail(tekton.GetFailedPipelineRunLogs(f.AsKubeAdmin.CommonController, pipelineRun)) } } return pipelineRun.IsDone() diff --git a/tests/mvp-demo/mvp-demo.go b/tests/mvp-demo/mvp-demo.go index 8ce2bf8a1b..1a66dc6c92 100644 --- a/tests/mvp-demo/mvp-demo.go +++ b/tests/mvp-demo/mvp-demo.go @@ -190,7 +190,7 @@ var _ = framework.MvpDemoSuiteDescribe("MVP Demo tests", Label("mvp-demo"), func It("sample app can be built successfully", func() { _, err = f.AsKubeAdmin.HasController.CreateComponent(appName, componentName, userNamespace, sampleRepoURL, componentNewBaseBranch, "", constants.DefaultImagePushRepo, "", true) Expect(err).ShouldNot(HaveOccurred()) - Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(componentName, appName, userNamespace, "")).To(Succeed()) + Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(f.AsKubeAdmin.CommonController, componentName, appName, userNamespace, "")).To(Succeed()) }) It("sample app is successfully deployed to dev environment", func() { @@ -310,7 +310,7 @@ var _ = framework.MvpDemoSuiteDescribe("MVP Demo tests", Label("mvp-demo"), func }) It("SLSA level 3 customizable pipeline completes successfully", func() { - Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(componentName, appName, userNamespace, mergeResultSha)).To(Succeed()) + Expect(f.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(f.AsKubeAdmin.CommonController, componentName, appName, userNamespace, mergeResultSha)).To(Succeed()) }) It("resulting SBOM file can be downloaded", func() {