From cca4451e578bf37881bc1b1c6243e723e0acd04a Mon Sep 17 00:00:00 2001 From: Shivam Mukhade Date: Mon, 23 Aug 2021 23:43:38 +0530 Subject: [PATCH] Converts ResultType from string to int enum This converts the ResultType from string to int enum to curtail the size of json object emittted by steps. Closes #4150 Signed-off-by: Shivam Mukhade --- pkg/apis/pipeline/v1beta1/resource_types.go | 4 ++-- pkg/apis/pipeline/v1beta1/task_types.go | 8 ++++---- pkg/pod/status_test.go | 22 ++++++++++----------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/pkg/apis/pipeline/v1beta1/resource_types.go b/pkg/apis/pipeline/v1beta1/resource_types.go index 91192d3b4f0..6a87233daf9 100644 --- a/pkg/apis/pipeline/v1beta1/resource_types.go +++ b/pkg/apis/pipeline/v1beta1/resource_types.go @@ -126,11 +126,11 @@ type PipelineResourceResult struct { // The field ResourceRef should be deprecated and removed in the next API version. // See https://github.com/tektoncd/pipeline/issues/2694 for more information. ResourceRef *PipelineResourceRef `json:"resourceRef,omitempty"` - ResultType ResultType `json:"type,omitempty"` + ResultType ResultType `json:"t,omitempty"` } // ResultType used to find out whether a PipelineResourceResult is from a task result or not -type ResultType string +type ResultType int // PipelineResourceRef can be used to refer to a specific instance of a Resource type PipelineResourceRef struct { diff --git a/pkg/apis/pipeline/v1beta1/task_types.go b/pkg/apis/pipeline/v1beta1/task_types.go index b41a8edcb7e..1beca09daee 100644 --- a/pkg/apis/pipeline/v1beta1/task_types.go +++ b/pkg/apis/pipeline/v1beta1/task_types.go @@ -23,13 +23,13 @@ import ( const ( // TaskRunResultType default task run result value - TaskRunResultType ResultType = "TaskRunResult" + TaskRunResultType ResultType = iota + 1 // PipelineResourceResultType default pipeline result value - PipelineResourceResultType ResultType = "PipelineResourceResult" + PipelineResourceResultType // InternalTektonResultType default internal tekton result value - InternalTektonResultType ResultType = "InternalTektonResult" + InternalTektonResultType // UnknownResultType default unknown result type value - UnknownResultType ResultType = "" + UnknownResultType ) // +genclient diff --git a/pkg/pod/status_test.go b/pkg/pod/status_test.go index 746adff3618..cece2628895 100644 --- a/pkg/pod/status_test.go +++ b/pkg/pod/status_test.go @@ -549,7 +549,7 @@ func TestMakeTaskRunStatus(t *testing.T) { Name: "step-bar", State: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultName","value":"resultValue", "type": "TaskRunResult"}, {"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}}]`, + Message: `[{"key":"resultName","value":"resultValue", "t":1}, {"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}}]`, }, }, }}, @@ -560,7 +560,7 @@ func TestMakeTaskRunStatus(t *testing.T) { Steps: []v1beta1.StepState{{ ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}},{"key":"resultName","value":"resultValue","type":"TaskRunResult"}]`, + Message: `[{"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}},{"key":"resultName","value":"resultValue","t":1}]`, }}, Name: "bar", ContainerName: "step-bar", @@ -587,7 +587,7 @@ func TestMakeTaskRunStatus(t *testing.T) { Name: "step-banana", State: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultName","value":"resultValue", "type": "TaskRunResult"}, {"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}}]`, + Message: `[{"key":"resultName","value":"resultValue", "t":1}, {"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}}]`, }, }, }}, @@ -598,7 +598,7 @@ func TestMakeTaskRunStatus(t *testing.T) { Steps: []v1beta1.StepState{{ ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}},{"key":"resultName","value":"resultValue","type":"TaskRunResult"}]`, + Message: `[{"key":"digest","value":"sha256:1234","resourceRef":{"name":"source-image"}},{"key":"resultName","value":"resultValue","t":1}]`, }}, Name: "banana", ContainerName: "step-banana", @@ -625,14 +625,14 @@ func TestMakeTaskRunStatus(t *testing.T) { Name: "step-one", State: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultNameOne","value":"resultValueOne", "type": "TaskRunResult"}, {"key":"resultNameTwo","value":"resultValueTwo", "type": "TaskRunResult"}]`, + Message: `[{"key":"resultNameOne","value":"resultValueOne", "t":1}, {"key":"resultNameTwo","value":"resultValueTwo", "t":1}]`, }, }, }, { Name: "step-two", State: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultNameOne","value":"resultValueThree","type":"TaskRunResult"},{"key":"resultNameTwo","value":"resultValueTwo","type":"TaskRunResult"}]`, + Message: `[{"key":"resultNameOne","value":"resultValueThree","t":1},{"key":"resultNameTwo","value":"resultValueTwo","t":1}]`, }, }, }}, @@ -643,14 +643,14 @@ func TestMakeTaskRunStatus(t *testing.T) { Steps: []v1beta1.StepState{{ ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultNameOne","value":"resultValueOne","type":"TaskRunResult"},{"key":"resultNameTwo","value":"resultValueTwo","type":"TaskRunResult"}]`, + Message: `[{"key":"resultNameOne","value":"resultValueOne","t":1},{"key":"resultNameTwo","value":"resultValueTwo","t":1}]`, }}, Name: "one", ContainerName: "step-one", }, { ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultNameOne","value":"resultValueThree","type":"TaskRunResult"},{"key":"resultNameTwo","value":"resultValueTwo","type":"TaskRunResult"}]`, + Message: `[{"key":"resultNameOne","value":"resultValueThree","t":1},{"key":"resultNameTwo","value":"resultValueTwo","t":1}]`, }}, Name: "two", ContainerName: "step-two", @@ -727,7 +727,7 @@ func TestMakeTaskRunStatus(t *testing.T) { Name: "step-pear", State: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultNameOne","value":"","type":"PipelineResourceResult"}, {"key":"resultNameTwo","value":"","type":"InternalTektonResult"}, {"key":"resultNameThree","value":"","type":"TaskRunResult"}]`, + Message: `[{"key":"resultNameOne","value":"","t":2}, {"key":"resultNameTwo","value":"","t":3}, {"key":"resultNameThree","value":"","t":1}]`, }, }, }}, @@ -738,7 +738,7 @@ func TestMakeTaskRunStatus(t *testing.T) { Steps: []v1beta1.StepState{{ ContainerState: corev1.ContainerState{ Terminated: &corev1.ContainerStateTerminated{ - Message: `[{"key":"resultNameOne","value":"","type":"PipelineResourceResult"},{"key":"resultNameThree","value":"","type":"TaskRunResult"}]`, + Message: `[{"key":"resultNameOne","value":"","t":2},{"key":"resultNameThree","value":"","t":1}]`, }}, Name: "pear", ContainerName: "step-pear", @@ -747,7 +747,7 @@ func TestMakeTaskRunStatus(t *testing.T) { ResourcesResult: []v1beta1.PipelineResourceResult{{ Key: "resultNameOne", Value: "", - ResultType: "PipelineResourceResult", + ResultType: v1beta1.PipelineResourceResultType, }}, TaskRunResults: []v1beta1.TaskRunResult{{ Name: "resultNameThree",