From 0381a4060bbc84d44359dbc65f13d1f9c0ed86cb Mon Sep 17 00:00:00 2001 From: Sushanta Das Date: Mon, 5 Aug 2024 18:44:07 +0530 Subject: [PATCH] simple build removal related changes in pkg --- pkg/clients/has/components.go | 4 ++-- pkg/clients/tekton/pipelineruns.go | 15 +++++++-------- pkg/utils/build/git.go | 21 +++++++++++++++++++++ pkg/utils/build/task_results.go | 28 +--------------------------- 4 files changed, 31 insertions(+), 37 deletions(-) diff --git a/pkg/clients/has/components.go b/pkg/clients/has/components.go index 7f7508d559..bfd843c5af 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 cf9d45e27b..00193b1f54 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 c3bee4538e..231a0924af 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 30e9733088..80e5f94267 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