Skip to content

Commit

Permalink
V1: Add conversion for TaskRef.Bundle
Browse files Browse the repository at this point in the history
This commit adds support for TaskRef.Bundle when converting between
v1beta1 and v1 versions of TaskRef. This allows us to release v1 TaskRun
and PipelineRun in a backwards compatible way by ensuring that v1beta1
TaskRuns and PipelineRuns with Bundle converted into ResolverRef and
params on the v1 TaskRuns and PipelineRuns on conversion.
  • Loading branch information
JeromeJu committed Sep 12, 2022
1 parent 3733e13 commit 855e66b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pkg/apis/pipeline/v1beta1/taskref_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,38 @@ func (tr TaskRef) convertTo(ctx context.Context, sink *v1.TaskRef) {
sink.Name = tr.Name
sink.Kind = v1.TaskKind(tr.Kind)
sink.APIVersion = tr.APIVersion
// TODO: handle bundle in #4546
new := v1.ResolverRef{}
tr.ResolverRef.convertTo(ctx, &new)
sink.ResolverRef = new
tr.convertBundleToResolver(sink)
}

func (tr *TaskRef) convertFrom(ctx context.Context, source v1.TaskRef) {
tr.Name = source.Name
tr.Kind = TaskKind(source.Kind)
tr.APIVersion = source.APIVersion
// TODO: handle bundle in #4546
new := ResolverRef{}
new.convertFrom(ctx, source.ResolverRef)
tr.ResolverRef = new
}

// convertBundleToResolver converts v1beta1 bundle string to a remote reference with the bundle resolver in v1.
// The conversion from Resolver to Bundle is not being supported since remote resolution would be turned on by
// default and it will be in beta before the stored version of CRD getting swapped to v1.
func (tr TaskRef) convertBundleToResolver(sink *v1.TaskRef) {
if tr.Bundle != "" {
sink.ResolverRef = v1.ResolverRef{
Resolver: "bundles",
Params: []v1.Param{{
Name: "bundle",
Value: v1.ParamValue{StringVal: tr.Bundle},
}, {
Name: "name",
Value: v1.ParamValue{StringVal: tr.Name},
}, {
Name: "kind",
Value: v1.ParamValue{StringVal: "Task"},
}},
}
}
}
33 changes: 33 additions & 0 deletions pkg/apis/pipeline/v1beta1/taskrun_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,39 @@ func TestTaskRunConversionFromDeprecated(t *testing.T) {
},
},
},
}, {
name: "bundle",
in: &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{
Name: "test-bundle-name",
Bundle: "test-bundle",
},
},
},
want: &v1beta1.TaskRun{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Spec: v1beta1.TaskRunSpec{
TaskRef: &v1beta1.TaskRef{
Name: "test-bundle-name",
ResolverRef: v1beta1.ResolverRef{
Resolver: "bundles",
Params: []v1beta1.Param{
{Name: "bundle", Value: v1beta1.ParamValue{StringVal: "test-bundle"}},
{Name: "name", Value: v1beta1.ParamValue{StringVal: "test-bundle-name"}},
{Name: "kind", Value: v1beta1.ParamValue{StringVal: "Task"}},
},
},
},
},
},
}}
for _, test := range tests {
for _, version := range versions {
Expand Down

0 comments on commit 855e66b

Please sign in to comment.