Skip to content

Commit

Permalink
Converts ResultType from string to int enum
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Shivam Mukhade committed Aug 23, 2021
1 parent 8e10069 commit cca4451
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pkg/apis/pipeline/v1beta1/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/pipeline/v1beta1/task_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions pkg/pod/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}]`,
},
},
}},
Expand All @@ -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",
Expand All @@ -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"}}]`,
},
},
}},
Expand All @@ -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",
Expand All @@ -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}]`,
},
},
}},
Expand All @@ -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",
Expand Down Expand Up @@ -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}]`,
},
},
}},
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit cca4451

Please sign in to comment.