Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated cherry pick of #11093: Ensure protokube can connect to kube-apiserver before #11108

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion protokube/pkg/protokube/kube_boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}
Expand Down