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 9, 2024
1 parent fd26460 commit 74c6eae
Show file tree
Hide file tree
Showing 3 changed files with 40 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 @@ -239,7 +239,7 @@ func (t *TektonController) StorePipelineRun(prefix string, pipelineRun *pipeline

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

Expand Down
36 changes: 36 additions & 0 deletions pkg/clients/tekton/taskruns.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,42 @@ 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)
taskRunLog, err := t.GetTaskRunLogs(prefix, taskRun.Name, taskRun.Namespace)
if err != nil {
return err
}
artifacts["taskRun-"+taskRun.Name+".log"] = []byte(taskRunLog)

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 string) error {

Check failure on line 116 in pkg/clients/tekton/taskruns.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected string in parameter list; possibly missing comma or )) (typecheck)

Check failure on line 116 in pkg/clients/tekton/taskruns.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected string in parameter list; possibly missing comma or )) (typecheck)

Check failure on line 116 in pkg/clients/tekton/taskruns.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected string in parameter list; possibly missing comma or )) (typecheck)

Check failure on line 116 in pkg/clients/tekton/taskruns.go

View workflow job for this annotation

GitHub Actions / lint

syntax error: unexpected string in parameter list; possibly missing comma or ) (typecheck)

Check failure on line 116 in pkg/clients/tekton/taskruns.go

View workflow job for this annotation

GitHub Actions / lint

missing ',' in parameter list (typecheck)

Check failure on line 116 in pkg/clients/tekton/taskruns.go

View workflow job for this annotation

GitHub Actions / Unit tests

syntax error: unexpected name string in parameter list; possibly missing comma or )
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 = StoreTaskRun(taskRun.Name, taskRun); err != nil{
g.GinkgoWriter.Printf("failed to store 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(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 74c6eae

Please sign in to comment.