Skip to content

Commit

Permalink
Merge branch 'tektoncd:main' into fix/compute-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Ccheers authored Jan 29, 2025
2 parents b841c30 + cef86d1 commit b925e07
Show file tree
Hide file tree
Showing 58 changed files with 2,519 additions and 270 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
uses: github/codeql-action/init@f6091c0113d1dcf9b98e269ee48e8a7e51b7bdd4 # v3.28.5
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand Down Expand Up @@ -96,4 +96,4 @@ jobs:
make -j 4 all
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
uses: github/codeql-action/analyze@f6091c0113d1dcf9b98e269ee48e8a7e51b7bdd4 # v3.28.5
2 changes: 1 addition & 1 deletion .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3.28.1
uses: github/codeql-action/upload-sarif@f6091c0113d1dcf9b98e269ee48e8a7e51b7bdd4 # v3.28.5
with:
sarif_file: results.sarif
15 changes: 15 additions & 0 deletions docs/stepactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ spec:

**Note:** If a `Step` declares `params` for an `inlined Step`, it will also lead to a validation error. This is because an `inlined Step` gets its `params` from the `TaskRun`.

#### Parameter Substitution Precedence

When applying parameters to a StepAction, the substitutions are applied in the following order:

1. TaskRun parameter values in step parameters
2. Parameters from StepAction defaults
3. Parameters from the step (overwriting any defaults)
4. Step result replacements

This order ensures that:
- Step parameters can reference TaskRun parameters
- StepAction defaults provide fallback values
- Step-specific parameters take precedence over defaults
- Step result references are resolved last to allow referencing results from previous steps

### Emitting Results

A `StepAction` also declares the results that it will emit.
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/ahmetb/gen-crd-api-reference-docs v0.3.1-0.20220720053627-e327d0730470 // Waiting for /~https://github.com/ahmetb/gen-crd-api-reference-docs/pull/43/files to merge
github.com/cloudevents/sdk-go/v2 v2.15.2
github.com/containerd/containerd v1.7.25
github.com/go-git/go-git/v5 v5.13.1
github.com/go-git/go-git/v5 v5.13.2
github.com/google/go-cmp v0.6.0
github.com/google/go-containerregistry v0.20.2
github.com/google/uuid v1.6.0
Expand Down Expand Up @@ -57,7 +57,7 @@ require (
)

require (
github.com/ProtonMail/go-crypto v1.1.3 // indirect
github.com/ProtonMail/go-crypto v1.1.5 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.6.2
Expand All @@ -69,7 +69,7 @@ require (
)

require (
cel.dev/expr v0.18.0 // indirect
cel.dev/expr v0.19.0 // indirect
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/auth v0.13.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
Expand Down Expand Up @@ -122,7 +122,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pjbgf/sha1cd v0.3.2 // indirect
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.9.0 // indirect
Expand Down Expand Up @@ -240,8 +240,8 @@ require (
golang.org/x/tools v0.23.0 // indirect
google.golang.org/api v0.214.0 // indirect
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
google.golang.org/grpc v1.69.4
google.golang.org/protobuf v1.36.3
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.36.4
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
32 changes: 16 additions & 16 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 34 additions & 17 deletions pkg/reconciler/taskrun/resources/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,22 @@ var (
}
)

// applyStepActionParameters applies the params from the Task and the underlying Step to the referenced StepAction.
// applyStepActionParameters applies the params from the task and the underlying step to the referenced stepaction.
// substitution order:
// 1. taskrun parameter values in step parameters
// 2. set params from StepAction defaults
// 3. set and overwrite params with the ones from the step
// 4. set step result replacements last
func applyStepActionParameters(step *v1.Step, spec *v1.TaskSpec, tr *v1.TaskRun, stepParams v1.Params, defaults []v1.ParamSpec) (*v1.Step, error) {
// 1. taskrun parameter substitutions to step parameters
if stepParams != nil {
stringR, arrayR, objectR := getTaskParameters(spec, tr, spec.Params...)
stepParams = stepParams.ReplaceVariables(stringR, arrayR, objectR)
}
// Set params from StepAction defaults
// 2. set params from stepaction defaults
stringReplacements, arrayReplacements, _ := replacementsFromDefaultParams(defaults)

// Set and overwrite params with the ones from the Step
// 3. set and overwrite params with the ones from the step
stepStrings, stepArrays, _ := replacementsFromParams(stepParams)
for k, v := range stepStrings {
stringReplacements[k] = v
Expand All @@ -84,16 +90,19 @@ func applyStepActionParameters(step *v1.Step, spec *v1.TaskSpec, tr *v1.TaskRun,
arrayReplacements[k] = v
}

stepResultReplacements, _ := replacementsFromStepResults(step, stepParams, defaults)
for k, v := range stepResultReplacements {
stringReplacements[k] = v
// 4. set step result replacements last
if stepResultReplacements, err := replacementsFromStepResults(step, stepParams, defaults); err != nil {
return nil, err
} else {
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
// 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 {
if err := checkForDuplicateKeys(stringReplacements, arrayReplacements); err != nil {
return nil, err
}

Expand Down Expand Up @@ -165,8 +174,9 @@ func replacementsArrayIdxStepResults(step *v1.Step, paramName string, stepName s
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)
if sp.Value.StringVal != "" && strings.HasPrefix(sp.Value.StringVal, "$(steps.") {
// eg: when parameter p1 references a step result, replace:
// $(params.p1) with $(steps.step1.results.foo)
value := strings.TrimSuffix(strings.TrimPrefix(sp.Value.StringVal, "$("), ")")
pr, err := resultref.ParseStepExpression(value)
if err != nil {
Expand All @@ -180,19 +190,26 @@ func replacementsFromStepResults(step *v1.Step, stepParams v1.Params, defaults [
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)
// with star notation, replace:
// $(params.p1[*]) with $(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])
// with index notation, replace:
// $(params.p1[idx]) with $(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.
fallthrough
default:
// for string parameters and default case,
// replace any reference to the parameter with the step result reference
// since both use simple value substitution
// eg: replace $(params.p1) with $(steps.step1.results.foo)
for _, pattern := range paramPatterns {
stringReplacements[fmt.Sprintf(pattern, d.Name)] = sp.Value.StringVal
}
}
}
}
Expand Down
Loading

0 comments on commit b925e07

Please sign in to comment.