fix: ignore transient errors in upgrade Kubernetes code

This ignores temporary errors while `upgrade-k8s` is running,
as I observed that etcd leader change happened while waiting for
daemonset to be updated which aborted the upgrade process.

Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
This commit is contained in:
Andrey Smirnov 2020-10-23 17:01:08 +03:00 committed by talos-bot
parent 775010ddba
commit cb7f29991b

View File

@ -12,6 +12,7 @@ import (
"time" "time"
appsv1 "k8s.io/api/apps/v1" appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/strategicpatch" "k8s.io/apimachinery/pkg/util/strategicpatch"
@ -115,6 +116,10 @@ func updateDaemonset(ctx context.Context, clientset *kubernetes.Clientset, ds st
return retry.Constant(5*time.Minute, retry.WithUnits(10*time.Second)).Retry(func() error { return retry.Constant(5*time.Minute, retry.WithUnits(10*time.Second)).Retry(func() error {
daemonset, err = clientset.AppsV1().DaemonSets(namespace).Get(ctx, ds, metav1.GetOptions{}) daemonset, err = clientset.AppsV1().DaemonSets(namespace).Get(ctx, ds, metav1.GetOptions{})
if err != nil { if err != nil {
if apierrors.IsTimeout(err) || apierrors.IsServerTimeout(err) || apierrors.IsInternalError(err) {
return retry.ExpectedError(err)
}
return retry.UnexpectedError(fmt.Errorf("error fetching daemonset: %w", err)) return retry.UnexpectedError(fmt.Errorf("error fetching daemonset: %w", err))
} }