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 serialized into annotations on the
v1 TaskRuns and PipelineRuns on conversion.
  • Loading branch information
JeromeJu committed Sep 8, 2022
1 parent 64984fc commit 6769f29
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 2 deletions.
36 changes: 36 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pick 62d14a3cf V1: Add conversion for TaskRef.Bundle
squash 8c0fde8d7 WIp
squash 475a5bf4a WIP
squash 6cf0a36fc WIP
squash fa576b3ca wip

# Rebase 64984fcca..fa576b3ca onto 64984fcca (5 commands)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup [-C | -c] <commit> = like "squash" but keep only the previous
# commit's log message, unless -C is used, in which case
# keep only this commit's message; -c is same as -C but
# opens the editor
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# create a merge commit using the original merge commit's
# message (or the oneline, if no original merge commit was
# specified); use -c <commit> to reword the commit message
# u, update-ref <ref> = track a placeholder for the <ref> to be updated
# to this position in the new commits. The <ref> is
# updated at the end of the rebase
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
37 changes: 35 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,51 @@ 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
tr.convertResolverToBundle(source)
}

// convertBundleToResolver converts v1beta1 bundle string to a remote reference with the bundle resolver in 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: tr.Name},
}},
}
}
}

//
func (tr *TaskRef) convertResolverToBundle(source v1.TaskRef) {
if source.ResolverRef.Resolver == "bundles" {
for _, p := range source.Params {
if p.Name == "bundle" {
tr.Bundle = p.Value.StringVal
}
if p.Name == "name" {
tr.Name = p.Value.StringVal
}
}
}
}
34 changes: 34 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,40 @@ 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",
Bundle: "test-bundle",
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: "test-bundle-name"}},
},
},
},
},
},
}}
for _, test := range tests {
for _, version := range versions {
Expand Down

0 comments on commit 6769f29

Please sign in to comment.