-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathapply.go
561 lines (506 loc) · 22.2 KB
/
apply.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
/*
Copyright 2019 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package resources
import (
"context"
"fmt"
"path/filepath"
"regexp"
"sort"
"strconv"
"strings"
"github.com/tektoncd/pipeline/internal/artifactref"
"github.com/tektoncd/pipeline/pkg/apis/pipeline"
v1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/container"
"github.com/tektoncd/pipeline/pkg/internal/resultref"
"github.com/tektoncd/pipeline/pkg/pod"
"github.com/tektoncd/pipeline/pkg/substitution"
"github.com/tektoncd/pipeline/pkg/workspace"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
)
const (
// objectIndividualVariablePattern is the reference pattern for object individual keys params.<object_param_name>.<key_name>
objectIndividualVariablePattern = "params.%s.%s"
)
var (
paramPatterns = []string{
"params.%s",
"params[%q]",
"params['%s']",
// FIXME(vdemeester) Remove that with deprecating v1beta1
"inputs.params.%s",
}
substitutionToParamNamePatterns = []string{
`^params\.(\w+)$`,
`^params\["([^"]+)"\]$`,
`^params\['([^']+)'\]$`,
// FIXME(vdemeester) Remove that with deprecating v1beta1
`^inputs\.params\.(\w+)$`,
}
paramIndexRegexPatterns = []string{
`\$\(params.%s\[([0-9]*)*\*?\]\)`,
`\$\(params\[%q\]\[([0-9]*)*\*?\]\)`,
`\$\(params\['%s'\]\[([0-9]*)*\*?\]\)`,
}
)
// applyStepActionParameters applies the params from the Task and the underlying Step to the referenced StepAction.
func applyStepActionParameters(step *v1.Step, spec *v1.TaskSpec, tr *v1.TaskRun, stepParams v1.Params, defaults []v1.ParamSpec) (*v1.Step, error) {
if stepParams != nil {
stringR, arrayR, objectR := getTaskParameters(spec, tr, spec.Params...)
stepParams = stepParams.ReplaceVariables(stringR, arrayR, objectR)
}
// Set params from StepAction defaults
stringReplacements, arrayReplacements, _ := replacementsFromDefaultParams(defaults)
// Set and overwrite params with the ones from the Step
stepStrings, stepArrays, _ := replacementsFromParams(stepParams)
for k, v := range stepStrings {
stringReplacements[k] = v
}
for k, v := range stepArrays {
arrayReplacements[k] = v
}
stepResultReplacements, _ := replacementsFromStepResults(step, stepParams, defaults)
for k, v := range stepResultReplacements {
stringReplacements[k] = v
}
// Check if there are duplicate keys in the replacements
// If the same key is present in both stringReplacements and arrayReplacements, it means
// that the default value and the passed value have different types.
err := checkForDuplicateKeys(stringReplacements, arrayReplacements)
if err != nil {
return nil, err
}
container.ApplyStepReplacements(step, stringReplacements, arrayReplacements)
return step, nil
}
// checkForDuplicateKeys checks if there are duplicate keys in the replacements
func checkForDuplicateKeys(stringReplacements map[string]string, arrayReplacements map[string][]string) error {
keys := make([]string, 0, len(stringReplacements))
for k := range stringReplacements {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
if _, ok := arrayReplacements[k]; ok {
paramName := paramNameFromReplacementKey(k)
return fmt.Errorf("invalid parameter substitution: %s. Please check the types of the default value and the passed value", paramName)
}
}
return nil
}
// paramNameFromReplacementKey returns the param name from the replacement key in best effort
func paramNameFromReplacementKey(key string) string {
for _, regexPattern := range substitutionToParamNamePatterns {
re := regexp.MustCompile(regexPattern)
if matches := re.FindStringSubmatch(key); matches != nil {
return matches[1]
}
}
// If no match is found, return the key
return key
}
// findArrayIndexParamUsage finds the array index in a string using array param substitution
func findArrayIndexParamUsage(s string, paramName string, stepName string, resultName string, stringReplacements map[string]string) map[string]string {
for _, pattern := range paramIndexRegexPatterns {
arrayIndexingRegex := regexp.MustCompile(fmt.Sprintf(pattern, paramName))
matches := arrayIndexingRegex.FindAllStringSubmatch(s, -1)
for _, match := range matches {
if len(match) == 2 {
key := strings.TrimSuffix(strings.TrimPrefix(match[0], "$("), ")")
if match[1] != "" {
stringReplacements[key] = fmt.Sprintf("$(steps.%s.results.%s[%s])", stepName, resultName, match[1])
}
}
}
}
return stringReplacements
}
// replacementsArrayIdxStepResults looks for Step Result array usage with index in the Step's command, args, env and script.
func replacementsArrayIdxStepResults(step *v1.Step, paramName string, stepName string, resultName string) map[string]string {
stringReplacements := map[string]string{}
for _, c := range step.Command {
stringReplacements = findArrayIndexParamUsage(c, paramName, stepName, resultName, stringReplacements)
}
for _, a := range step.Args {
stringReplacements = findArrayIndexParamUsage(a, paramName, stepName, resultName, stringReplacements)
}
for _, e := range step.Env {
stringReplacements = findArrayIndexParamUsage(e.Value, paramName, stepName, resultName, stringReplacements)
}
return stringReplacements
}
// replacementsFromStepResults generates string replacements for params whose values is a variable substitution of a step result.
func replacementsFromStepResults(step *v1.Step, stepParams v1.Params, defaults []v1.ParamSpec) (map[string]string, error) {
stringReplacements := map[string]string{}
for _, sp := range stepParams {
if sp.Value.StringVal != "" {
// $(params.p1) --> $(steps.step1.results.foo) (normal substitution)
value := strings.TrimSuffix(strings.TrimPrefix(sp.Value.StringVal, "$("), ")")
pr, err := resultref.ParseStepExpression(value)
if err != nil {
return nil, err
}
for _, d := range defaults {
if d.Name == sp.Name {
switch d.Type {
case v1.ParamTypeObject:
for k := range d.Properties {
stringReplacements[fmt.Sprintf("params.%s.%s", d.Name, k)] = fmt.Sprintf("$(steps.%s.results.%s.%s)", pr.ResourceName, pr.ResultName, k)
}
case v1.ParamTypeArray:
// $(params.p1[*]) --> $(steps.step1.results.foo)
for _, pattern := range paramPatterns {
stringReplacements[fmt.Sprintf(pattern+"[*]", d.Name)] = fmt.Sprintf("$(steps.%s.results.%s[*])", pr.ResourceName, pr.ResultName)
}
// $(params.p1[idx]) --> $(steps.step1.results.foo[idx])
for k, v := range replacementsArrayIdxStepResults(step, d.Name, pr.ResourceName, pr.ResultName) {
stringReplacements[k] = v
}
// This is handled by normal param substitution.
// $(params.p1.key) --> $(steps.step1.results.foo)
case v1.ParamTypeString:
// Since String is the default, This is handled by normal param substitution.
default:
}
}
}
}
}
return stringReplacements, nil
}
// getTaskParameters gets the string, array and object parameter variable replacements needed in the Task
func getTaskParameters(spec *v1.TaskSpec, tr *v1.TaskRun, defaults ...v1.ParamSpec) (map[string]string, map[string][]string, map[string]map[string]string) {
// This assumes that the TaskRun inputs have been validated against what the Task requests.
// Set params from Task defaults
stringReplacements, arrayReplacements, objectReplacements := replacementsFromDefaultParams(defaults)
// Set and overwrite params with the ones from the TaskRun
trStrings, trArrays, trObjects := replacementsFromParams(tr.Spec.Params)
for k, v := range trStrings {
stringReplacements[k] = v
}
for k, v := range trArrays {
arrayReplacements[k] = v
}
for k, v := range trObjects {
for key, val := range v {
if objectReplacements != nil {
if objectReplacements[k] != nil {
objectReplacements[k][key] = val
} else {
objectReplacements[k] = v
}
}
}
}
return stringReplacements, arrayReplacements, objectReplacements
}
// ApplyParameters applies the params from a TaskRun.Parameters to a TaskSpec
func ApplyParameters(spec *v1.TaskSpec, tr *v1.TaskRun, defaults ...v1.ParamSpec) *v1.TaskSpec {
stringReplacements, arrayReplacements, objectReplacements := getTaskParameters(spec, tr, defaults...)
return ApplyReplacements(spec, stringReplacements, arrayReplacements, objectReplacements)
}
func replacementsFromDefaultParams(defaults v1.ParamSpecs) (map[string]string, map[string][]string, map[string]map[string]string) {
stringReplacements := map[string]string{}
arrayReplacements := map[string][]string{}
objectReplacements := map[string]map[string]string{}
// Set all the default stringReplacements
for _, p := range defaults {
if p.Default != nil {
switch p.Default.Type {
case v1.ParamTypeArray:
for _, pattern := range paramPatterns {
for i := range len(p.Default.ArrayVal) {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Default.ArrayVal[i]
}
arrayReplacements[fmt.Sprintf(pattern, p.Name)] = p.Default.ArrayVal
}
case v1.ParamTypeObject:
for _, pattern := range paramPatterns {
objectReplacements[fmt.Sprintf(pattern, p.Name)] = p.Default.ObjectVal
}
for k, v := range p.Default.ObjectVal {
stringReplacements[fmt.Sprintf(objectIndividualVariablePattern, p.Name, k)] = v
}
case v1.ParamTypeString:
fallthrough
default:
for _, pattern := range paramPatterns {
stringReplacements[fmt.Sprintf(pattern, p.Name)] = p.Default.StringVal
}
}
}
}
return stringReplacements, arrayReplacements, objectReplacements
}
func replacementsFromParams(params v1.Params) (map[string]string, map[string][]string, map[string]map[string]string) {
// stringReplacements is used for standard single-string stringReplacements, while arrayReplacements contains arrays
// and objectReplacements contains objects that need to be further processed.
stringReplacements := map[string]string{}
arrayReplacements := map[string][]string{}
objectReplacements := map[string]map[string]string{}
for _, p := range params {
switch p.Value.Type {
case v1.ParamTypeArray:
for _, pattern := range paramPatterns {
for i := range len(p.Value.ArrayVal) {
stringReplacements[fmt.Sprintf(pattern+"[%d]", p.Name, i)] = p.Value.ArrayVal[i]
}
arrayReplacements[fmt.Sprintf(pattern, p.Name)] = p.Value.ArrayVal
}
case v1.ParamTypeObject:
for _, pattern := range paramPatterns {
objectReplacements[fmt.Sprintf(pattern, p.Name)] = p.Value.ObjectVal
}
for k, v := range p.Value.ObjectVal {
stringReplacements[fmt.Sprintf(objectIndividualVariablePattern, p.Name, k)] = v
}
case v1.ParamTypeString:
fallthrough
default:
for _, pattern := range paramPatterns {
stringReplacements[fmt.Sprintf(pattern, p.Name)] = p.Value.StringVal
}
}
}
return stringReplacements, arrayReplacements, objectReplacements
}
func getContextReplacements(taskName string, tr *v1.TaskRun) map[string]string {
return map[string]string{
"context.taskRun.name": tr.Name,
"context.task.name": taskName,
"context.taskRun.namespace": tr.Namespace,
"context.taskRun.uid": string(tr.ObjectMeta.UID),
"context.task.retry-count": strconv.Itoa(len(tr.Status.RetriesStatus)),
}
}
// ApplyContexts applies the substitution from $(context.(taskRun|task).*) with the specified values.
// Uses "" as a default if a value is not available.
func ApplyContexts(spec *v1.TaskSpec, taskName string, tr *v1.TaskRun) *v1.TaskSpec {
return ApplyReplacements(spec, getContextReplacements(taskName, tr), map[string][]string{}, map[string]map[string]string{})
}
// ApplyWorkspaces applies the substitution from paths that the workspaces in declarations mounted to, the
// volumes that bindings are realized with in the task spec and the PersistentVolumeClaim names for the
// workspaces.
func ApplyWorkspaces(ctx context.Context, spec *v1.TaskSpec, declarations []v1.WorkspaceDeclaration, bindings []v1.WorkspaceBinding, vols map[string]corev1.Volume) *v1.TaskSpec {
stringReplacements := map[string]string{}
bindNames := sets.NewString()
for _, binding := range bindings {
bindNames.Insert(binding.Name)
}
for _, declaration := range declarations {
prefix := fmt.Sprintf("workspaces.%s.", declaration.Name)
if declaration.Optional && !bindNames.Has(declaration.Name) {
stringReplacements[prefix+"bound"] = "false"
stringReplacements[prefix+"path"] = ""
} else {
stringReplacements[prefix+"bound"] = "true"
spec = applyWorkspaceMountPath(prefix+"path", spec, declaration)
}
}
for name, vol := range vols {
stringReplacements[fmt.Sprintf("workspaces.%s.volume", name)] = vol.Name
}
for _, binding := range bindings {
if binding.PersistentVolumeClaim != nil {
stringReplacements[fmt.Sprintf("workspaces.%s.claim", binding.Name)] = binding.PersistentVolumeClaim.ClaimName
} else {
stringReplacements[fmt.Sprintf("workspaces.%s.claim", binding.Name)] = ""
}
}
return ApplyReplacements(spec, stringReplacements, map[string][]string{}, map[string]map[string]string{})
}
// ApplyParametersToWorkspaceBindings applies parameters to the WorkspaceBindings of a TaskRun. It takes a TaskSpec and a TaskRun as input and returns the modified TaskRun.
func ApplyParametersToWorkspaceBindings(ts *v1.TaskSpec, tr *v1.TaskRun) *v1.TaskRun {
tsCopy := ts.DeepCopy()
parameters, _, _ := getTaskParameters(tsCopy, tr, tsCopy.Params...)
tr.Spec.Workspaces = workspace.ReplaceWorkspaceBindingsVars(tr.Spec.Workspaces, parameters)
return tr
}
// applyWorkspaceMountPath accepts a workspace path variable of the form $(workspaces.foo.path) and replaces
// it in the fields of the TaskSpec. A new updated TaskSpec is returned. Steps or Sidecars in the TaskSpec
// that override the mountPath will receive that mountPath in place of the variable's value. Other Steps and
// Sidecars will see either the workspace's declared mountPath or the default of /workspaces/<name>.
func applyWorkspaceMountPath(variable string, spec *v1.TaskSpec, declaration v1.WorkspaceDeclaration) *v1.TaskSpec {
stringReplacements := map[string]string{variable: ""}
emptyArrayReplacements := map[string][]string{}
defaultMountPath := declaration.GetMountPath()
// Replace instances of the workspace path variable that are overridden per-Step
for i := range spec.Steps {
step := &spec.Steps[i]
for _, usage := range step.Workspaces {
if usage.Name == declaration.Name && usage.MountPath != "" {
stringReplacements[variable] = usage.MountPath
container.ApplyStepReplacements(step, stringReplacements, emptyArrayReplacements)
}
}
}
// Replace instances of the workspace path variable that are overridden per-Sidecar
for i := range spec.Sidecars {
sidecar := &spec.Sidecars[i]
for _, usage := range sidecar.Workspaces {
if usage.Name == declaration.Name && usage.MountPath != "" {
stringReplacements[variable] = usage.MountPath
container.ApplySidecarReplacements(sidecar, stringReplacements, emptyArrayReplacements)
}
}
}
// Replace any remaining instances of the workspace path variable, which should fall
// back to the mount path specified in the declaration.
stringReplacements[variable] = defaultMountPath
return ApplyReplacements(spec, stringReplacements, emptyArrayReplacements, map[string]map[string]string{})
}
// ApplyResults applies the substitution from values in results and step results which are referenced in spec as subitems
// of the replacementStr.
func ApplyResults(spec *v1.TaskSpec) *v1.TaskSpec {
// Apply all the Step Result replacements
for i := range spec.Steps {
stringReplacements := getStepResultReplacements(spec.Steps[i], i)
container.ApplyStepReplacements(&spec.Steps[i], stringReplacements, map[string][]string{})
}
stringReplacements := getTaskResultReplacements(spec)
return ApplyReplacements(spec, stringReplacements, map[string][]string{}, map[string]map[string]string{})
}
// getStepResultReplacements creates all combinations of string replacements from Step Results.
func getStepResultReplacements(step v1.Step, idx int) map[string]string {
stringReplacements := map[string]string{}
patterns := []string{
"step.results.%s.path",
"step.results[%q].path",
"step.results['%s'].path",
}
stepName := pod.StepName(step.Name, idx)
for _, result := range step.Results {
for _, pattern := range patterns {
stringReplacements[fmt.Sprintf(pattern, result.Name)] = filepath.Join(pipeline.StepsDir, stepName, "results", result.Name)
}
}
return stringReplacements
}
// getTaskResultReplacements creates all combinations of string replacements from TaskResults.
func getTaskResultReplacements(spec *v1.TaskSpec) map[string]string {
stringReplacements := map[string]string{}
patterns := []string{
"results.%s.path",
"results[%q].path",
"results['%s'].path",
}
for _, result := range spec.Results {
for _, pattern := range patterns {
stringReplacements[fmt.Sprintf(pattern, result.Name)] = filepath.Join(pipeline.DefaultResultPath, result.Name)
}
}
return stringReplacements
}
// ApplyArtifacts replaces the occurrences of artifacts.path and step.artifacts.path with the absolute tekton internal path
func ApplyArtifacts(spec *v1.TaskSpec) *v1.TaskSpec {
for i := range spec.Steps {
stringReplacements := getArtifactReplacements(spec.Steps[i], i)
container.ApplyStepReplacements(&spec.Steps[i], stringReplacements, map[string][]string{})
}
return spec
}
func getArtifactReplacements(step v1.Step, idx int) map[string]string {
stringReplacements := map[string]string{}
stepName := pod.StepName(step.Name, idx)
stringReplacements[artifactref.StepArtifactPathPattern] = filepath.Join(pipeline.StepsDir, stepName, "artifacts", "provenance.json")
stringReplacements[artifactref.TaskArtifactPathPattern] = filepath.Join(pipeline.ArtifactsDir, "provenance.json")
return stringReplacements
}
// ApplyStepExitCodePath replaces the occurrences of exitCode path with the absolute tekton internal path
// Replace $(steps.<step-name>.exitCode.path) with pipeline.StepPath/<step-name>/exitCode
func ApplyStepExitCodePath(spec *v1.TaskSpec) *v1.TaskSpec {
stringReplacements := map[string]string{}
for i, step := range spec.Steps {
stringReplacements[fmt.Sprintf("steps.%s.exitCode.path", pod.StepName(step.Name, i))] = filepath.Join(pipeline.StepsDir, pod.StepName(step.Name, i), "exitCode")
}
return ApplyReplacements(spec, stringReplacements, map[string][]string{}, map[string]map[string]string{})
}
// ApplyCredentialsPath applies a substitution of the key $(credentials.path) with the path that credentials
// from annotated secrets are written to.
func ApplyCredentialsPath(spec *v1.TaskSpec, path string) *v1.TaskSpec {
stringReplacements := map[string]string{
"credentials.path": path,
}
return ApplyReplacements(spec, stringReplacements, map[string][]string{}, map[string]map[string]string{})
}
// ApplyReplacements replaces placeholders for declared parameters with the specified replacements.
func ApplyReplacements(spec *v1.TaskSpec, stringReplacements map[string]string, arrayReplacements map[string][]string, objectReplacements map[string]map[string]string) *v1.TaskSpec {
spec = spec.DeepCopy()
// Apply variable expansion to steps fields.
steps := spec.Steps
for i := range steps {
if steps[i].Params != nil {
steps[i].Params = steps[i].Params.ReplaceVariables(stringReplacements, arrayReplacements, objectReplacements)
}
container.ApplyStepReplacements(&steps[i], stringReplacements, arrayReplacements)
}
// Apply variable expansion to stepTemplate fields.
if spec.StepTemplate != nil {
container.ApplyStepTemplateReplacements(spec.StepTemplate, stringReplacements, arrayReplacements)
}
// Apply variable expansion to the build's volumes
for i, v := range spec.Volumes {
spec.Volumes[i].Name = substitution.ApplyReplacements(v.Name, stringReplacements)
if v.VolumeSource.ConfigMap != nil {
spec.Volumes[i].ConfigMap.Name = substitution.ApplyReplacements(v.ConfigMap.Name, stringReplacements)
for index, item := range v.ConfigMap.Items {
spec.Volumes[i].ConfigMap.Items[index].Key = substitution.ApplyReplacements(item.Key, stringReplacements)
spec.Volumes[i].ConfigMap.Items[index].Path = substitution.ApplyReplacements(item.Path, stringReplacements)
}
}
if v.VolumeSource.Secret != nil {
spec.Volumes[i].Secret.SecretName = substitution.ApplyReplacements(v.Secret.SecretName, stringReplacements)
for index, item := range v.Secret.Items {
spec.Volumes[i].Secret.Items[index].Key = substitution.ApplyReplacements(item.Key, stringReplacements)
spec.Volumes[i].Secret.Items[index].Path = substitution.ApplyReplacements(item.Path, stringReplacements)
}
}
if v.PersistentVolumeClaim != nil {
spec.Volumes[i].PersistentVolumeClaim.ClaimName = substitution.ApplyReplacements(v.PersistentVolumeClaim.ClaimName, stringReplacements)
}
if v.Projected != nil {
for _, s := range spec.Volumes[i].Projected.Sources {
if s.ConfigMap != nil {
s.ConfigMap.Name = substitution.ApplyReplacements(s.ConfigMap.Name, stringReplacements)
}
if s.Secret != nil {
s.Secret.Name = substitution.ApplyReplacements(s.Secret.Name, stringReplacements)
}
if s.ServiceAccountToken != nil {
s.ServiceAccountToken.Audience = substitution.ApplyReplacements(s.ServiceAccountToken.Audience, stringReplacements)
}
}
}
if v.CSI != nil {
if v.CSI.NodePublishSecretRef != nil {
spec.Volumes[i].CSI.NodePublishSecretRef.Name = substitution.ApplyReplacements(v.CSI.NodePublishSecretRef.Name, stringReplacements)
}
if v.CSI.VolumeAttributes != nil {
for key, value := range v.CSI.VolumeAttributes {
spec.Volumes[i].CSI.VolumeAttributes[key] = substitution.ApplyReplacements(value, stringReplacements)
}
}
}
}
for i, v := range spec.Workspaces {
spec.Workspaces[i].MountPath = substitution.ApplyReplacements(v.MountPath, stringReplacements)
}
// Apply variable substitution to the sidecar definitions
sidecars := spec.Sidecars
for i := range sidecars {
container.ApplySidecarReplacements(&sidecars[i], stringReplacements, arrayReplacements)
}
return spec
}