pkg/kubelet: improve the node informer sync check
GetNode() is called in a lot of places including a hot loop in fastStatusUpdateOnce. Having a poll in it is delaying the kubelet /readyz status=200 report. If a client is available attempt to wait for the sync to happen, before starting the list watch for pods at the apiserver.
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
cadvisorapiv1 "github.com/google/cadvisor/info/v1"
|
||||
cadvisorv2 "github.com/google/cadvisor/info/v2"
|
||||
@@ -33,7 +32,6 @@ import (
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/kubernetes/pkg/kubelet/cm"
|
||||
"k8s.io/kubernetes/pkg/kubelet/config"
|
||||
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
|
||||
@@ -237,15 +235,6 @@ func (kl *Kubelet) GetNode() (*v1.Node, error) {
|
||||
if kl.kubeClient == nil {
|
||||
return kl.initialNode(context.TODO())
|
||||
}
|
||||
// if we have a valid kube client, we wait for initial lister to sync
|
||||
if !kl.nodeHasSynced() {
|
||||
err := wait.PollImmediate(time.Second, maxWaitForAPIServerSync, func() (bool, error) {
|
||||
return kl.nodeHasSynced(), nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("nodes have not yet been read at least once, cannot construct node object")
|
||||
}
|
||||
}
|
||||
return kl.nodeLister.Get(string(kl.nodeName))
|
||||
}
|
||||
|
||||
@@ -256,7 +245,7 @@ func (kl *Kubelet) GetNode() (*v1.Node, error) {
|
||||
// zero capacity, and the default labels.
|
||||
func (kl *Kubelet) getNodeAnyWay() (*v1.Node, error) {
|
||||
if kl.kubeClient != nil {
|
||||
if n, err := kl.GetNode(); err == nil {
|
||||
if n, err := kl.nodeLister.Get(string(kl.nodeName)); err == nil {
|
||||
return n, nil
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user