Skip to content

Commit

Permalink
Fix conversion of non-object results declared in Tasks
Browse files Browse the repository at this point in the history
Prior to this commit, conversion between v1beta1 and v1 Tasks
would create an empty map for task.spec.results.properties,
even if the Task result was not an object result.

Currently, if Task result properties are a nil map, the result is treated
as a string result. If Task result properties are an empty map, the result
is treated as an object result. This commit only updates the conversion logic
of Task results to match the conversion logic of task params; it creates
a non-nil Properties map only if Properties was already non-nil.

Addressing the differences in how nil vs empty Properties are treated
will be handled in a separate commit.
  • Loading branch information
lbernick authored and tekton-robot committed May 1, 2023
1 parent a0fb784 commit 09d422c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 12 additions & 8 deletions pkg/apis/pipeline/v1beta1/result_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ func (r TaskResult) convertTo(ctx context.Context, sink *v1.TaskResult) {
sink.Name = r.Name
sink.Type = v1.ResultsType(r.Type)
sink.Description = r.Description
properties := make(map[string]v1.PropertySpec)
for k, v := range r.Properties {
properties[k] = v1.PropertySpec{Type: v1.ParamType(v.Type)}
if r.Properties != nil {
properties := make(map[string]v1.PropertySpec)
for k, v := range r.Properties {
properties[k] = v1.PropertySpec{Type: v1.ParamType(v.Type)}
}
sink.Properties = properties
}
sink.Properties = properties
}

func (r *TaskResult) convertFrom(ctx context.Context, source v1.TaskResult) {
r.Name = source.Name
r.Type = ResultsType(source.Type)
r.Description = source.Description
properties := make(map[string]PropertySpec)
for k, v := range source.Properties {
properties[k] = PropertySpec{Type: ParamType(v.Type)}
if source.Properties != nil {
properties := make(map[string]PropertySpec)
for k, v := range source.Properties {
properties[k] = PropertySpec{Type: ParamType(v.Type)}
}
r.Properties = properties
}
r.Properties = properties
}
5 changes: 5 additions & 0 deletions pkg/apis/pipeline/v1beta1/task_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func TestTaskConversion(t *testing.T) {
Type: v1beta1.ParamTypeString,
Description: "My first param",
}},
Results: []v1beta1.TaskResult{{
Name: "result-1",
Type: v1beta1.ResultsTypeString,
Description: "a result",
}},
},
},
}, {
Expand Down

0 comments on commit 09d422c

Please sign in to comment.