mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-17 20:04:36 -05:00
helm: retry on connection refused (#1245)
* bootstrapper: directly return kubewaiter error * helm: retry on connection refused
This commit is contained in:
parent
d78d22f95a
commit
3339ae2399
@ -15,6 +15,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/k8sapi"
|
"github.com/edgelesssys/constellation/v2/bootstrapper/internal/kubernetes/k8sapi"
|
||||||
@ -188,6 +189,11 @@ func (h *Client) installCiliumGCP(ctx context.Context, kubectl k8sapi.Client, re
|
|||||||
// The function will wait 30 seconds before retrying a failed installation attempt.
|
// The function will wait 30 seconds before retrying a failed installation attempt.
|
||||||
// After 5 minutes the retrier will be canceld and the function returns with an error.
|
// After 5 minutes the retrier will be canceld and the function returns with an error.
|
||||||
func (h *Client) install(ctx context.Context, chartRaw []byte, values map[string]any) error {
|
func (h *Client) install(ctx context.Context, chartRaw []byte, values map[string]any) error {
|
||||||
|
retriable := func(err error) bool {
|
||||||
|
return errors.Is(err, wait.ErrWaitTimeout) ||
|
||||||
|
strings.Contains(err.Error(), "connection refused")
|
||||||
|
}
|
||||||
|
|
||||||
reader := bytes.NewReader(chartRaw)
|
reader := bytes.NewReader(chartRaw)
|
||||||
chart, err := loader.LoadArchive(reader)
|
chart, err := loader.LoadArchive(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -200,7 +206,7 @@ func (h *Client) install(ctx context.Context, chartRaw []byte, values map[string
|
|||||||
values,
|
values,
|
||||||
h.log,
|
h.log,
|
||||||
}
|
}
|
||||||
retrier := retry.NewIntervalRetrier(doer, 30*time.Second, isTimeoutErr)
|
retrier := retry.NewIntervalRetrier(doer, 30*time.Second, retriable)
|
||||||
|
|
||||||
// Since we have no precise retry condition we want to stop retrying after 5 minutes.
|
// Since we have no precise retry condition we want to stop retrying after 5 minutes.
|
||||||
// The helm library only reports a timeout error in the error cases we currently know.
|
// The helm library only reports a timeout error in the error cases we currently know.
|
||||||
@ -229,8 +235,3 @@ func (i installDoer) Do(ctx context.Context) error {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// isTimeoutErr checks if the given error is a timeout error from k8s.io/apimachinery.
|
|
||||||
func isTimeoutErr(err error) bool {
|
|
||||||
return errors.Is(err, wait.ErrWaitTimeout)
|
|
||||||
}
|
|
||||||
|
@ -9,6 +9,7 @@ package kubewaiter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@ -33,7 +34,7 @@ func (w *CloudKubeAPIWaiter) Wait(ctx context.Context, kubernetesClient Kubernet
|
|||||||
doer := &kubeDoer{kubeClient: kubernetesClient}
|
doer := &kubeDoer{kubeClient: kubernetesClient}
|
||||||
retrier := retry.NewIntervalRetrier(doer, 5*time.Second, funcAlwaysRetriable)
|
retrier := retry.NewIntervalRetrier(doer, 5*time.Second, funcAlwaysRetriable)
|
||||||
if err := retrier.Do(ctx); err != nil {
|
if err := retrier.Do(ctx); err != nil {
|
||||||
return doer.Do(context.Background())
|
return fmt.Errorf("waiting for Kubernetes API: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user