Skip to content

Commit 1c4d4b2

Browse files
bobcatfishtekton-robot
authored andcommitted
Remove support for ${} syntax 🗑️
In #850 we decided that to make our syntax more similar to k8s style syntax, we will use $() for variable substitution instead of ${}. In a later iteration we may also want to make it so that anything that can be acesssed as a variable is also available as an env var to the running container, but that is TBD. In #1172 we added support for the new syntax, $(), and continued support for ${}, which was released in 0.6. This commit removes support for ${}. Fixes #1170
1 parent 10b6427 commit 1c4d4b2

File tree

15 files changed

+63
-559
lines changed

15 files changed

+63
-559
lines changed

docs/pipelines.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ parameters can be passed to the `Pipeline` from a `PipelineRun`.
9191

9292
Input parameters in the form of `$(params.foo)` are replaced inside of the
9393
[`PipelineTask` parameters' values](#pipeline-tasks) (see also
94-
[variable substitution](tasks.md#variable-substitution)). _As with
95-
[variable substitution](tasks.md#variable-substitution), the deprecated syntax
96-
`${params.foo}` will be supported until [#1170](https://github.com/tektoncd/pipeline/issues/1170)._
94+
[variable substitution](tasks.md#variable-substitution)).
9795

9896
The following `Pipeline` declares an input parameter called 'context', and uses
9997
it in the `PipelineTask`'s parameter. The `description` and `default` fields for

docs/resources.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@ The `path` key is pre-defined and refers to the local path to a resource on the
8686
$(inputs.resouces.<name>.path)
8787
```
8888

89-
_The deprecated syntax `${}`, e.g. `${inputs.params.<name>}` will be supported
90-
until [#1170](https://github.com/tektoncd/pipeline/issues/1170)._
91-
9289
### Controlling where resources are mounted
9390

9491
The optional field `targetPath` can be used to initialize a resource in specific

docs/tasks.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,9 +400,6 @@ $(inputs.params.<name>)
400400

401401
Param values from resources can also be accessed using [variable substitution](./resources.md#variable-substitution)
402402

403-
_The deprecated syntax `${}`, e.g. `${inputs.params.<name>}` will be supported
404-
until [#1170](https://github.com/tektoncd/pipeline/issues/1170)._
405-
406403
#### Variable Substitution with Parameters of Type `Array`
407404

408405
Referenced parameters of type `array` will expand to insert the array elements in the reference string's spot.

pkg/apis/pipeline/v1alpha1/param_types_test.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -128,42 +128,6 @@ func TestArrayOrString_ApplyReplacements(t *testing.T) {
128128
arrayReplacements: map[string][]string{"arraykey": {}},
129129
},
130130
expectedOutput: builder.ArrayOrString("firstvalue", "lastvalue"),
131-
}, {
132-
// TODO(#1170): Remove support for ${} syntax
133-
name: "deprecated string replacements on string",
134-
args: args{
135-
input: builder.ArrayOrString("astring${some} asdf ${anotherkey}"),
136-
stringReplacements: map[string]string{"some": "value", "anotherkey": "value"},
137-
arrayReplacements: map[string][]string{"arraykey": {"array", "value"}, "sdfdf": {"asdf", "sdfsd"}},
138-
},
139-
expectedOutput: builder.ArrayOrString("astringvalue asdf value"),
140-
}, {
141-
// TODO(#1170): Remove support for ${} syntax
142-
name: "deprecated single array replacement",
143-
args: args{
144-
input: builder.ArrayOrString("firstvalue", "${arraykey}", "lastvalue"),
145-
stringReplacements: map[string]string{"some": "value", "anotherkey": "value"},
146-
arrayReplacements: map[string][]string{"arraykey": {"array", "value"}, "sdfdf": {"asdf", "sdfsd"}},
147-
},
148-
expectedOutput: builder.ArrayOrString("firstvalue", "array", "value", "lastvalue"),
149-
}, {
150-
// TODO(#1170): Remove support for ${} syntax
151-
name: "deprecated multiple array replacement",
152-
args: args{
153-
input: builder.ArrayOrString("firstvalue", "${arraykey}", "lastvalue", "${sdfdf}"),
154-
stringReplacements: map[string]string{"some": "value", "anotherkey": "value"},
155-
arrayReplacements: map[string][]string{"arraykey": {"array", "value"}, "sdfdf": {"asdf", "sdfsd"}},
156-
},
157-
expectedOutput: builder.ArrayOrString("firstvalue", "array", "value", "lastvalue", "asdf", "sdfsd"),
158-
}, {
159-
// TODO(#1170): Remove support for ${} syntax
160-
name: "deprecated empty array replacement",
161-
args: args{
162-
input: builder.ArrayOrString("firstvalue", "${arraykey}", "lastvalue"),
163-
stringReplacements: map[string]string{"some": "value", "anotherkey": "value"},
164-
arrayReplacements: map[string][]string{"arraykey": {}},
165-
},
166-
expectedOutput: builder.ArrayOrString("firstvalue", "lastvalue"),
167131
}}
168132
for _, tt := range tests {
169133
t.Run(tt.name, func(t *testing.T) {

pkg/apis/pipeline/v1alpha1/pipeline_validation_test.go

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -152,35 +152,6 @@ func TestPipelineSpec_Validate(t *testing.T) {
152152
tb.PipelineTaskParam("a-param", "$(input.workspace.$(baz))")),
153153
)),
154154
failureExpected: false,
155-
}, {
156-
// TODO(#1170): Remove support for ${} syntax
157-
name: "deprecated valid parameter variables",
158-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
159-
tb.PipelineParamSpec("baz", v1alpha1.ParamTypeString),
160-
tb.PipelineParamSpec("foo-is-baz", v1alpha1.ParamTypeString),
161-
tb.PipelineTask("bar", "bar-task",
162-
tb.PipelineTaskParam("a-param", "${baz} and ${foo-is-baz}")),
163-
)),
164-
failureExpected: false,
165-
}, {
166-
// TODO(#1170): Remove support for ${} syntax
167-
name: "deprecated valid array parameter variables",
168-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
169-
tb.PipelineParamSpec("baz", v1alpha1.ParamTypeArray, tb.ParamSpecDefault("some", "default")),
170-
tb.PipelineParamSpec("foo-is-baz", v1alpha1.ParamTypeArray),
171-
tb.PipelineTask("bar", "bar-task",
172-
tb.PipelineTaskParam("a-param", "${baz}", "and", "${foo-is-baz}")),
173-
)),
174-
failureExpected: false,
175-
}, {
176-
// TODO(#1170): Remove support for ${} syntax
177-
name: "deprecated pipeline parameter nested in task parameter",
178-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
179-
tb.PipelineParamSpec("baz", v1alpha1.ParamTypeString),
180-
tb.PipelineTask("bar", "bar-task",
181-
tb.PipelineTaskParam("a-param", "${input.workspace.${baz}}")),
182-
)),
183-
failureExpected: false,
184155
}, {
185156
name: "duplicate tasks",
186157
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
@@ -305,67 +276,6 @@ func TestPipelineSpec_Validate(t *testing.T) {
305276
tb.PipelineTaskParam("a-param", "first", "value: $(params.baz)", "last")),
306277
)),
307278
failureExpected: true,
308-
}, {
309-
// TODO(#1170): Remove support for ${} syntax
310-
name: "deprecated not defined parameter variable",
311-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
312-
tb.PipelineTask("foo", "foo-task",
313-
tb.PipelineTaskParam("a-param", "${params.does-not-exist}")))),
314-
failureExpected: true,
315-
}, {
316-
// TODO(#1170): Remove support for ${} syntax
317-
name: "not defined parameter variable with defined",
318-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
319-
tb.PipelineParamSpec("foo", v1alpha1.ParamTypeString, tb.ParamSpecDefault("something")),
320-
tb.PipelineTask("foo", "foo-task",
321-
tb.PipelineTaskParam("a-param", "${params.foo} and ${params.does-not-exist}")))),
322-
failureExpected: true,
323-
}, {
324-
// TODO(#1170): Remove support for ${} syntax
325-
name: "deprecated invalid parameter type",
326-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
327-
tb.PipelineParamSpec("baz", "invalidtype", tb.ParamSpecDefault("some", "default")),
328-
tb.PipelineParamSpec("foo-is-baz", v1alpha1.ParamTypeArray),
329-
tb.PipelineTask("bar", "bar-task",
330-
tb.PipelineTaskParam("a-param", "${baz}", "and", "${foo-is-baz}")),
331-
)),
332-
failureExpected: true,
333-
}, {
334-
// TODO(#1170): Remove support for ${} syntax
335-
name: "deprecated array parameter mismatching default type",
336-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
337-
tb.PipelineParamSpec("baz", v1alpha1.ParamTypeArray, tb.ParamSpecDefault("astring")),
338-
tb.PipelineTask("bar", "bar-task",
339-
tb.PipelineTaskParam("a-param", "arrayelement", "${baz}")),
340-
)),
341-
failureExpected: true,
342-
}, {
343-
// TODO(#1170): Remove support for ${} syntax
344-
name: "deprecated string parameter mismatching default type",
345-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
346-
tb.PipelineParamSpec("baz", v1alpha1.ParamTypeString, tb.ParamSpecDefault("anarray", "elements")),
347-
tb.PipelineTask("bar", "bar-task",
348-
tb.PipelineTaskParam("a-param", "arrayelement", "${baz}")),
349-
)),
350-
failureExpected: true,
351-
}, {
352-
// TODO(#1170): Remove support for ${} syntax
353-
name: "deprecated array parameter used as string",
354-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
355-
tb.PipelineParamSpec("baz", v1alpha1.ParamTypeArray, tb.ParamSpecDefault("anarray", "elements")),
356-
tb.PipelineTask("bar", "bar-task",
357-
tb.PipelineTaskParam("a-param", "${params.baz}")),
358-
)),
359-
failureExpected: true,
360-
}, {
361-
// TODO(#1170): Remove support for ${} syntax
362-
name: "deprecated array parameter string template not isolated",
363-
p: tb.Pipeline("pipeline", "namespace", tb.PipelineSpec(
364-
tb.PipelineParamSpec("baz", v1alpha1.ParamTypeArray, tb.ParamSpecDefault("anarray", "elements")),
365-
tb.PipelineTask("bar", "bar-task",
366-
tb.PipelineTaskParam("a-param", "first", "value: ${params.baz}", "last")),
367-
)),
368-
failureExpected: true,
369279
}, {
370280
name: "invalid dependency graph between the tasks",
371281
p: tb.Pipeline("foo", "namespace", tb.PipelineSpec(

pkg/apis/pipeline/v1alpha1/step_replacements_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,45 @@ func TestApplyStepReplacements(t *testing.T) {
3434
}
3535

3636
s := v1alpha1.Step{Container: corev1.Container{
37-
Name: "${replace.me}",
38-
Image: "${replace.me}",
39-
Command: []string{"${array.replace.me}"},
40-
Args: []string{"${array.replace.me}"},
41-
WorkingDir: "${replace.me}",
37+
Name: "$(replace.me)",
38+
Image: "$(replace.me)",
39+
Command: []string{"$(array.replace.me)"},
40+
Args: []string{"$(array.replace.me)"},
41+
WorkingDir: "$(replace.me)",
4242
EnvFrom: []corev1.EnvFromSource{{
4343
ConfigMapRef: &corev1.ConfigMapEnvSource{
4444
LocalObjectReference: corev1.LocalObjectReference{
45-
Name: "${replace.me}",
45+
Name: "$(replace.me)",
4646
},
4747
},
4848
SecretRef: &corev1.SecretEnvSource{
4949
LocalObjectReference: corev1.LocalObjectReference{
50-
Name: "${replace.me}",
50+
Name: "$(replace.me)",
5151
},
5252
},
5353
}},
5454
Env: []corev1.EnvVar{{
5555
Name: "not_me",
56-
Value: "${replace.me}",
56+
Value: "$(replace.me)",
5757
ValueFrom: &corev1.EnvVarSource{
5858
ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
5959
LocalObjectReference: corev1.LocalObjectReference{
60-
Name: "${replace.me}",
60+
Name: "$(replace.me)",
6161
},
62-
Key: "${replace.me}",
62+
Key: "$(replace.me)",
6363
},
6464
SecretKeyRef: &corev1.SecretKeySelector{
6565
LocalObjectReference: corev1.LocalObjectReference{
66-
Name: "${replace.me}",
66+
Name: "$(replace.me)",
6767
},
68-
Key: "${replace.me}",
68+
Key: "$(replace.me)",
6969
},
7070
},
7171
}},
7272
VolumeMounts: []corev1.VolumeMount{{
73-
Name: "${replace.me}",
74-
MountPath: "${replace.me}",
75-
SubPath: "${replace.me}",
73+
Name: "$(replace.me)",
74+
MountPath: "$(replace.me)",
75+
SubPath: "$(replace.me)",
7676
}},
7777
}}
7878

@@ -126,7 +126,7 @@ func TestApplyStepReplacements(t *testing.T) {
126126

127127
func TestApplyStepReplacements_NotDefined(t *testing.T) {
128128
s := v1alpha1.Step{Container: corev1.Container{
129-
Name: "${params.not.defined}",
129+
Name: "$(params.not.defined)",
130130
}}
131131
replacements := map[string]string{
132132
"replace.me": "replaced!",
@@ -137,7 +137,7 @@ func TestApplyStepReplacements_NotDefined(t *testing.T) {
137137
}
138138

139139
expected := v1alpha1.Step{Container: corev1.Container{
140-
Name: "${params.not.defined}",
140+
Name: "$(params.not.defined)",
141141
}}
142142
v1alpha1.ApplyStepReplacements(&s, replacements, arrayReplacements)
143143
if d := cmp.Diff(s, expected); d != "" {

pkg/apis/pipeline/v1alpha1/substitution.go

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import (
2626

2727
const parameterSubstitution = "[_a-zA-Z][_a-zA-Z0-9.-]*"
2828

29-
//TODO(#1170): Regex matches both ${} and $(), we will need to remove ${} compatibility.
30-
const braceMatchingRegex = "(\\$({%s.(?P<deprecated>%s)}))|(\\$(\\(%s.(?P<var>%s)\\)))"
29+
const braceMatchingRegex = "(\\$(\\(%s.(?P<var>%s)\\)))"
3130

3231
func ValidateVariable(name, value, prefix, contextPrefix, locationName, path string, vars map[string]struct{}) *apis.FieldError {
3332
if vs, present := extractVariablesFromString(value, contextPrefix+prefix); present {
@@ -76,10 +75,10 @@ func ValidateVariableIsolated(name, value, prefix, contextPrefix, locationName,
7675
return nil
7776
}
7877

79-
// Extract a the first full string expressions found (e.g "${input.params.foo}"). Return
78+
// Extract a the first full string expressions found (e.g "$(input.params.foo)"). Return
8079
// "" and false if nothing is found.
8180
func extractExpressionFromString(s, prefix string) (string, bool) {
82-
pattern := fmt.Sprintf(braceMatchingRegex, prefix, parameterSubstitution, prefix, parameterSubstitution)
81+
pattern := fmt.Sprintf(braceMatchingRegex, prefix, parameterSubstitution)
8382
re := regexp.MustCompile(pattern)
8483
match := re.FindStringSubmatch(s)
8584
if match == nil {
@@ -89,7 +88,7 @@ func extractExpressionFromString(s, prefix string) (string, bool) {
8988
}
9089

9190
func extractVariablesFromString(s, prefix string) ([]string, bool) {
92-
pattern := fmt.Sprintf(braceMatchingRegex, prefix, parameterSubstitution, prefix, parameterSubstitution)
91+
pattern := fmt.Sprintf(braceMatchingRegex, prefix, parameterSubstitution)
9392
re := regexp.MustCompile(pattern)
9493
matches := re.FindAllStringSubmatch(s, -1)
9594
if len(matches) == 0 {
@@ -101,14 +100,7 @@ func extractVariablesFromString(s, prefix string) ([]string, bool) {
101100
// foo -> foo
102101
// foo.bar -> foo
103102
// foo.bar.baz -> foo
104-
var v string
105-
if groups["var"] != "" {
106-
v = groups["var"]
107-
} else {
108-
//TODO(#1170): Regex matches both ${} and $(), we will need to remove ${} compatibility.
109-
v = groups["deprecated"]
110-
}
111-
vars[i] = strings.SplitN(v, ".", 2)[0]
103+
vars[i] = strings.SplitN(groups["var"], ".", 2)[0]
112104
}
113105
return vars, true
114106
}
@@ -124,9 +116,6 @@ func matchGroups(matches []string, pattern *regexp.Regexp) map[string]string {
124116
func ApplyReplacements(in string, replacements map[string]string) string {
125117
for k, v := range replacements {
126118
in = strings.Replace(in, fmt.Sprintf("$(%s)", k), v, -1)
127-
128-
//TODO(#1170): Delete the line below when we want to remove support for ${} variable interpolation:
129-
in = strings.Replace(in, fmt.Sprintf("${%s}", k), v, -1)
130119
}
131120
return in
132121
}
@@ -143,12 +132,6 @@ func ApplyArrayReplacements(in string, stringReplacements map[string]string, arr
143132
if (strings.Count(in, stringToReplace) == 1) && len(in) == len(stringToReplace) {
144133
return v
145134
}
146-
147-
//TODO(#1170): Delete the block below when we want to remove support for ${} variable interpolation:
148-
deprecatedStringToReplace := fmt.Sprintf("${%s}", k)
149-
if (strings.Count(in, deprecatedStringToReplace) == 1) && len(in) == len(deprecatedStringToReplace) {
150-
return v
151-
}
152135
}
153136

154137
// Otherwise return a size-1 array containing the input string with standard stringReplacements applied.

0 commit comments

Comments
 (0)