Skip to content

Commit fb20f5e

Browse files
committed
Allow setting sidecar ready annotation early
This commit adds an option to a new `config-features` ConfigMap called `running-in-environment-with-injected-sidecars`. Enabling this option will decrease the time it takes for a TaskRun to start running(when no sidecars are present). However, for clusters that use injected sidecars e.g. istio enabling this option can lead to unexpected behavior.By default, the option is set to "true" for backwards compatibility. When no sidercars are present and the cluster does not use injected sidecars, the pipeline controller can optimize the TaskRun Pod creation process by setting the `tekton.dev/ready` annotation during pod creation itself instead of setting it after pod creation. Fixes #2080 Signed-off-by: Dibyo Mukherjee <[email protected]>
1 parent f7710bc commit fb20f5e

File tree

6 files changed

+282
-10
lines changed

6 files changed

+282
-10
lines changed

config/config-feature-flags.yaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ data:
2828
# $HOME environment variable but this will change in an upcoming
2929
# release.
3030
#
31-
# See https://github.com/tektoncd/pipeline/issues/2013 for more
32-
# info.
31+
# See https://github.com/tektoncd/pipeline/issues/2013 for more info.
3332
disable-home-env-overwrite: "false"
3433
# Setting this flag to "true" will prevent Tekton overriding your
3534
# Task container's working directory.
@@ -38,6 +37,15 @@ data:
3837
# working directory if not set by the user but this will change
3938
# in an upcoming release.
4039
#
41-
# See https://github.com/tektoncd/pipeline/issues/1836 for more
42-
# info.
40+
# See https://github.com/tektoncd/pipeline/issues/1836 for more info.
4341
disable-working-directory-overwrite: "false"
42+
43+
# Setting this flag to "true" will set the `tekton.dev/ready` annotation
44+
# at pod creation time for Taskruns without sidecars.
45+
#
46+
# Enabling this option should decrease the time it takes for a TaskRun to
47+
# start running. However, for clusters that use injected sidecars e.g. istio
48+
# enabling this option can lead to unexpected behavior.
49+
#
50+
# See https://github.com/tektoncd/pipeline/issues/2080 for more info.
51+
enable-ready-annotation-on-pod-create: "false"

config/config-features.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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-features
19+
namespace: tekton-pipelines
20+
labels:
21+
app.kubernetes.io/instance: default
22+
app.kubernetes.io/part-of: tekton-pipelines
23+
data:
24+
25+
# This option should be set to false when Pipelines is running in a cluster
26+
# that does not use injected sidecars such as Istio. Setting it to false should decrease the time it takes for a TaskRun to
27+
# start running. For clusters that use injected sidecars, setting this option to false can lead to unexpected behavior.
28+
#
29+
# See https://github.com/tektoncd/pipeline/issues/2080 for more info.
30+
running-in-environment-with-injected-sidecars: "true"

config/controller.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ spec:
9797
value: feature-flags
9898
- name: CONFIG_LEADERELECTION_NAME
9999
value: config-leader-election
100+
- name: CONFIG_FEATURES_NAME
101+
value: config-features
100102
- name: METRICS_DOMAIN
101103
value: tekton.dev/pipeline
102104
volumes:

docs/install.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ The default value is `false`, which causes Tekton to override the working direct
278278
for each `Step` that does not have its working directory explicitly set with `/workspace`.
279279
For more information, see the [associated issue](https://github.com/tektoncd/pipeline/issues/1836).
280280

281+
- `enable-ready-annotation-on-pod-create`: set this flag to `"true"` to allow the
282+
Tekton controller to set the `tekon.dev/ready` annotation at pod creation time for
283+
TaskRuns with no Sidecars specified. Enabling this option should decrease the time it takes for a TaskRun to
284+
start running. However, for clusters that use injected sidecars e.g. istio
285+
enabling this option can lead to unexpected behavior.
286+
281287
For example:
282288

283289
```yaml

pkg/pod/pod.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ const (
4545
// ResultsDir is the folder used by default to create the results file
4646
ResultsDir = "/tekton/results"
4747

48-
featureFlagDisableHomeEnvKey = "disable-home-env-overwrite"
49-
featureFlagDisableWorkingDirKey = "disable-working-directory-overwrite"
48+
featureInjectedSidecar = "running-in-environment-with-injected-sidecars"
49+
featureFlagDisableHomeEnvKey = "disable-home-env-overwrite"
50+
featureFlagDisableWorkingDirKey = "disable-working-directory-overwrite"
51+
featureFlagConfigMapName = "feature-flags"
52+
featureFlagSetReadyAnnotationOnPodCreate = "enable-ready-annotation-on-pod-create"
5053

5154
taskRunLabelKey = pipeline.GroupName + pipeline.TaskRunLabelKey
5255
)
@@ -238,6 +241,10 @@ func MakePod(images pipeline.Images, taskRun *v1beta1.TaskRun, taskSpec v1beta1.
238241
podAnnotations := taskRun.Annotations
239242
podAnnotations[ReleaseAnnotation] = ReleaseAnnotationValue
240243

244+
if shouldAddReadyAnnotationOnPodCreate(taskSpec.Sidecars, kubeclient) {
245+
podAnnotations[readyAnnotation] = readyAnnotationValue
246+
}
247+
241248
return &corev1.Pod{
242249
ObjectMeta: metav1.ObjectMeta{
243250
// We execute the build's pod in the same namespace as where the build was
@@ -351,3 +358,30 @@ func shouldOverrideWorkingDir(kubeclient kubernetes.Interface) bool {
351358
}
352359
return true
353360
}
361+
362+
// shouldAddReadyAnnotationonPodCreate returns a bool indicating whether the
363+
// controller should add the `Ready` annotation when creating the Pod. We cannot
364+
// add the annotation if Tekton is running in a cluster with injected sidecars
365+
// or if the Task specifies any sidecars.
366+
func shouldAddReadyAnnotationOnPodCreate(sidecars []v1beta1.Sidecar, kubeclient kubernetes.Interface) bool {
367+
// If the TaskRun has sidecars, we cannot set the READY annotation early
368+
if len(sidecars) > 0 {
369+
return false
370+
}
371+
// If the TaskRun has no sidecars, check if we are running in a cluster where sidecars can be injected by other
372+
// controllers.
373+
configMap, err := kubeclient.CoreV1().ConfigMaps(system.GetNamespace()).Get(getFeaturesConfigName(), metav1.GetOptions{})
374+
if err == nil && configMap != nil && configMap.Data != nil && configMap.Data[featureInjectedSidecar] == "false" {
375+
return true
376+
}
377+
return false
378+
}
379+
380+
// getFeaturesConfigName returns the name of the configmap containing all
381+
// customizations for the feature flags.
382+
func getFeaturesConfigName() string {
383+
if e := os.Getenv("CONFIG_FEATURES_NAME"); e != "" {
384+
return e
385+
}
386+
return "config-features"
387+
}

0 commit comments

Comments
 (0)