Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
JeromeJu committed Sep 12, 2022
1 parent 3733e13 commit f17ecaf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
24 changes: 22 additions & 2 deletions pkg/apis/pipeline/v1beta1/pipelineref_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,37 @@ import (
func (pr PipelineRef) convertTo(ctx context.Context, sink *v1.PipelineRef) {
sink.Name = pr.Name
sink.APIVersion = pr.APIVersion
// TODO: handle bundle in #4546
new := v1.ResolverRef{}
pr.ResolverRef.convertTo(ctx, &new)
sink.ResolverRef = new
pr.convertBundleToResolver(sink)
}

func (pr *PipelineRef) convertFrom(ctx context.Context, source v1.PipelineRef) {
pr.Name = source.Name
pr.APIVersion = source.APIVersion
// TODO: handle bundle in #4546
new := ResolverRef{}
new.convertFrom(ctx, source.ResolverRef)
pr.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 PipelineRef) convertBundleToResolver(sink *v1.PipelineRef) {
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"},
}},
}
}
}
34 changes: 33 additions & 1 deletion pkg/apis/pipeline/v1beta1/pipelinerun_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,40 @@ func TestPipelineRunConversionFromDeprecated(t *testing.T) {
},
},
},
}, {
name: "bundle",
in: &v1beta1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Spec: v1beta1.PipelineRunSpec{
PipelineRef: &v1beta1.PipelineRef{
Name: "test-bundle-name",
Bundle: "test-bundle",
},
},
},
want: &v1beta1.PipelineRun{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Namespace: "bar",
},
Spec: v1beta1.PipelineRunSpec{
PipelineRef: &v1beta1.PipelineRef{
Name: "test-bundle-name",
ResolverRef: v1beta1.ResolverRef{
Resolver: "bundles",
Params: []v1beta1.Param{
{Name: "bundle", Value: v1beta1.ParamValue{StringVal: "test-bundles"}},
{Name: "name", Value: v1beta1.ParamValue{StringVal: "test-bundle-name"}},
{Name: "kind", Value: v1beta1.ParamValue{StringVal: "Task"}},
},
},
},
},
},
}}
// TODO add the cases for bundles #4546
for _, test := range tests {
for _, version := range versions {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit f17ecaf

Please sign in to comment.