Skip to content

Commit

Permalink
chore: store taskRuns in rh_advisiories
Browse files Browse the repository at this point in the history
Signed-off-by: Jing Qi <[email protected]>
  • Loading branch information
tester authored and jinqi7 committed Dec 10, 2024
1 parent fd26460 commit 0dfb609
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/clients/tekton/pipelineruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (t *TektonController) StorePipelineRun(prefix string, pipelineRun *pipeline
artifacts := make(map[string][]byte)
pipelineRunLog, err := t.GetPipelineRunLogs(prefix, pipelineRun.Name, pipelineRun.Namespace)
if err != nil {
return err
g.GinkgoWriter.Printf("an error happened during storing pipelineRun log %s:%s: %s\n", pipelineRun.GetNamespace(), pipelineRun.GetName(), err.Error())
}
artifacts["pipelineRun-"+pipelineRun.Name+".log"] = []byte(pipelineRunLog)

Expand Down
33 changes: 33 additions & 0 deletions pkg/clients/tekton/taskruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"strings"
"time"

"github.com/konflux-ci/e2e-tests/pkg/logs"
"github.com/konflux-ci/e2e-tests/pkg/utils"
g "github.com/onsi/ginkgo/v2"
"github.com/tektoncd/pipeline/pkg/apis/pipeline/pod"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"sigs.k8s.io/yaml"
pointer "k8s.io/utils/ptr"

pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
Expand Down Expand Up @@ -91,6 +93,37 @@ func (t *TektonController) GetTaskRun(name, namespace string) (*pipeline.TaskRun
return &taskRun, nil
}

// StoreTaskRun stores a given TaskRun as an artifact.
func (t *TektonController) StoreTaskRun(prefix string, taskRun *pipeline.TaskRun) error {
artifacts := make(map[string][]byte)

taskRunYaml, err := yaml.Marshal(taskRun)
if err != nil {
g.GinkgoWriter.Printf("failed to store taskRun %s:%s: %s\n", taskRun.GetNamespace(), taskRun.GetName(), err.Error())
}
artifacts["taskRun-"+taskRun.Name+".yaml"] = taskRunYaml

if err := logs.StoreArtifacts(artifacts); err != nil {
return err
}

return nil
}

func (t *TektonController) StoreTaskRunsForPipelineRun(c crclient.Client, pr *pipeline.PipelineRun) error {
for _, chr := range pr.Status.ChildReferences {
taskRun := &pipeline.TaskRun{}
taskRunKey := types.NamespacedName{Namespace: pr.Namespace, Name: chr.Name}
if err := c.Get(context.Background(), taskRunKey, taskRun); err != nil {
return err
}
if err := t.StoreTaskRun(taskRun.Name, taskRun); err != nil{
g.GinkgoWriter.Printf("an error happened during storing taskRun %s:%s: %s\n", taskRun.GetNamespace(), taskRun.GetName(), err.Error())
}
}
return nil
}

// GetTaskRunLogs returns logs of a specified taskRun.
func (t *TektonController) GetTaskRunLogs(pipelineRunName, pipelineTaskName, namespace string) (map[string]string, error) {
tektonClient := t.PipelineClient().TektonV1beta1().PipelineRuns(namespace)
Expand Down
3 changes: 3 additions & 0 deletions tests/release/pipelines/rh_advisories.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ var _ = framework.ReleasePipelinesSuiteDescribe("e2e tests for rh-advisories pip
if err = managedFw.AsKubeDeveloper.TektonController.StorePipelineRun(pipelineRun.Name, pipelineRun); err != nil {
GinkgoWriter.Printf("failed to store PipelineRun %s:%s: %s\n", pipelineRun.GetNamespace(), pipelineRun.GetName(), err.Error())
}
if err = managedFw.AsKubeDeveloper.TektonController.StoreTaskRunsForPipelineRun(managedFw.AsKubeDeveloper.CommonController.KubeRest(), pipelineRun); err != nil {
GinkgoWriter.Printf("failed to store TaskRuns for PipelineRun %s:%s: %s\n", pipelineRun.GetNamespace(), pipelineRun.GetName(), err.Error())
}
if err = devFw.AsKubeDeveloper.ReleaseController.StoreRelease(releaseCR); err != nil {
GinkgoWriter.Printf("failed to store Release %s:%s: %s\n", releaseCR.GetNamespace(), releaseCR.GetName(), err.Error())
}
Expand Down

0 comments on commit 0dfb609

Please sign in to comment.