Skip to content

Commit

Permalink
Add env variable switch for allowing node server to patch cached node
Browse files Browse the repository at this point in the history
Signed-off-by: TrafalgarZZZ <[email protected]>
  • Loading branch information
TrafalgarZZZ committed Mar 23, 2022
1 parent f06bafe commit f4ed7ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 2 additions & 0 deletions charts/fluid/fluid/templates/csi/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions pkg/csi/plugins/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import (
"k8s.io/utils/mount"
)

const (
AllowPatchStaleNodeEnv = "ALLOW_PATCH_STALE_NODE"
)

type nodeServer struct {
nodeId string
*csicommon.DefaultNodeServer
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}
Expand Down

0 comments on commit f4ed7ca

Please sign in to comment.