diff --git a/protokube/pkg/protokube/kube_boot.go b/protokube/pkg/protokube/kube_boot.go index 886a707ce5..823225d067 100644 --- a/protokube/pkg/protokube/kube_boot.go +++ b/protokube/pkg/protokube/kube_boot.go @@ -18,10 +18,12 @@ package protokube import ( "context" + "fmt" "net" "path/filepath" "time" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/klog/v2" ) @@ -101,8 +103,24 @@ func (k *KubeBoot) Init(volumesProvider Volumes) { // RunSyncLoop is responsible for provision the cluster func (k *KubeBoot) RunSyncLoop() { + ctx := context.Background() + + client, err := k.Kubernetes.KubernetesClient() + if err != nil { + panic(fmt.Sprintf("could not create kubernetes client: %v", err)) + } + + klog.Info("polling for apiserver readiness") + for { + _, err = client.CoreV1().Namespaces().Get(ctx, "kube-system", metav1.GetOptions{}) + if err == nil { + klog.Info("successfully connected to the apiserver") + break + } + klog.Infof("failed to connect to the apiserver (will sleep and retry): %v", err) + time.Sleep(5 * time.Second) + } for { - ctx := context.Background() if err := k.syncOnce(ctx); err != nil { klog.Warningf("error during attempt to bootstrap (will sleep and retry): %v", err) }