Skip to content
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

fix(executor): Retry kubectl on internal transient error #8092

Merged
merged 3 commits into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions util/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func matchTransientErrPattern(err error) bool {
if pattern == "" {
return false
}
match, _ := regexp.MatchString(pattern, err.Error())
match, _ := regexp.MatchString(pattern, generateErrorString(err))
return match
}

Expand All @@ -63,10 +63,7 @@ func isTransientNetworkErr(err error) bool {
}
}

errorString := err.Error()
if exitErr, ok := err.(*exec.ExitError); ok {
errorString = fmt.Sprintf("%s %s", errorString, exitErr.Stderr)
}
errorString := generateErrorString(err)
if strings.Contains(errorString, "net/http: TLS handshake timeout") {
// If error is - tlsHandshakeTimeoutError, retry.
return true
Expand All @@ -80,3 +77,11 @@ func isTransientNetworkErr(err error) bool {

return false
}

func generateErrorString(err error) string {
errorString := err.Error()
if exitErr, ok := err.(*exec.ExitError); ok {
errorString = fmt.Sprintf("%s %s", errorString, exitErr.Stderr)
}
return errorString
}
Comment on lines +81 to +87
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

7 changes: 7 additions & 0 deletions util/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"net/url"
"os"
"os/exec"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -23,6 +24,10 @@ var (
ioTimeoutErr net.Error = netError("i/o timeout")
connectionTimedout net.Error = netError("connection timed out")
transientErr net.Error = netError("this error is transient")
transientExitErr = exec.ExitError{
ProcessState: &os.ProcessState{},
Stderr: []byte("this error is transient"),
}
)

const transientEnvVarKey = "TRANSIENT_ERROR_PATTERN"
Expand Down Expand Up @@ -67,9 +72,11 @@ func TestIsTransientErr(t *testing.T) {
t.Run("TransientErrorPattern", func(t *testing.T) {
_ = os.Setenv(transientEnvVarKey, "this error is transient")
assert.True(t, IsTransientErr(transientErr))
assert.True(t, IsTransientErr(&transientExitErr))

_ = os.Setenv(transientEnvVarKey, "this error is not transient")
assert.False(t, IsTransientErr(transientErr))
assert.False(t, IsTransientErr(&transientExitErr))

_ = os.Setenv(transientEnvVarKey, "")
assert.False(t, IsTransientErr(transientErr))
Expand Down