mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-09 22:51:12 +02:00
This fixes `talosctl upgrade-k8s`: ``` Get "https://172.21.0.1:6443/api/v1/namespaces/kube-system/pods?labelSelector=k8s-app+%3D+kube-apiserver": read tcp 172.21.0.1:51416->172.21.0.1:6443: read: connection reset by peer ``` The error happens when the `kube-apiserver` is restarted during the control plane upgrade, and it should be ignored as a transient error. Signed-off-by: Andrey Smirnov <andrey.smirnov@talos-systems.com>
38 lines
862 B
Go
38 lines
862 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) {
|
|
if netErr.Temporary() || netErr.Timeout() {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|