mirror of https://github.com/kubernetes/kops.git
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:
commit
9c4de8da81
|
|
@ -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() {
|
||||
for {
|
||||
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 {
|
||||
klog.Warningf("error during attempt to bootstrap (will sleep and retry): %v", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue