From e78dd84d03daa33ceb76e514df55f16c63360818 Mon Sep 17 00:00:00 2001 From: Jerome Ju Date: Thu, 9 Mar 2023 03:39:55 +0000 Subject: [PATCH] Migrate git-init image off PipelineResourceResult This commit makes introduces the generics of PipelineResourceResult and TaskrunResult in termination package and migrates the git-init image off from using PipelineResourceResult. --- cmd/git-init/main.go | 18 +++++++++--------- pkg/termination/write.go | 8 ++++++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/cmd/git-init/main.go b/cmd/git-init/main.go index 19c00fe943a..e42adf0f544 100644 --- a/cmd/git-init/main.go +++ b/cmd/git-init/main.go @@ -17,7 +17,6 @@ package main import ( "flag" - "os" "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" "github.com/tektoncd/pipeline/pkg/git" @@ -58,17 +57,18 @@ func main() { if err != nil { logger.Fatalf("Error parsing revision %s of git repository: %s", fetchSpec.Revision, err) } - resourceName := os.Getenv("TEKTON_RESOURCE_NAME") - output := []v1beta1.PipelineResourceResult{ + output := []v1beta1.TaskRunResult{ { - Key: "commit", - Value: commit, - ResourceName: resourceName, + Name: "commit", + Value: v1beta1.ParamValue{ + StringVal: commit, + }, }, { - Key: "url", - Value: fetchSpec.URL, - ResourceName: resourceName, + Name: "url", + Value: v1beta1.ParamValue{ + StringVal: fetchSpec.URL, + }, }, } diff --git a/pkg/termination/write.go b/pkg/termination/write.go index 3ddae367131..74c26b5f53d 100644 --- a/pkg/termination/write.go +++ b/pkg/termination/write.go @@ -29,13 +29,17 @@ const ( MaxContainerTerminationMessageLength = 1024 * 4 ) +type iResult interface { + v1beta1.TaskRunResult | v1beta1.PipelineResourceResult +} + // WriteMessage writes the results to the termination message path. -func WriteMessage(path string, pro []v1beta1.PipelineResourceResult) error { +func WriteMessage[T v1beta1.TaskRunResult | v1beta1.PipelineResourceResult](path string, pro []T) error { // if the file at path exists, concatenate the new values otherwise create it // file at path already exists fileContents, err := os.ReadFile(path) if err == nil { - var existingEntries []v1beta1.PipelineResourceResult + var existingEntries []T if err := json.Unmarshal(fileContents, &existingEntries); err == nil { // append new entries to existing entries pro = append(existingEntries, pro...)