From f4ed7caa262f79664c94b4a9837bfabe2cacdeaf Mon Sep 17 00:00:00 2001 From: TrafalgarZZZ Date: Wed, 23 Mar 2022 23:00:05 +0800 Subject: [PATCH] Add env variable switch for allowing node server to patch cached node Signed-off-by: TrafalgarZZZ --- charts/fluid/fluid/templates/csi/daemonset.yaml | 2 ++ pkg/csi/plugins/nodeserver.go | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/charts/fluid/fluid/templates/csi/daemonset.yaml b/charts/fluid/fluid/templates/csi/daemonset.yaml index ae594553611..a8d455f1324 100644 --- a/charts/fluid/fluid/templates/csi/daemonset.yaml +++ b/charts/fluid/fluid/templates/csi/daemonset.yaml @@ -84,6 +84,8 @@ spec: - name: MOUNT_ROOT value: {{ .Values.runtime.mountRoot | quote }} {{- end }} + - name: ALLOW_PATCH_STALE_NODE + value: "true" - name: KUBELET_ROOTDIR value: {{ .Values.csi.kubelet.rootDir }} - name: CSI_ENDPOINT diff --git a/pkg/csi/plugins/nodeserver.go b/pkg/csi/plugins/nodeserver.go index 59ede89d573..a8d2eab4422 100644 --- a/pkg/csi/plugins/nodeserver.go +++ b/pkg/csi/plugins/nodeserver.go @@ -41,6 +41,10 @@ import ( "k8s.io/utils/mount" ) +const ( + AllowPatchStaleNodeEnv = "ALLOW_PATCH_STALE_NODE" +) + type nodeServer struct { nodeId string *csicommon.DefaultNodeServer @@ -315,7 +319,7 @@ func (ns *nodeServer) getRuntimeNamespacedName(volumeContext map[string]string, runtimeName, nameFound := volumeContext[common.VolumeAttrName] runtimeNamespace, nsFound := volumeContext[common.VolumeAttrNamespace] if nameFound && nsFound { - glog.Infof("Get runtime namespace(%s) and name(%s) from volume context", runtimeNamespace, runtimeName) + glog.V(3).Infof("Get runtime namespace(%s) and name(%s) from volume context", runtimeNamespace, runtimeName) return runtimeNamespace, runtimeName, nil } } @@ -327,15 +331,18 @@ func (ns *nodeServer) getRuntimeNamespacedName(volumeContext map[string]string, // getNode first checks cached node func (ns *nodeServer) getNode() (node *v1.Node, err error) { - if ns.node != nil { - glog.V(1).Infof("Found cached node %s", ns.node.Name) - return ns.node, nil + // Default to allow patch stale node info + if envVar, found := os.LookupEnv(AllowPatchStaleNodeEnv); !found || "true" == envVar { + if ns.node != nil { + glog.V(3).Infof("Found cached node %s", ns.node.Name) + return ns.node, nil + } } if node, err = kubeclient.GetNode(ns.apiReader, ns.nodeId); err != nil { return nil, err } - glog.Infof("Got node %s from api server", node.Name) + glog.V(1).Infof("Got node %s from api server", node.Name) ns.node = node return ns.node, nil }