talos/pkg/kubernetes/errors.go
Dmitriy Matrenichev 30f7851d2a
chore: bump golangci-lint from 1.45.2 to 1.47.2
Minor linter upgrade.

Signed-off-by: Dmitriy Matrenichev <dmitry.matrenichev@siderolabs.com>
2022-07-22 17:49:44 +03:00

40 lines
959 B
Go

// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package kubernetes
import (
"errors"
"io"
"net"
"syscall"
apierrors "k8s.io/apimachinery/pkg/api/errors"
)
// IsRetryableError returns true if this Kubernetes API should be retried.
func IsRetryableError(err error) bool {
if apierrors.IsTimeout(err) || apierrors.IsServerTimeout(err) || apierrors.IsInternalError(err) {
return true
}
for _, retryableError := range []error{io.EOF, io.ErrUnexpectedEOF, syscall.ECONNREFUSED, syscall.ECONNRESET} {
if errors.Is(err, retryableError) {
return true
}
}
var netErr net.Error
if errors.As(err, &netErr) {
// https://groups.google.com/g/golang-nuts/c/-JcZzOkyqYI/m/xwaZzjCgAwAJ
//nolint:staticcheck
if netErr.Temporary() || netErr.Timeout() {
return true
}
}
return false
}