Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize CSI Plugin node server logic #1582

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions pkg/csi/plugins/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/fluid-cloudnative/fluid/pkg/utils/dataset/volume"
"github.com/fluid-cloudnative/fluid/pkg/utils/kubeclient"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
"os"
"os/exec"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -46,6 +47,7 @@ type nodeServer struct {
client client.Client
apiReader client.Reader
mutex sync.Mutex
node *v1.Node
}

func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) {
Expand Down Expand Up @@ -234,7 +236,7 @@ func (ns *nodeServer) NodeUnstageVolume(ctx context.Context, req *csi.NodeUnstag
var labelsToModify common.LabelsToModify
labelsToModify.Delete(fuseLabelKey)

node, err := kubeclient.GetNode(ns.apiReader, ns.nodeId)
node, err := ns.getNode()
if err != nil {
glog.Errorf("NodeUnstageVolume: can't get node %s: %v", ns.nodeId, err)
return nil, errors.Wrapf(err, "NodeUnstageVolume: can't get node %s", ns.nodeId)
Expand Down Expand Up @@ -266,7 +268,7 @@ func (ns *nodeServer) NodeStageVolume(ctx context.Context, req *csi.NodeStageVol
var labelsToModify common.LabelsToModify
labelsToModify.Add(fuseLabelKey, "true")

node, err := kubeclient.GetNode(ns.apiReader, ns.nodeId)
node, err := ns.getNode()
if err != nil {
glog.Errorf("NodeStageVolume: can't get node %s: %v", ns.nodeId, err)
return nil, errors.Wrapf(err, "NodeStageVolume: can't get node %s", ns.nodeId)
Expand Down Expand Up @@ -313,14 +315,31 @@ 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)
TrafalgarZZZ marked this conversation as resolved.
Show resolved Hide resolved
return runtimeNamespace, runtimeName, nil
}
}

// Fallback: query API Server to get namespaced name
glog.Infof("Get runtime namespace and name directly from api server with volumeId %s", volumeId)
return volume.GetNamespacedNameByVolumeId(ns.apiReader, volumeId)
}

// getNode first checks cached node
func (ns *nodeServer) getNode() (node *v1.Node, err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need add UT for this function.

if ns.node != nil {
TrafalgarZZZ marked this conversation as resolved.
Show resolved Hide resolved
glog.V(1).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)
ns.node = node
return ns.node, nil
}

func checkMountInUse(volumeName string) (bool, error) {
var inUse bool
glog.Infof("Try to check if the volume %s is being used", volumeName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddc/goosefs/transform_permission.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2022 The Fluid Authors.
Copyright 2022 The Fluid Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down