talos/pkg/kubernetes/errors.go
Andrey Smirnov 5e0c80f616
fix: ignore connection reset errors on k8s upgrade
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>
2022-03-18 22:11:28 +03:00

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
}