From 30af703a2fe7f3f2aa0bdca50bfa5054e0982d09 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Tue, 17 Nov 2020 13:08:54 +0530 Subject: [PATCH] rbd: add controller to main initialize and start the rbd controller when we the driver type is controller. Signed-off-by: Madhu Rajanna --- cmd/cephcsi.go | 33 +++++++++++++++++++++++++++++---- internal/util/util.go | 15 ++++++++------- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/cmd/cephcsi.go b/cmd/cephcsi.go index fd4769e0e..6b7d6dfe1 100644 --- a/cmd/cephcsi.go +++ b/cmd/cephcsi.go @@ -24,6 +24,8 @@ import ( "time" "github.com/ceph/ceph-csi/internal/cephfs" + "github.com/ceph/ceph-csi/internal/controller" + "github.com/ceph/ceph-csi/internal/controller/persistentvolume" "github.com/ceph/ceph-csi/internal/liveness" "github.com/ceph/ceph-csi/internal/rbd" "github.com/ceph/ceph-csi/internal/util" @@ -32,9 +34,10 @@ import ( ) const ( - rbdType = "rbd" - cephfsType = "cephfs" - livenessType = "liveness" + rbdType = "rbd" + cephfsType = "cephfs" + livenessType = "liveness" + controllerType = "controller" rbdDefaultName = "rbd.csi.ceph.com" cephfsDefaultName = "cephfs.csi.ceph.com" @@ -42,6 +45,9 @@ const ( pollTime = 60 // seconds probeTimeout = 3 // seconds + + // use default namespace if namespace is not set + defaultNS = "default" ) var ( @@ -50,9 +56,10 @@ var ( func init() { // common flags - flag.StringVar(&conf.Vtype, "type", "", "driver type [rbd|cephfs|liveness]") + flag.StringVar(&conf.Vtype, "type", "", "driver type [rbd|cephfs|liveness|controller]") flag.StringVar(&conf.Endpoint, "endpoint", "unix://tmp/csi.sock", "CSI endpoint") flag.StringVar(&conf.DriverName, "drivername", "", "name of the driver") + flag.StringVar(&conf.DriverNamespace, "drivernamespace", defaultNS, "namespace in which driver is deployed") flag.StringVar(&conf.NodeID, "nodeid", "", "node id") flag.StringVar(&conf.InstanceID, "instanceid", "", "Unique ID distinguishing this instance of Ceph CSI among other"+ " instances, when sharing Ceph clusters across CSI instances for provisioning") @@ -181,11 +188,29 @@ func main() { case livenessType: liveness.Run(&conf) + + case controllerType: + cfg := controller.Config{ + DriverName: dname, + Namespace: conf.DriverNamespace, + } + // initialize all controllers before starting. + initControllers() + err = controller.Start(cfg) + if err != nil { + logAndExit(err.Error()) + } } os.Exit(0) } +// initControllers will initialize all the controllers. +func initControllers() { + // Add list of controller here. + persistentvolume.Init() +} + func validateCloneDepthFlag(conf *util.Config) { // keeping hardlimit to 14 as max to avoid max image depth if conf.RbdHardMaxCloneDepth == 0 || conf.RbdHardMaxCloneDepth > 14 { diff --git a/internal/util/util.go b/internal/util/util.go index 24b8d6ed6..0c6c79046 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -68,13 +68,14 @@ var ( // Config holds the parameters list which can be configured. type Config struct { - Vtype string // driver type [rbd|cephfs|liveness] - Endpoint string // CSI endpoint - DriverName string // name of the driver - NodeID string // node id - InstanceID string // unique ID distinguishing this instance of Ceph CSI - PluginPath string // location of cephcsi plugin - DomainLabels string // list of domain labels to read from the node + Vtype string // driver type [rbd|cephfs|liveness|controller] + Endpoint string // CSI endpoint + DriverName string // name of the driver + DriverNamespace string // namespace in which driver is deployed + NodeID string // node id + InstanceID string // unique ID distinguishing this instance of Ceph CSI + PluginPath string // location of cephcsi plugin + DomainLabels string // list of domain labels to read from the node // metrics related flags MetricsPath string // path of prometheus endpoint where metrics will be available