Hit APIServer cache when testing healthiness

This commit is contained in:
Eric Lin 2024-02-22 11:12:50 +00:00
parent 2016fab308
commit 9f9858b6ca

View File

@ -41,6 +41,7 @@ import (
storagelisters "k8s.io/client-go/listers/storage/v1"
csitranslationplugins "k8s.io/csi-translation-lib/plugins"
"k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/kubelet/util"
"k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/csi/nodeinfomanager"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
@ -867,12 +868,16 @@ func unregisterDriver(driverName string) error {
// for a healthy APIServer
func waitForAPIServerForever(client clientset.Interface, nodeName types.NodeName) error {
var lastErr error
// Served object is discarded so no risk to have stale object with benefit to
// reduce the load on APIServer and etcd.
opts := meta.GetOptions{}
util.FromApiserverCache(&opts)
err := wait.PollImmediateInfinite(time.Second, func() (bool, error) {
// Get a CSINode from API server to make sure 1) kubelet can reach API server
// and 2) it has enough permissions. Kubelet may have restricted permissions
// when it's bootstrapping TLS.
// https://kubernetes.io/docs/reference/command-line-tools-reference/kubelet-tls-bootstrapping/
_, lastErr = client.StorageV1().CSINodes().Get(context.TODO(), string(nodeName), meta.GetOptions{})
_, lastErr = client.StorageV1().CSINodes().Get(context.TODO(), string(nodeName), opts)
if lastErr == nil || apierrors.IsNotFound(lastErr) {
// API server contacted
return true, nil