util: add CSIDriver.GetInstanceID()

There has been some confusion about using different variables for the
InstanceID of the RBD-driver. By removing the global variable
CSIInstanceID, there should be no confusion anymore what variable to
use.

Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
Niels de Vos 2024-08-02 15:19:02 +02:00 committed by mergify[bot]
parent 0092a47586
commit dfb48bac17
9 changed files with 36 additions and 24 deletions

View File

@ -70,8 +70,8 @@ func init() {
flag.StringVar(&conf.StagingPath, "stagingpath", defaultStagingPath, "staging path") flag.StringVar(&conf.StagingPath, "stagingpath", defaultStagingPath, "staging path")
flag.StringVar(&conf.ClusterName, "clustername", "", "name of the cluster") flag.StringVar(&conf.ClusterName, "clustername", "", "name of the cluster")
flag.BoolVar(&conf.SetMetadata, "setmetadata", false, "set metadata on the volume") flag.BoolVar(&conf.SetMetadata, "setmetadata", false, "set metadata on the volume")
flag.StringVar(&conf.InstanceID, "instanceid", "", "Unique ID distinguishing this instance of Ceph CSI among other"+ flag.StringVar(&conf.InstanceID, "instanceid", "default", "Unique ID distinguishing this instance of Ceph-CSI"+
" instances, when sharing Ceph clusters across CSI instances for provisioning") " among other instances, when sharing Ceph clusters across CSI instances for provisioning")
flag.IntVar(&conf.PidLimit, "pidlimit", 0, "the PID limit to configure through cgroups") flag.IntVar(&conf.PidLimit, "pidlimit", 0, "the PID limit to configure through cgroups")
flag.BoolVar(&conf.IsControllerServer, "controllerserver", false, "start cephcsi controller server") flag.BoolVar(&conf.IsControllerServer, "controllerserver", false, "start cephcsi controller server")
flag.BoolVar(&conf.IsNodeServer, "nodeserver", false, "start cephcsi node server") flag.BoolVar(&conf.IsNodeServer, "nodeserver", false, "start cephcsi node server")
@ -249,6 +249,7 @@ func main() {
DriverName: dname, DriverName: dname,
Namespace: conf.DriverNamespace, Namespace: conf.DriverNamespace,
ClusterName: conf.ClusterName, ClusterName: conf.ClusterName,
InstanceID: conf.InstanceID,
SetMetadata: conf.SetMetadata, SetMetadata: conf.SetMetadata,
} }
// initialize all controllers before starting. // initialize all controllers before starting.

View File

@ -39,6 +39,7 @@ type Config struct {
DriverName string DriverName string
Namespace string Namespace string
ClusterName string ClusterName string
InstanceID string
SetMetadata bool SetMetadata bool
} }

View File

@ -189,6 +189,7 @@ func (r *ReconcilePersistentVolume) reconcilePV(ctx context.Context, obj runtime
requestName, requestName,
pvcNamespace, pvcNamespace,
r.config.ClusterName, r.config.ClusterName,
r.config.InstanceID,
r.config.SetMetadata, r.config.SetMetadata,
cr) cr)
if err != nil { if err != nil {

View File

@ -30,6 +30,11 @@ type CSIDriver struct {
name string name string
nodeID string nodeID string
version string version string
// instance is the instance ID that is unique to an instance of CSI, used when sharing
// ceph clusters across CSI instances, to differentiate omap names per CSI instance.
instance string
// topology constraints that this nodeserver will advertise // topology constraints that this nodeserver will advertise
topology map[string]string topology map[string]string
capabilities []*csi.ControllerServiceCapability capabilities []*csi.ControllerServiceCapability
@ -40,7 +45,7 @@ type CSIDriver struct {
// NewCSIDriver Creates a NewCSIDriver object. Assumes vendor // NewCSIDriver Creates a NewCSIDriver object. Assumes vendor
// version is equal to driver version & does not support optional // version is equal to driver version & does not support optional
// driver plugin info manifest field. Refer to CSI spec for more details. // driver plugin info manifest field. Refer to CSI spec for more details.
func NewCSIDriver(name, v, nodeID string) *CSIDriver { func NewCSIDriver(name, v, nodeID, instance string) *CSIDriver {
if name == "" { if name == "" {
klog.Errorf("Driver name missing") klog.Errorf("Driver name missing")
@ -59,15 +64,27 @@ func NewCSIDriver(name, v, nodeID string) *CSIDriver {
return nil return nil
} }
if instance == "" {
klog.Errorf("Instance argument missing")
return nil
}
driver := CSIDriver{ driver := CSIDriver{
name: name, name: name,
version: v, version: v,
nodeID: nodeID, nodeID: nodeID,
instance: instance,
} }
return &driver return &driver
} }
// GetInstance returns the instance identification of the CSI driver.
func (d *CSIDriver) GetInstanceID() string {
return d.instance
}
// ValidateControllerServiceRequest validates the controller // ValidateControllerServiceRequest validates the controller
// plugin capabilities. // plugin capabilities.
func (d *CSIDriver) ValidateControllerServiceRequest(c csi.ControllerServiceCapability_RPC_Type) error { func (d *CSIDriver) ValidateControllerServiceRequest(c csi.ControllerServiceCapability_RPC_Type) error {

View File

@ -45,8 +45,8 @@ type Server struct {
// NewControllerServer initialize a controller server for ceph CSI driver. // NewControllerServer initialize a controller server for ceph CSI driver.
func NewControllerServer(d *csicommon.CSIDriver) *Server { func NewControllerServer(d *csicommon.CSIDriver) *Server {
// global instance of the volume journal, yuck // global instance of the volume journal, yuck
store.VolJournal = journal.NewCSIVolumeJournalWithNamespace(cephfs.CSIInstanceID, fsutil.RadosNamespace) store.VolJournal = journal.NewCSIVolumeJournalWithNamespace(d.GetInstanceID(), fsutil.RadosNamespace)
store.SnapJournal = journal.NewCSISnapshotJournalWithNamespace(cephfs.CSIInstanceID, fsutil.RadosNamespace) store.SnapJournal = journal.NewCSISnapshotJournalWithNamespace(d.GetInstanceID(), fsutil.RadosNamespace)
return &Server{ return &Server{
backendServer: cephfs.NewControllerServer(d), backendServer: cephfs.NewControllerServer(d),

View File

@ -39,7 +39,7 @@ func NewDriver() *Driver {
// ceph CSI driver which can serve multiple parallel requests. // ceph CSI driver which can serve multiple parallel requests.
func (fs *Driver) Run(conf *util.Config) { func (fs *Driver) Run(conf *util.Config) {
// Initialize default library driver // Initialize default library driver
cd := csicommon.NewCSIDriver(conf.DriverName, util.DriverVersion, conf.NodeID) cd := csicommon.NewCSIDriver(conf.DriverName, util.DriverVersion, conf.NodeID, conf.InstanceID)
if cd == nil { if cd == nil {
log.FatalLogMsg("failed to initialize CSI driver") log.FatalLogMsg("failed to initialize CSI driver")
} }

View File

@ -100,7 +100,7 @@ func (r *Driver) Run(conf *util.Config) {
rbd.InitJournals(conf.InstanceID) rbd.InitJournals(conf.InstanceID)
// Initialize default library driver // Initialize default library driver
r.cd = csicommon.NewCSIDriver(conf.DriverName, util.DriverVersion, conf.NodeID) r.cd = csicommon.NewCSIDriver(conf.DriverName, util.DriverVersion, conf.NodeID, conf.InstanceID)
if r.cd == nil { if r.cd == nil {
log.FatalLogMsg("Failed to initialize CSI Driver.") log.FatalLogMsg("Failed to initialize CSI Driver.")
} }
@ -217,7 +217,7 @@ func (r *Driver) setupCSIAddonsServer(conf *util.Config) error {
fcs := casrbd.NewFenceControllerServer() fcs := casrbd.NewFenceControllerServer()
r.cas.RegisterService(fcs) r.cas.RegisterService(fcs)
rcs := casrbd.NewReplicationServer(rbd.CSIInstanceID, NewControllerServer(r.cd)) rcs := casrbd.NewReplicationServer(conf.InstanceID, NewControllerServer(r.cd))
r.cas.RegisterService(rcs) r.cas.RegisterService(rcs)
vgcs := casrbd.NewVolumeGroupServer(conf.InstanceID) vgcs := casrbd.NewVolumeGroupServer(conf.InstanceID)

View File

@ -23,10 +23,6 @@ import (
) )
var ( var (
// CSIInstanceID is the instance ID that is unique to an instance of CSI, used when sharing
// ceph clusters across CSI instances, to differentiate omap names per CSI instance.
CSIInstanceID = "default"
// volJournal and snapJournal are used to maintain RADOS based journals for CO generated // volJournal and snapJournal are used to maintain RADOS based journals for CO generated
// VolumeName to backing RBD images. // VolumeName to backing RBD images.
volJournal *journal.Config volJournal *journal.Config
@ -91,11 +87,6 @@ func SetGlobalBool(name string, value bool) {
// NodeService where appropriate. Using global journals limits the ability to // NodeService where appropriate. Using global journals limits the ability to
// configure these options based on the Ceph cluster or StorageClass. // configure these options based on the Ceph cluster or StorageClass.
func InitJournals(instance string) { func InitJournals(instance string) {
// Use passed in instance ID, if provided for omap suffix naming volJournal = journal.NewCSIVolumeJournal(instance)
if instance != "" { snapJournal = journal.NewCSISnapshotJournal(instance)
CSIInstanceID = instance
}
volJournal = journal.NewCSIVolumeJournal(CSIInstanceID)
snapJournal = journal.NewCSISnapshotJournal(CSIInstanceID)
} }

View File

@ -547,7 +547,8 @@ func RegenerateJournal(
volumeID, volumeID,
requestName, requestName,
owner, owner,
clusterName string, clusterName,
instanceID string,
setMetadata bool, setMetadata bool,
cr *util.Credentials, cr *util.Credentials,
) (string, error) { ) (string, error) {
@ -595,7 +596,7 @@ func RegenerateJournal(
if rbdVol.JournalPool == "" { if rbdVol.JournalPool == "" {
rbdVol.JournalPool = rbdVol.Pool rbdVol.JournalPool = rbdVol.Pool
} }
volJournal = journal.NewCSIVolumeJournal(CSIInstanceID) volJournal = journal.NewCSIVolumeJournal(instanceID)
j, err := volJournal.Connect(rbdVol.Monitors, rbdVol.RadosNamespace, cr) j, err := volJournal.Connect(rbdVol.Monitors, rbdVol.RadosNamespace, cr)
if err != nil { if err != nil {
return "", err return "", err