diff --git a/pkg/controller/cluster/cluster.go b/pkg/controller/cluster/cluster.go index 83f5beb..a523564 100644 --- a/pkg/controller/cluster/cluster.go +++ b/pkg/controller/cluster/cluster.go @@ -123,6 +123,11 @@ func (c *ClusterReconciler) Reconcile(ctx context.Context, req reconcile.Request // if there was an error during the reconciliation, return if reconcilerErr != nil { + if errors.Is(reconcilerErr, bootstrap.ErrServerNotReady) { + log.Info("server not ready, requeueing") + return reconcile.Result{RequeueAfter: time.Second * 10}, nil + } + return reconcile.Result{}, reconcilerErr } diff --git a/pkg/controller/cluster/server/bootstrap/bootstrap.go b/pkg/controller/cluster/server/bootstrap/bootstrap.go index 6b1c48a..82fe9d8 100644 --- a/pkg/controller/cluster/server/bootstrap/bootstrap.go +++ b/pkg/controller/cluster/server/bootstrap/bootstrap.go @@ -8,6 +8,7 @@ import ( "errors" "fmt" "net/http" + "syscall" "time" "github.com/rancher/k3k/pkg/apis/k3k.io/v1alpha1" @@ -17,6 +18,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) +var ErrServerNotReady = errors.New("server not ready") + type ControlRuntimeBootstrap struct { ServerCA content `json:"serverCA"` ServerCAKey content `json:"serverCAKey"` @@ -68,6 +71,10 @@ func requestBootstrap(token, serverIP string) (*ControlRuntimeBootstrap, error) resp, err := client.Do(req) if err != nil { + if errors.Is(err, syscall.ECONNREFUSED) { + return nil, ErrServerNotReady + } + return nil, err } defer resp.Body.Close()