Skip to content

Commit e48f5d1

Browse files
committed
feat: resolve steps referencing StepActions in parallel
Avoids unnecessary DeepCopy operations on steps that do not reference a StepAction. Introduces parallel resolution of steps that reference StepActions to improve the performance of TaskRun reconciliation, especially when using remote resolvers like git. The key changes include: - `hasStepRefs` function: A new function that quickly checks if a `TaskSpec` contains any steps referencing `StepActions`. This allows for an early exit if no resolution is needed, avoiding unnecessary work. - `resolveStepRef` function: This new function encapsulates the logic for resolving a single `StepAction` reference. It handles fetching the remote resource, merging the `StepAction` with the step's specification, and returning the resolved step - Two-phase resolution: The `GetStepActionsData` function is now split into two distinct phases: - Concurrent Resolution: All `StepAction` references are resolved in parallel using an `errgroup`. - Sequential Merging: The resolved steps and their provenance are merged into the final step list and the `TaskRun` status sequentially. - `updateTaskRunProvenance` function: A dedicated function for updating the TaskRun's status with provenance information. The maximum number of StepActions that can be resolved in parallel is defined by the default config and its `default-step-action-parallelism-limit` key.
1 parent 85152e4 commit e48f5d1

File tree

11 files changed

+460
-141
lines changed

11 files changed

+460
-141
lines changed

config/config-defaults.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,6 @@ data:
157157
# This value is used by the sidecar-tekton-log-results container and can be tuned for performance or test scenarios.
158158
# Example values: "100ms", "500ms", "1s"
159159
default-sidecar-log-polling-interval: "100ms"
160+
161+
# default-step-action-parallelism-limit specifies the default limit for parallel StepAction resolution.
162+
default-step-action-parallelism-limit: "5"

docs/additional-configs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ The example below customizes the following:
245245
more information, see [`Matrix`](matrix.md).
246246
- the default resolver type to `git`.
247247
- the default polling interval for the sidecar log results container via `default-sidecar-log-polling-interval`.
248+
- the default limit for parallel StepAction resolution via `default-step-action-parallelism-limit`.
248249

249250
```yaml
250251
apiVersion: v1
@@ -263,6 +264,7 @@ data:
263264
default-max-matrix-combinations-count: "1024"
264265
default-resolver-type: "git"
265266
default-sidecar-log-polling-interval: "100ms"
267+
default-step-action-parallelism-limit: "10"
266268
```
267269

268270
### `default-sidecar-log-polling-interval`

pkg/apis/config/default.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ const (
5656

5757
DefaultSidecarLogPollingInterval = 100 * time.Millisecond
5858

59+
// DefaultStepActionParallelismLimit is the default limit for parallel StepAction resolution.
60+
DefaultStepActionParallelismLimit = 5
61+
5962
defaultTimeoutMinutesKey = "default-timeout-minutes"
6063
defaultServiceAccountKey = "default-service-account"
6164
defaultManagedByLabelValueKey = "default-managed-by-label-value"
@@ -70,6 +73,7 @@ const (
7073
defaultImagePullBackOffTimeout = "default-imagepullbackoff-timeout"
7174
defaultMaximumResolutionTimeout = "default-maximum-resolution-timeout"
7275
defaultSidecarLogPollingIntervalKey = "default-sidecar-log-polling-interval"
76+
defaultStepActionParallelismLimitKey = "default-step-action-parallelism-limit"
7377
)
7478

7579
// DefaultConfig holds all the default configurations for the config.
@@ -94,7 +98,8 @@ type Defaults struct {
9498
// DefaultSidecarLogPollingInterval specifies how frequently (as a time.Duration) the Tekton sidecar log results container polls for step completion files.
9599
// This value is loaded from the 'sidecar-log-polling-interval' key in the config-defaults ConfigMap.
96100
// It is used to control the responsiveness and resource usage of the sidecar in both production and test environments.
97-
DefaultSidecarLogPollingInterval time.Duration
101+
DefaultSidecarLogPollingInterval time.Duration
102+
DefaultStepActionParallelismLimit int
98103
}
99104

100105
// GetDefaultsConfigName returns the name of the configmap containing all
@@ -128,6 +133,7 @@ func (cfg *Defaults) Equals(other *Defaults) bool {
128133
other.DefaultImagePullBackOffTimeout == cfg.DefaultImagePullBackOffTimeout &&
129134
other.DefaultMaximumResolutionTimeout == cfg.DefaultMaximumResolutionTimeout &&
130135
other.DefaultSidecarLogPollingInterval == cfg.DefaultSidecarLogPollingInterval &&
136+
other.DefaultStepActionParallelismLimit == cfg.DefaultStepActionParallelismLimit &&
131137
reflect.DeepEqual(other.DefaultForbiddenEnv, cfg.DefaultForbiddenEnv)
132138
}
133139

@@ -143,6 +149,7 @@ func NewDefaultsFromMap(cfgMap map[string]string) (*Defaults, error) {
143149
DefaultImagePullBackOffTimeout: DefaultImagePullBackOffTimeout,
144150
DefaultMaximumResolutionTimeout: DefaultMaximumResolutionTimeout,
145151
DefaultSidecarLogPollingInterval: DefaultSidecarLogPollingInterval,
152+
DefaultStepActionParallelismLimit: DefaultStepActionParallelismLimit,
146153
}
147154

148155
if defaultTimeoutMin, ok := cfgMap[defaultTimeoutMinutesKey]; ok {
@@ -237,6 +244,14 @@ func NewDefaultsFromMap(cfgMap map[string]string) (*Defaults, error) {
237244
tc.DefaultSidecarLogPollingInterval = interval
238245
}
239246

247+
if defaultStepActionParallelismLimit, ok := cfgMap[defaultStepActionParallelismLimitKey]; ok {
248+
stepActionParallelismLimit, err := strconv.ParseInt(defaultStepActionParallelismLimit, 10, 0)
249+
if err != nil {
250+
return nil, fmt.Errorf("failed parsing default config %q", defaultStepActionParallelismLimitKey)
251+
}
252+
tc.DefaultStepActionParallelismLimit = int(stepActionParallelismLimit)
253+
}
254+
240255
return &tc, nil
241256
}
242257

pkg/apis/config/default_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
4747
DefaultImagePullBackOffTimeout: time.Duration(5) * time.Second,
4848
DefaultMaximumResolutionTimeout: 1 * time.Minute,
4949
DefaultSidecarLogPollingInterval: 100 * time.Millisecond,
50+
DefaultStepActionParallelismLimit: 5,
5051
},
5152
fileName: config.GetDefaultsConfigName(),
5253
},
@@ -69,6 +70,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
6970
DefaultImagePullBackOffTimeout: 0,
7071
DefaultMaximumResolutionTimeout: 1 * time.Minute,
7172
DefaultSidecarLogPollingInterval: 100 * time.Millisecond,
73+
DefaultStepActionParallelismLimit: 5,
7274
},
7375
fileName: "config-defaults-with-pod-template",
7476
},
@@ -94,6 +96,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
9496
DefaultImagePullBackOffTimeout: 0,
9597
DefaultMaximumResolutionTimeout: 1 * time.Minute,
9698
DefaultSidecarLogPollingInterval: 100 * time.Millisecond,
99+
DefaultStepActionParallelismLimit: 5,
97100
},
98101
},
99102
{
@@ -108,6 +111,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
108111
DefaultImagePullBackOffTimeout: 0,
109112
DefaultMaximumResolutionTimeout: 1 * time.Minute,
110113
DefaultSidecarLogPollingInterval: 100 * time.Millisecond,
114+
DefaultStepActionParallelismLimit: 5,
111115
},
112116
},
113117
{
@@ -125,6 +129,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
125129
DefaultImagePullBackOffTimeout: 0,
126130
DefaultMaximumResolutionTimeout: 1 * time.Minute,
127131
DefaultSidecarLogPollingInterval: 100 * time.Millisecond,
132+
DefaultStepActionParallelismLimit: 5,
128133
},
129134
},
130135
{
@@ -139,6 +144,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
139144
DefaultImagePullBackOffTimeout: time.Duration(15) * time.Second,
140145
DefaultMaximumResolutionTimeout: 1 * time.Minute,
141146
DefaultSidecarLogPollingInterval: 100 * time.Millisecond,
147+
DefaultStepActionParallelismLimit: 5,
142148
},
143149
},
144150
{
@@ -153,6 +159,7 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
153159
DefaultImagePullBackOffTimeout: 0,
154160
DefaultMaximumResolutionTimeout: 1 * time.Minute,
155161
DefaultSidecarLogPollingInterval: 100 * time.Millisecond,
162+
DefaultStepActionParallelismLimit: 5,
156163
},
157164
},
158165
{
@@ -203,6 +210,25 @@ func TestNewDefaultsFromConfigMap(t *testing.T) {
203210
},
204211
"test": {},
205212
},
213+
DefaultStepActionParallelismLimit: 5,
214+
},
215+
},
216+
{
217+
expectedError: true,
218+
fileName: "config-defaults-step-action-parallelism-limit-err",
219+
},
220+
{
221+
expectedError: false,
222+
fileName: "config-defaults-step-action-parallelism-limit",
223+
expectedConfig: &config.Defaults{
224+
DefaultStepActionParallelismLimit: 10,
225+
DefaultTimeoutMinutes: 60,
226+
DefaultServiceAccount: "default",
227+
DefaultManagedByLabelValue: config.DefaultManagedByLabelValue,
228+
DefaultMaxMatrixCombinationsCount: 256,
229+
DefaultImagePullBackOffTimeout: 0,
230+
DefaultMaximumResolutionTimeout: 1 * time.Minute,
231+
DefaultSidecarLogPollingInterval: 100 * time.Millisecond,
206232
},
207233
},
208234
}
@@ -228,6 +254,7 @@ func TestNewDefaultsFromEmptyConfigMap(t *testing.T) {
228254
DefaultImagePullBackOffTimeout: 0,
229255
DefaultMaximumResolutionTimeout: 1 * time.Minute,
230256
DefaultSidecarLogPollingInterval: 100 * time.Millisecond,
257+
DefaultStepActionParallelismLimit: 5,
231258
}
232259
verifyConfigFileWithExpectedConfig(t, DefaultsConfigEmptyName, expectedConfig)
233260
}
@@ -414,6 +441,25 @@ func TestEquals(t *testing.T) {
414441
},
415442
expected: true,
416443
},
444+
{
445+
name: "different default step action parallelism limit",
446+
left: &config.Defaults{
447+
DefaultStepActionParallelismLimit: 5,
448+
},
449+
right: &config.Defaults{
450+
DefaultStepActionParallelismLimit: 10,
451+
},
452+
expected: false,
453+
}, {
454+
name: "same default step action parallelism limit",
455+
left: &config.Defaults{
456+
DefaultStepActionParallelismLimit: 5,
457+
},
458+
right: &config.Defaults{
459+
DefaultStepActionParallelismLimit: 5,
460+
},
461+
expected: true,
462+
},
417463
}
418464

419465
for _, tc := range testCases {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2019 The Tekton Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: config-defaults
19+
namespace: tekton-pipelines
20+
data:
21+
default-step-action-parallelism-limit: "abc"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2019 The Tekton Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
apiVersion: v1
16+
kind: ConfigMap
17+
metadata:
18+
name: config-defaults
19+
namespace: tekton-pipelines
20+
data:
21+
default-step-action-parallelism-limit: "10"

pkg/apis/config/testdata/config-defaults.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ data:
2222
default-service-account: "tekton"
2323
default-managed-by-label-value: "something-else"
2424
default-resolver-type: "git"
25-
default-imagepullbackoff-timeout: "5s"
25+
default-imagepullbackoff-timeout: "5s"
26+
default-step-action-parallelism-limit: "5"

pkg/pod/pod_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2628,7 +2628,6 @@ _EOF_
26282628
} else {
26292629
trAnnotations = c.trAnnotation
26302630
trAnnotations[ReleaseAnnotation] = fakeVersion
2631-
26322631
}
26332632
testTaskRunName := taskRunName
26342633
if c.trName != "" {

0 commit comments

Comments
 (0)