Skip to content

Commit

Permalink
Support quoted name references.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmoor committed Dec 14, 2020
1 parent ec1fb87 commit 7cbb29e
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 56 deletions.
2 changes: 2 additions & 0 deletions pkg/reconciler/pipelinerun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func ApplyParameters(p *v1beta1.PipelineSpec, pr *v1beta1.PipelineRun) *v1beta1.

patterns := []string{
"params.%s",
"params.%q",
}

// Set all the default stringReplacements
Expand Down Expand Up @@ -102,6 +103,7 @@ func ApplyWorkspaces(p *v1beta1.PipelineSpec, pr *v1beta1.PipelineRun) *v1beta1.

patterns := []string{
"workspaces.%s.bound",
"workspaces.%q.bound",
}

for _, declaredWorkspace := range p.Workspaces {
Expand Down
48 changes: 48 additions & 0 deletions pkg/reconciler/pipelinerun/resources/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,35 @@ func TestApplyParameters(t *testing.T) {
},
}},
},
}, {
name: "quoted DNS parameters",
original: v1beta1.PipelineSpec{
Params: []v1beta1.ParamSpec{
{Name: "dev.tekton.first", Type: v1beta1.ParamTypeString, Default: v1beta1.NewArrayOrString("default-value")},
{Name: "dev.tekton.second", Type: v1beta1.ParamTypeString},
},
Tasks: []v1beta1.PipelineTask{{
Params: []v1beta1.Param{
{Name: "first-task-first-param", Value: *v1beta1.NewArrayOrString(`$(params."dev.tekton.first")`)},
{Name: "first-task-second-param", Value: *v1beta1.NewArrayOrString(`$(params."dev.tekton.second")`)},
{Name: "first-task-third-param", Value: *v1beta1.NewArrayOrString("static value")},
},
}},
},
params: []v1beta1.Param{{Name: "dev.tekton.second", Value: *v1beta1.NewArrayOrString("second-value")}},
expected: v1beta1.PipelineSpec{
Params: []v1beta1.ParamSpec{
{Name: "dev.tekton.first", Type: v1beta1.ParamTypeString, Default: v1beta1.NewArrayOrString("default-value")},
{Name: "dev.tekton.second", Type: v1beta1.ParamTypeString},
},
Tasks: []v1beta1.PipelineTask{{
Params: []v1beta1.Param{
{Name: "first-task-first-param", Value: *v1beta1.NewArrayOrString("default-value")},
{Name: "first-task-second-param", Value: *v1beta1.NewArrayOrString("second-value")},
{Name: "first-task-third-param", Value: *v1beta1.NewArrayOrString("static value")},
},
}},
},
}} {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -577,6 +606,16 @@ func TestApplyWorkspaces(t *testing.T) {
}},
variableUsage: "$(workspaces.foo.bound)",
expectedReplacement: "true",
}, {
description: "quoted workspace declared and bound",
declarations: []v1beta1.PipelineWorkspaceDeclaration{{
Name: "foo",
}},
bindings: []v1beta1.WorkspaceBinding{{
Name: "foo",
}},
variableUsage: `$(workspaces."foo".bound)`,
expectedReplacement: "true",
}, {
description: "workspace declared not bound",
declarations: []v1beta1.PipelineWorkspaceDeclaration{{
Expand All @@ -586,6 +625,15 @@ func TestApplyWorkspaces(t *testing.T) {
bindings: []v1beta1.WorkspaceBinding{},
variableUsage: "$(workspaces.foo.bound)",
expectedReplacement: "false",
}, {
description: "quoted workspace declared not bound",
declarations: []v1beta1.PipelineWorkspaceDeclaration{{
Name: "foo",
Optional: true,
}},
bindings: []v1beta1.WorkspaceBinding{},
variableUsage: `$(workspaces."foo".bound)`,
expectedReplacement: "false",
}} {
t.Run(tc.description, func(t *testing.T) {
p1 := v1beta1.PipelineSpec{
Expand Down
6 changes: 6 additions & 0 deletions pkg/reconciler/taskrun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func ApplyParameters(spec *v1beta1.TaskSpec, tr *v1beta1.TaskRun, defaults ...v1

patterns := []string{
"params.%s",
"params.%q",
// FIXME(vdemeester) Remove that with deprecating v1beta1
"inputs.params.%s",
}
Expand Down Expand Up @@ -79,6 +80,7 @@ func ApplyParameters(spec *v1beta1.TaskSpec, tr *v1beta1.TaskRun, defaults ...v1
func ApplyResources(spec *v1beta1.TaskSpec, resolvedResources map[string]v1beta1.PipelineResourceInterface, replacementStr string) *v1beta1.TaskSpec {
replacementPatterns := []string{
"resources.%s.%s.%s",
"resources.%s.%q.%s",
// FIXME(vdemeester) Remove that with deprecating v1beta1
"%s.resources.%s.%s",
}
Expand All @@ -95,6 +97,7 @@ func ApplyResources(spec *v1beta1.TaskSpec, resolvedResources map[string]v1beta1
if spec.Resources != nil && spec.Resources.Inputs != nil {
patterns := []string{
"resources.inputs.%s.path",
"resources.inputs.%q.path",
// FIXME(vdemeester) Remove that with deprecating v1beta1
"inputs.resources.%s.path",
}
Expand All @@ -108,6 +111,7 @@ func ApplyResources(spec *v1beta1.TaskSpec, resolvedResources map[string]v1beta1
if spec.Resources != nil && spec.Resources.Outputs != nil {
patterns := []string{
"resources.outputs.%s.path",
"resources.outputs.%q.path",
// FIXME(vdemeester) Remove that with deprecating v1beta1
"outputs.resources.%s.path",
}
Expand Down Expand Up @@ -146,6 +150,7 @@ func ApplyWorkspaces(spec *v1beta1.TaskSpec, declarations []v1beta1.WorkspaceDec

patterns := []string{
"workspaces.%s.%s",
"workspaces.%q.%s",
}

for _, declaration := range declarations {
Expand Down Expand Up @@ -184,6 +189,7 @@ func ApplyTaskResults(spec *v1beta1.TaskSpec) *v1beta1.TaskSpec {

patterns := []string{
"results.%s.path",
"results.%q.path",
}

for _, result := range spec.Results {
Expand Down
Loading

0 comments on commit 7cbb29e

Please sign in to comment.