Merge pull request #11093 from olemarkus/protokube-eager-connect

Ensure protokube can connect to kube-apiserver before starting the sync loop
This commit is contained in:
Kubernetes Prow Robot 2021-03-21 15:47:43 -07:00 committed by GitHub
commit 9c4de8da81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 19 additions and 1 deletions

View File

@ -18,10 +18,12 @@ package protokube
import ( import (
"context" "context"
"fmt"
"net" "net"
"path/filepath" "path/filepath"
"time" "time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2" "k8s.io/klog/v2"
) )
@ -101,8 +103,24 @@ func (k *KubeBoot) Init(volumesProvider Volumes) {
// RunSyncLoop is responsible for provision the cluster // RunSyncLoop is responsible for provision the cluster
func (k *KubeBoot) RunSyncLoop() { func (k *KubeBoot) RunSyncLoop() {
for {
ctx := context.Background() 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 {
if err := k.syncOnce(ctx); err != nil { if err := k.syncOnce(ctx); err != nil {
klog.Warningf("error during attempt to bootstrap (will sleep and retry): %v", err) klog.Warningf("error during attempt to bootstrap (will sleep and retry): %v", err)
} }