Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: store taskRuns in rh_advisiories #1474

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
johnbieren marked this conversation as resolved.
Show resolved Hide resolved
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
Loading