-
Notifications
You must be signed in to change notification settings - Fork 1.9k
exponential backoff in taskRun controller
#8926
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| /* | ||
| Copyright 2025 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 controller provides helper methods for external controllers for | ||
| // Custom Task types. | ||
| package controller | ||
|
|
||
| import ( | ||
| "errors" | ||
| "net/http" | ||
| "strings" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| ) | ||
|
|
||
| // IsWebhookTimeout checks if the error is due to a mutating admission webhook timeout. | ||
| // This function is used to determine if an error should trigger exponential backoff retry logic. | ||
| func IsWebhookTimeout(err error) bool { | ||
| var statusErr *apierrors.StatusError | ||
| if errors.As(err, &statusErr) { | ||
| return statusErr.ErrStatus.Code == http.StatusInternalServerError && | ||
| strings.Contains(statusErr.ErrStatus.Message, "timeout") | ||
| } | ||
| return false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| /* | ||
| Copyright 2025 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 controller | ||
|
|
||
| import ( | ||
| "errors" | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| ) | ||
|
|
||
| func TestIsWebhookTimeout(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| err error | ||
| expected bool | ||
| }{ | ||
| { | ||
| name: "nil error", | ||
| err: nil, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "non-status error", | ||
| err: errors.New("some other error"), | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "webhook timeout error - exact match", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusInternalServerError, | ||
| Message: "timeout", | ||
| }, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "webhook timeout error - contains timeout in message", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusInternalServerError, | ||
| Message: "admission webhook timeout occurred", | ||
| }, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "webhook timeout error - case insensitive", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusInternalServerError, | ||
| Message: "TIMEOUT", | ||
| }, | ||
| }, | ||
| expected: false, // Case-sensitive matching, so "TIMEOUT" should not match "timeout" | ||
| }, | ||
| { | ||
| name: "non-webhook error - different status code", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusBadRequest, | ||
| Message: "timeout", | ||
| }, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "non-webhook error - different message", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusInternalServerError, | ||
| Message: "server error", | ||
| }, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "non-webhook error - forbidden", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusForbidden, | ||
| Message: "forbidden", | ||
| }, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "non-webhook error - conflict", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusConflict, | ||
| Message: "conflict", | ||
| }, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "non-webhook error - not found", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusNotFound, | ||
| Message: "not found", | ||
| }, | ||
| }, | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "webhook timeout error - with additional context", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusInternalServerError, | ||
| Message: "failed calling webhook: timeout", | ||
| }, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "webhook timeout error - with error details", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusInternalServerError, | ||
| Message: "admission webhook \"example.com\" failed: timeout", | ||
| }, | ||
| }, | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "non-webhook error - timeout in different context", | ||
| err: &apierrors.StatusError{ | ||
| ErrStatus: metav1.Status{ | ||
| Code: http.StatusInternalServerError, | ||
| Message: "operation completed successfully, no timeout", | ||
| }, | ||
| }, | ||
| expected: true, // Contains "timeout" substring, so it should match | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| result := IsWebhookTimeout(tt.err) | ||
| if result != tt.expected { | ||
| t.Errorf("IsWebhookTimeout() = %v, want %v", result, tt.expected) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨