Skip to content

Commit

Permalink
Allow to separate ControllerServer and NodeServer, allow to disable a…
Browse files Browse the repository at this point in the history
…ttacher (it do nothing in reality)
  • Loading branch information
kvaster authored and chrislusf committed Aug 7, 2023
1 parent 44d2cf5 commit a5a2c63
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
10 changes: 9 additions & 1 deletion cmd/seaweedfs-csi-driver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import (
)

var (
runNode = flag.Bool("node", false, "run node server")
runController = flag.Bool("controller", false, "run controller server")
enableAttacher = flag.Bool("attacher", false, "enable attacher")

filer = flag.String("filer", "localhost:8888", "filer server")
endpoint = flag.String("endpoint", "unix://tmp/seaweedfs-csi.sock", "CSI endpoint to accept gRPC calls")
nodeID = flag.String("nodeid", "", "node id")
Expand Down Expand Up @@ -53,7 +57,11 @@ func main() {

glog.Infof("connect to filer %s", *filer)

drv := driver.NewSeaweedFsDriver(*filer, *nodeID, *endpoint)
drv := driver.NewSeaweedFsDriver(*filer, *nodeID, *endpoint, *enableAttacher)

drv.RunNode = *runNode
drv.RunController = *runController

drv.ConcurrentWriters = *concurrentWriters
drv.CacheCapacityMB = *cacheCapacityMB
drv.CacheDir = *cacheDir
Expand Down
3 changes: 3 additions & 0 deletions deploy/helm/seaweedfs-csi-driver/templates/daemonset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ spec:
- "--nodeid=$(NODE_ID)"
- "--cacheDir=/var/cache/seaweedfs"
- "--dataLocality={{ .Values.dataLocality }}"
- "--node"
- "--controller"
- "--attacher"
{{- if .Values.node.injectTopologyInfoFromNodeLabel.enabled }}
- "--dataCenter=$(DATACENTER)"
{{- end }}
Expand Down
3 changes: 3 additions & 0 deletions deploy/helm/seaweedfs-csi-driver/templates/statefulset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ spec:
- "--endpoint=$(CSI_ENDPOINT)"
- "--filer=$(SEAWEEDFS_FILER)"
- "--nodeid=$(NODE_ID)"
- "--node"
- "--controller"
- "--attacher"
env:
- name: CSI_ENDPOINT
value: unix:///var/lib/csi/sockets/pluginproxy/csi.sock
Expand Down
31 changes: 24 additions & 7 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ type SeaweedFsDriver struct {
signature int32
DataCenter string
DataLocality datalocality.DataLocality

RunNode bool
RunController bool
}

func NewSeaweedFsDriver(filer, nodeID, endpoint string) *SeaweedFsDriver {
func NewSeaweedFsDriver(filer, nodeID, endpoint string, enableAttacher bool) *SeaweedFsDriver {

glog.Infof("Driver: %v version: %v", driverName, version)

Expand All @@ -75,11 +78,17 @@ func NewSeaweedFsDriver(filer, nodeID, endpoint string) *SeaweedFsDriver {
})
n.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME,
csi.ControllerServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
})

// we need this just only for csi-attach, but we do nothing for attach/detach
if enableAttacher {
n.AddControllerServiceCapabilities([]csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME,
})
}

return n
}

Expand All @@ -95,15 +104,21 @@ func (n *SeaweedFsDriver) initClient() error {
func (n *SeaweedFsDriver) Run() {
glog.Info("starting")

controller := NewControllerServer(n)
node := NewNodeServer(n)
var controller *ControllerServer
if n.RunController {
controller = NewControllerServer(n)
}

var node *NodeServer
if n.RunNode {
node = NewNodeServer(n)
}

s := NewNonBlockingGRPCServer()
s.Start(n.endpoint,
NewIdentityServer(n),
controller,
node)
s.Wait()

stopChan := make(chan os.Signal)
signal.Notify(stopChan, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
Expand All @@ -114,8 +129,10 @@ func (n *SeaweedFsDriver) Run() {
s.Stop()
s.Wait()

glog.Infof("node cleanup")
node.NodeCleanup()
if node != nil {
glog.Infof("node cleanup")
node.NodeCleanup()
}

glog.Infof("stopped")
}
Expand Down

0 comments on commit a5a2c63

Please sign in to comment.