From 21e23d1597320ab504f4e88be7e60187aba48881 Mon Sep 17 00:00:00 2001 From: Viktor Kuzmin Date: Tue, 8 Aug 2023 09:35:32 +0300 Subject: [PATCH] Refactor options to be backward compatible, fixes #133 --- cmd/seaweedfs-csi-driver/main.go | 30 +++++++++++++++---- .../templates/daemonset.yaml | 2 +- .../templates/deployment.yaml | 6 ++-- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/cmd/seaweedfs-csi-driver/main.go b/cmd/seaweedfs-csi-driver/main.go index eac42ec..566f6dd 100644 --- a/cmd/seaweedfs-csi-driver/main.go +++ b/cmd/seaweedfs-csi-driver/main.go @@ -4,6 +4,7 @@ import ( "fmt" "log" "os" + "strings" "github.com/seaweedfs/seaweedfs-csi-driver/pkg/datalocality" "github.com/seaweedfs/seaweedfs-csi-driver/pkg/driver" @@ -12,9 +13,8 @@ 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") + components = flag.String("components", "controller,node", "components to run, by default both controller and node") + enableAttacher = flag.Bool("attacher", true, "enable attacher, by default enabled for backward compatibility") filer = flag.String("filer", "localhost:8888", "filer server") endpoint = flag.String("endpoint", "unix://tmp/seaweedfs-csi.sock", "CSI endpoint to accept gRPC calls") @@ -55,12 +55,32 @@ func main() { os.Exit(1) } + runNode := false + runController := false + for _, c := range strings.Split(*components, ",") { + switch c { + case "controller": + runController = true + case "noe": + runNode = true + default: + glog.Errorf("invalid component %s", c) + os.Exit(1) + } + } + + glog.Infof("will run node: %v, controller: %v, attacher: %v", runNode, runController, *enableAttacher) + if !runNode && !runController { + glog.Errorf("at least one component should be enabled: either controller or node (use --components=...)") + os.Exit(1) + } + glog.Infof("connect to filer %s", *filer) drv := driver.NewSeaweedFsDriver(*filer, *nodeID, *endpoint, *enableAttacher) - drv.RunNode = *runNode - drv.RunController = *runController + drv.RunNode = runNode + drv.RunController = runController drv.ConcurrentWriters = *concurrentWriters drv.CacheCapacityMB = *cacheCapacityMB diff --git a/deploy/helm/seaweedfs-csi-driver/templates/daemonset.yaml b/deploy/helm/seaweedfs-csi-driver/templates/daemonset.yaml index 23738d2..e71b4df 100644 --- a/deploy/helm/seaweedfs-csi-driver/templates/daemonset.yaml +++ b/deploy/helm/seaweedfs-csi-driver/templates/daemonset.yaml @@ -45,7 +45,7 @@ spec: {{- if .Values.node.injectTopologyInfoFromNodeLabel.enabled }} - --dataCenter=$(DATACENTER) {{- end }} - - --node + - --components=node env: - name: CSI_ENDPOINT value: unix:///csi/csi.sock diff --git a/deploy/helm/seaweedfs-csi-driver/templates/deployment.yaml b/deploy/helm/seaweedfs-csi-driver/templates/deployment.yaml index 846a92a..96cd561 100644 --- a/deploy/helm/seaweedfs-csi-driver/templates/deployment.yaml +++ b/deploy/helm/seaweedfs-csi-driver/templates/deployment.yaml @@ -44,10 +44,8 @@ spec: - --endpoint=$(CSI_ENDPOINT) - --filer=$(SEAWEEDFS_FILER) - --nodeid=$(NODE_ID)" - - --controller - {{- if .Values.csiAttacher.enabled }} - - --attacher - {{- end }} + - --components=controller + - --attacher={{ .Values.csiAttacher.enabled }} env: - name: CSI_ENDPOINT value: unix:///var/lib/csi/sockets/pluginproxy/csi.sock