-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Allow imagePullBackOff for the specified duration
#7666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ installation. | |
| - [Verify the transparency logs using `rekor-cli`](#verify-the-transparency-logs-using-rekor-cli) | ||
| - [Verify Tekton Resources](#verify-tekton-resources) | ||
| - [Pipelinerun with Affinity Assistant](#pipelineruns-with-affinity-assistant) | ||
| - [TaskRuns with `imagePullBackOff` Timeout](#taskruns-with-imagepullbackoff-timeout) | ||
| - [Next steps](#next-steps) | ||
|
|
||
|
|
||
|
|
@@ -672,6 +673,26 @@ please take a look at [Trusted Resources](./trusted-resources.md). | |
| The cluster operators can review the [guidelines](developers/affinity-assistant.md) to `cordon` a node in the cluster | ||
| with the tekton controller and the affinity assistant is enabled. | ||
|
|
||
| ## TaskRuns with `imagePullBackOff` Timeout | ||
|
|
||
| Tekton pipelines has adopted a fail fast strategy with a taskRun failing with `TaskRunImagePullFailed` in case of an | ||
| `imagePullBackOff`. This can be limited in some cases, and it generally depends on the infrastructure. To allow the | ||
| cluster operators to decide whether to wait in case of an `imagePullBackOff`, a setting is available to configure | ||
| the wait time in minutes such that the controller will wait for the specified duration before declaring a failure. | ||
| For example, with the following `config-defaults`, the controller does not mark the taskRun as failure for 5 minutes since | ||
| the pod is scheduled in case the image pull fails with `imagePullBackOff`. | ||
| See issue https://github.com/tektoncd/pipeline/issues/5987 for more details. | ||
|
|
||
| ```yaml | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: config-defaults | ||
| namespace: tekton-pipelines | ||
| data: | ||
| default-imagepullbackoff-timeout: "5" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The example needs to be updated to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks @afrittoli - ptal - #7679. Thanks! |
||
| ``` | ||
|
|
||
| ## Next steps | ||
|
|
||
| To get started with Tekton check the [Introductory tutorials][quickstarts], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # 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 | ||
| # | ||
| # https://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. | ||
|
|
||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: config-defaults | ||
| namespace: tekton-pipelines | ||
| data: | ||
| default-imagepullbackoff-timeout: "not-a-timeout" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,13 +94,15 @@ type Reconciler struct { | |
| tracerProvider trace.TracerProvider | ||
| } | ||
|
|
||
| const ImagePullBackOff = "ImagePullBackOff" | ||
|
|
||
| var ( | ||
| // Check that our Reconciler implements taskrunreconciler.Interface | ||
| _ taskrunreconciler.Interface = (*Reconciler)(nil) | ||
|
|
||
| // Pod failure reasons that trigger failure of the TaskRun | ||
| podFailureReasons = map[string]struct{}{ | ||
| "ImagePullBackOff": {}, | ||
| ImagePullBackOff: {}, | ||
| "InvalidImageName": {}, | ||
| } | ||
| ) | ||
|
|
@@ -171,7 +173,7 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, tr *v1.TaskRun) pkgrecon | |
| } | ||
|
|
||
| // Check for Pod Failures | ||
| if failed, reason, message := c.checkPodFailed(tr); failed { | ||
| if failed, reason, message := c.checkPodFailed(ctx, tr); failed { | ||
| err := c.failTaskRun(ctx, tr, reason, message) | ||
| return c.finishReconcileUpdateEmitEvents(ctx, tr, before, err) | ||
| } | ||
|
|
@@ -222,10 +224,30 @@ func (c *Reconciler) ReconcileKind(ctx context.Context, tr *v1.TaskRun) pkgrecon | |
| return nil | ||
| } | ||
|
|
||
| func (c *Reconciler) checkPodFailed(tr *v1.TaskRun) (bool, v1.TaskRunReason, string) { | ||
| func (c *Reconciler) checkPodFailed(ctx context.Context, tr *v1.TaskRun) (bool, v1.TaskRunReason, string) { | ||
| for _, step := range tr.Status.Steps { | ||
| if step.Waiting != nil { | ||
| if _, found := podFailureReasons[step.Waiting.Reason]; found { | ||
| if step.Waiting.Reason == ImagePullBackOff { | ||
| imagePullBackOffTimeOut := config.FromContextOrDefaults(ctx).Defaults.DefaultImagePullBackOffTimeout | ||
| // only attempt to recover from the imagePullBackOff if specified | ||
| if imagePullBackOffTimeOut.Seconds() != 0 { | ||
| p, err := c.KubeClientSet.CoreV1().Pods(tr.Namespace).Get(ctx, tr.Status.PodName, metav1.GetOptions{}) | ||
| if err != nil { | ||
| message := fmt.Sprintf(`The step %q in TaskRun %q failed to pull the image %q and the pod with error: "%s."`, step.Name, tr.Name, step.ImageID, err) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: error messages should start in lowercase
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks @afrittoli - ptal - #7679. Thanks! |
||
| return true, v1.TaskRunReasonImagePullFailed, message | ||
| } | ||
| for _, condition := range p.Status.Conditions { | ||
| // check the pod condition to get the time when the pod was scheduled | ||
| // keep trying until the pod schedule time has exceeded the specified imagePullBackOff timeout duration | ||
| if condition.Type == corev1.PodScheduled { | ||
| if c.Clock.Since(condition.LastTransitionTime.Time) < imagePullBackOffTimeOut { | ||
| return false, "", "" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| image := step.ImageID | ||
| message := fmt.Sprintf(`The step %q in TaskRun %q failed to pull the image %q. The pod errored with the message: "%s."`, step.Name, tr.Name, image, step.Waiting.Message) | ||
| return true, v1.TaskRunReasonImagePullFailed, message | ||
|
|
@@ -235,6 +257,26 @@ func (c *Reconciler) checkPodFailed(tr *v1.TaskRun) (bool, v1.TaskRunReason, str | |
| for _, sidecar := range tr.Status.Sidecars { | ||
| if sidecar.Waiting != nil { | ||
| if _, found := podFailureReasons[sidecar.Waiting.Reason]; found { | ||
| if sidecar.Waiting.Reason == ImagePullBackOff { | ||
| imagePullBackOffTimeOut := config.FromContextOrDefaults(ctx).Defaults.DefaultImagePullBackOffTimeout | ||
| // only attempt to recover from the imagePullBackOff if specified | ||
| if imagePullBackOffTimeOut.Seconds() != 0 { | ||
| p, err := c.KubeClientSet.CoreV1().Pods(tr.Namespace).Get(ctx, tr.Status.PodName, metav1.GetOptions{}) | ||
| if err != nil { | ||
| message := fmt.Sprintf(`The sidecar %q in TaskRun %q failed to pull the image %q and the pod with error: "%s."`, sidecar.Name, tr.Name, sidecar.ImageID, err) | ||
| return true, v1.TaskRunReasonImagePullFailed, message | ||
| } | ||
| for _, condition := range p.Status.Conditions { | ||
| // check the pod condition to get the time when the pod was scheduled | ||
| // keep trying until the pod schedule time has exceeded the specified imagePullBackOff timeout duration | ||
| if condition.Type == corev1.PodScheduled { | ||
| if c.Clock.Since(condition.LastTransitionTime.Time) < imagePullBackOffTimeOut { | ||
| return false, "", "" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+260
to
+279
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: this might be a reusable function instead of having the same code twice
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a minor difference, both operating on different datatype. Its a little tricky as one has reference to step while other has a reference to sidecar. |
||
| image := sidecar.ImageID | ||
| message := fmt.Sprintf(`The sidecar %q in TaskRun %q failed to pull the image %q. The pod errored with the message: "%s."`, sidecar.Name, tr.Name, image, sidecar.Waiting.Message) | ||
| return true, v1.TaskRunReasonImagePullFailed, message | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.