journal: remove SetCSIDirectorySuffix to simplify journal creation

The function SetCSIDirectorySuffix was used only one per (long-lived,
gloabl) journal object. It is simpler to construct the journal objects
with this needed parameter:
1. As it is required to function and non-optional AFAICT
2. Removes the temptation to mutate global object
3. Reduces LOC with exact same functionality
4. SetCSIDirectorySuffix would not behave correctly if called a 2nd time
   anyway.

Point 4. means that if you called the function twice to change the
suffix when you previously had "csi.volumes.alice", you'd get
"csi.volumes.alice.bob" instead of "csi.volumes.bob" what one would
expect.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-05-11 17:21:30 -04:00 committed by mergify[bot]
parent b065726f19
commit 78a6de2bd0
3 changed files with 9 additions and 21 deletions

View File

@ -109,11 +109,8 @@ func (fs *Driver) Run(conf *util.Config, cachePersister util.CachePersister) {
if conf.InstanceID != "" { if conf.InstanceID != "" {
CSIInstanceID = conf.InstanceID CSIInstanceID = conf.InstanceID
} }
// Get an instance of the volume journal // Create an instance of the volume journal
volJournal = journal.NewCSIVolumeJournal() volJournal = journal.NewCSIVolumeJournal(CSIInstanceID)
// Update keys with CSI instance suffix
volJournal.SetCSIDirectorySuffix(CSIInstanceID)
// Update namespace for storing keys into a specific namespace on RADOS, in the CephFS // Update namespace for storing keys into a specific namespace on RADOS, in the CephFS
// metadata pool // metadata pool

View File

@ -147,9 +147,9 @@ type CSIJournal struct {
} }
// NewCSIVolumeJournal returns an instance of CSIJournal for volumes // NewCSIVolumeJournal returns an instance of CSIJournal for volumes
func NewCSIVolumeJournal() *CSIJournal { func NewCSIVolumeJournal(suffix string) *CSIJournal {
return &CSIJournal{ return &CSIJournal{
csiDirectory: "csi.volumes", csiDirectory: "csi.volumes." + suffix,
csiNameKeyPrefix: "csi.volume.", csiNameKeyPrefix: "csi.volume.",
cephUUIDDirectoryPrefix: "csi.volume.", cephUUIDDirectoryPrefix: "csi.volume.",
csiNameKey: "csi.volname", csiNameKey: "csi.volname",
@ -162,9 +162,9 @@ func NewCSIVolumeJournal() *CSIJournal {
} }
// NewCSISnapshotJournal returns an instance of CSIJournal for snapshots // NewCSISnapshotJournal returns an instance of CSIJournal for snapshots
func NewCSISnapshotJournal() *CSIJournal { func NewCSISnapshotJournal(suffix string) *CSIJournal {
return &CSIJournal{ return &CSIJournal{
csiDirectory: "csi.snaps", csiDirectory: "csi.snaps." + suffix,
csiNameKeyPrefix: "csi.snap.", csiNameKeyPrefix: "csi.snap.",
cephUUIDDirectoryPrefix: "csi.snap.", cephUUIDDirectoryPrefix: "csi.snap.",
csiNameKey: "csi.snapname", csiNameKey: "csi.snapname",
@ -188,11 +188,6 @@ func (cj *CSIJournal) GetNameForUUID(prefix, uid string, isSnapshot bool) string
return prefix + uid return prefix + uid
} }
// SetCSIDirectorySuffix sets the given suffix for the csiDirectory omap
func (cj *CSIJournal) SetCSIDirectorySuffix(suffix string) {
cj.csiDirectory = cj.csiDirectory + "." + suffix
}
// SetNamespace sets the namespace in which all RADOS objects would be created // SetNamespace sets the namespace in which all RADOS objects would be created
func (cj *CSIJournal) SetNamespace(ns string) { func (cj *CSIJournal) SetNamespace(ns string) {
cj.namespace = ns cj.namespace = ns

View File

@ -103,13 +103,9 @@ func (r *Driver) Run(conf *util.Config, cachePersister util.CachePersister) {
CSIInstanceID = conf.InstanceID CSIInstanceID = conf.InstanceID
} }
// Get an instance of the volume and snapshot journal keys // Create instances of the volume and snapshot journal
volJournal = journal.NewCSIVolumeJournal() volJournal = journal.NewCSIVolumeJournal(CSIInstanceID)
snapJournal = journal.NewCSISnapshotJournal() snapJournal = journal.NewCSISnapshotJournal(CSIInstanceID)
// Update keys with CSI instance suffix
volJournal.SetCSIDirectorySuffix(CSIInstanceID)
snapJournal.SetCSIDirectorySuffix(CSIInstanceID)
// 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)