Skip to content

Commit

Permalink
protokube: don't try to connect to apiserver if not control-plane
Browse files Browse the repository at this point in the history
We run protokube on the nodes in gossip mode; however protokube tries
to connect to the apiserver on localhost, and that simply won't work
if running on a node.

This doesn't cause any actual problems beyond logspam, but it's an
easy fix.
  • Loading branch information
justinsb committed Sep 26, 2021
1 parent c742621 commit 500f85e
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions protokube/pkg/protokube/kube_boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,24 @@ type KubeBoot struct {
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))
}
if k.Master {
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.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)
}
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)
Expand Down

0 comments on commit 500f85e

Please sign in to comment.