Skip to content

Commit

Permalink
cleanup: rename csiID to driverInstance
Browse files Browse the repository at this point in the history
The attribute and variable `csiID` ise used for at least two different
things:

 - name of the driver instance, used for journalling metadata
 - objects of the CSIIdentifier struct, composing a volume-handle

By changing the name of the `csiID` attribute for driver instances to
`driverInstance`, any confusion should be prevented.

Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic committed Jan 24, 2025
1 parent 7ea6944 commit 3f4b385
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
12 changes: 6 additions & 6 deletions internal/csi-addons/rbd/encryptionkeyrotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ import (

type EncryptionKeyRotationServer struct {
*ekr.UnimplementedEncryptionKeyRotationControllerServer
driver string
volLock *util.VolumeLocks
driverInstance string
volLock *util.VolumeLocks
}

func NewEncryptionKeyRotationServer(driver string, volLock *util.VolumeLocks) *EncryptionKeyRotationServer {
func NewEncryptionKeyRotationServer(driverInstance string, volLock *util.VolumeLocks) *EncryptionKeyRotationServer {
return &EncryptionKeyRotationServer{
driver: driver,
volLock: volLock,
driverInstance: driverInstance,
volLock: volLock,
}
}

Expand All @@ -62,7 +62,7 @@ func (ekrs *EncryptionKeyRotationServer) EncryptionKeyRotate(
}
defer ekrs.volLock.Release(volID)

mgr := rbd.NewManager(ekrs.driver, nil, req.GetSecrets())
mgr := rbd.NewManager(ekrs.driverInstance, nil, req.GetSecrets())
defer mgr.Destroy(ctx)

rbdVol, err := mgr.GetVolumeByID(ctx, volID)
Expand Down
15 changes: 9 additions & 6 deletions internal/csi-addons/rbd/reclaimspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ import (
type ReclaimSpaceControllerServer struct {
*rs.UnimplementedReclaimSpaceControllerServer

driver string
volumeLocks *util.VolumeLocks
driverInstance string
volumeLocks *util.VolumeLocks
}

// NewReclaimSpaceControllerServer creates a new ReclaimSpaceControllerServer which handles
// the ReclaimSpace Service requests from the CSI-Addons specification.
func NewReclaimSpaceControllerServer(driver string, volumeLocks *util.VolumeLocks) *ReclaimSpaceControllerServer {
func NewReclaimSpaceControllerServer(
driverInstance string,
volumeLocks *util.VolumeLocks,
) *ReclaimSpaceControllerServer {
return &ReclaimSpaceControllerServer{
driver: driver,
volumeLocks: volumeLocks,
driverInstance: driverInstance,
volumeLocks: volumeLocks,
}
}

Expand All @@ -71,7 +74,7 @@ func (rscs *ReclaimSpaceControllerServer) ControllerReclaimSpace(
}
defer rscs.volumeLocks.Release(volumeID)

mgr := rbdutil.NewManager(rscs.driver, nil, req.GetSecrets())
mgr := rbdutil.NewManager(rscs.driverInstance, nil, req.GetSecrets())
defer mgr.Destroy(ctx)

rbdVol, err := mgr.GetVolumeByID(ctx, volumeID)
Expand Down
18 changes: 9 additions & 9 deletions internal/csi-addons/rbd/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ type ReplicationServer struct {
*replication.UnimplementedControllerServer
// Embed ControllerServer as it implements helper functions
*corerbd.ControllerServer
// csiID is the unique ID for this CSI-driver deployment.
csiID string
// driverInstance is the unique ID for this CSI-driver deployment.
driverInstance string
}

// NewReplicationServer creates a new ReplicationServer which handles
// the Replication Service requests from the CSI-Addons specification.
func NewReplicationServer(instanceID string, c *corerbd.ControllerServer) *ReplicationServer {
return &ReplicationServer{
ControllerServer: c,
csiID: instanceID,
driverInstance: instanceID,
}
}

Expand Down Expand Up @@ -277,7 +277,7 @@ func (rs *ReplicationServer) EnableVolumeReplication(ctx context.Context,
}
defer rs.VolumeLocks.Release(volumeID)

mgr := rbd.NewManager(rs.csiID, req.GetParameters(), req.GetSecrets())
mgr := rbd.NewManager(rs.driverInstance, req.GetParameters(), req.GetSecrets())
defer mgr.Destroy(ctx)

rbdVol, err := mgr.GetVolumeByID(ctx, volumeID)
Expand Down Expand Up @@ -347,7 +347,7 @@ func (rs *ReplicationServer) DisableVolumeReplication(ctx context.Context,
}
defer rs.VolumeLocks.Release(volumeID)

mgr := rbd.NewManager(rs.csiID, req.GetParameters(), req.GetSecrets())
mgr := rbd.NewManager(rs.driverInstance, req.GetParameters(), req.GetSecrets())
defer mgr.Destroy(ctx)

rbdVol, err := mgr.GetVolumeByID(ctx, volumeID)
Expand Down Expand Up @@ -415,7 +415,7 @@ func (rs *ReplicationServer) PromoteVolume(ctx context.Context,
}
defer rs.VolumeLocks.Release(volumeID)

mgr := rbd.NewManager(rs.csiID, req.GetParameters(), req.GetSecrets())
mgr := rbd.NewManager(rs.driverInstance, req.GetParameters(), req.GetSecrets())
defer mgr.Destroy(ctx)

rbdVol, err := mgr.GetVolumeByID(ctx, volumeID)
Expand Down Expand Up @@ -508,7 +508,7 @@ func (rs *ReplicationServer) DemoteVolume(ctx context.Context,
}
defer rs.VolumeLocks.Release(volumeID)

mgr := rbd.NewManager(rs.csiID, req.GetParameters(), req.GetSecrets())
mgr := rbd.NewManager(rs.driverInstance, req.GetParameters(), req.GetSecrets())
defer mgr.Destroy(ctx)

rbdVol, err := mgr.GetVolumeByID(ctx, volumeID)
Expand Down Expand Up @@ -618,7 +618,7 @@ func (rs *ReplicationServer) ResyncVolume(ctx context.Context,
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volumeID)
}
defer rs.VolumeLocks.Release(volumeID)
mgr := rbd.NewManager(rs.csiID, req.GetParameters(), req.GetSecrets())
mgr := rbd.NewManager(rs.driverInstance, req.GetParameters(), req.GetSecrets())
defer mgr.Destroy(ctx)

rbdVol, err := mgr.GetVolumeByID(ctx, volumeID)
Expand Down Expand Up @@ -827,7 +827,7 @@ func (rs *ReplicationServer) GetVolumeReplicationInfo(ctx context.Context,
return nil, status.Errorf(codes.Aborted, util.VolumeOperationAlreadyExistsFmt, volumeID)
}
defer rs.VolumeLocks.Release(volumeID)
mgr := rbd.NewManager(rs.csiID, nil, req.GetSecrets())
mgr := rbd.NewManager(rs.driverInstance, nil, req.GetSecrets())
defer mgr.Destroy(ctx)

rbdVol, err := mgr.GetVolumeByID(ctx, volumeID)
Expand Down
14 changes: 7 additions & 7 deletions internal/csi-addons/rbd/volumegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ type VolumeGroupServer struct {
// don't need to add all RPC methods leading to forward compatibility.
*volumegroup.UnimplementedControllerServer

// csiID is the unique ID for this CSI-driver deployment.
csiID string
// driverInstance is the unique ID for this CSI-driver deployment.
driverInstance string
}

// NewVolumeGroupServer creates a new VolumeGroupServer which handles the
// VolumeGroup Service requests from the CSI-Addons specification.
func NewVolumeGroupServer(instanceID string) *VolumeGroupServer {
return &VolumeGroupServer{
csiID: instanceID,
driverInstance: instanceID,
}
}

Expand Down Expand Up @@ -85,7 +85,7 @@ func (vs *VolumeGroupServer) CreateVolumeGroup(
ctx context.Context,
req *volumegroup.CreateVolumeGroupRequest,
) (*volumegroup.CreateVolumeGroupResponse, error) {
mgr := rbd.NewManager(vs.csiID, req.GetParameters(), req.GetSecrets())
mgr := rbd.NewManager(vs.driverInstance, req.GetParameters(), req.GetSecrets())
defer mgr.Destroy(ctx)

// resolve all volumes
Expand Down Expand Up @@ -188,7 +188,7 @@ func (vs *VolumeGroupServer) DeleteVolumeGroup(
ctx context.Context,
req *volumegroup.DeleteVolumeGroupRequest,
) (*volumegroup.DeleteVolumeGroupResponse, error) {
mgr := rbd.NewManager(vs.csiID, nil, req.GetSecrets())
mgr := rbd.NewManager(vs.driverInstance, nil, req.GetSecrets())
defer mgr.Destroy(ctx)

// resolve the volume group
Expand Down Expand Up @@ -285,7 +285,7 @@ func (vs *VolumeGroupServer) ModifyVolumeGroupMembership(
ctx context.Context,
req *volumegroup.ModifyVolumeGroupMembershipRequest,
) (*volumegroup.ModifyVolumeGroupMembershipResponse, error) {
mgr := rbd.NewManager(vs.csiID, nil, req.GetSecrets())
mgr := rbd.NewManager(vs.driverInstance, nil, req.GetSecrets())
defer mgr.Destroy(ctx)

// resolve the volume group
Expand Down Expand Up @@ -427,7 +427,7 @@ func (vs *VolumeGroupServer) ControllerGetVolumeGroup(
ctx context.Context,
req *volumegroup.ControllerGetVolumeGroupRequest,
) (*volumegroup.ControllerGetVolumeGroupResponse, error) {
mgr := rbd.NewManager(vs.csiID, nil, req.GetSecrets())
mgr := rbd.NewManager(vs.driverInstance, nil, req.GetSecrets())
defer mgr.Destroy(ctx)

// resolve the volume group
Expand Down
26 changes: 13 additions & 13 deletions internal/rbd/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
var _ types.Manager = &rbdManager{}

type rbdManager struct {
// csiID is the instance id of the CSI-driver (driver name).
csiID string
// driverInstance is the instance id of the CSI-driver (driver name).
driverInstance string
// parameters can contain the parameters of a create request.
parameters map[string]string
// secrets contain the credentials to connect to the Ceph cluster.
Expand All @@ -46,11 +46,11 @@ type rbdManager struct {

// NewManager returns a new manager for handling Volume and Volume Group
// operations, combining the requests for RBD and the journalling in RADOS.
func NewManager(csiID string, parameters, secrets map[string]string) types.Manager {
func NewManager(driverInstance string, parameters, secrets map[string]string) types.Manager {
return &rbdManager{
csiID: csiID,
parameters: parameters,
secrets: secrets,
driverInstance: driverInstance,
parameters: parameters,
secrets: secrets,
}
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func (mgr *rbdManager) getVolumeGroupJournal(clusterID string) (journal.VolumeGr
return nil, fmt.Errorf("failed to find the RADOS namespace for cluster %q: %w", clusterID, err)
}

vgJournalConfig := journal.NewCSIVolumeGroupJournalWithNamespace(mgr.csiID, ns)
vgJournalConfig := journal.NewCSIVolumeGroupJournalWithNamespace(mgr.driverInstance, ns)

vgJournal, err := vgJournalConfig.Connect(monitors, ns, creds)
if err != nil {
Expand Down Expand Up @@ -221,7 +221,7 @@ func (mgr *rbdManager) GetVolumeGroupByID(ctx context.Context, id string) (types
return nil, err
}

vg, err := rbd_group.GetVolumeGroup(ctx, id, mgr.csiID, creds, mgr)
vg, err := rbd_group.GetVolumeGroup(ctx, id, mgr.driverInstance, creds, mgr)
if err != nil {
return nil, fmt.Errorf("failed to get volume group with id %q: %w", id, err)
}
Expand Down Expand Up @@ -302,7 +302,7 @@ func (mgr *rbdManager) CreateVolumeGroup(ctx context.Context, name string) (type
return nil, fmt.Errorf("failed to generate a unique CSI volume group with uuid for %q: %w", uuid, err)
}

vg, err := rbd_group.GetVolumeGroup(ctx, csiID, mgr.csiID, creds, mgr)
vg, err := rbd_group.GetVolumeGroup(ctx, csiID, mgr.driverInstance, creds, mgr)
if err != nil {
return nil, fmt.Errorf("failed to get volume group %q at cluster %q: %w", name, clusterID, err)
}
Expand All @@ -329,7 +329,7 @@ func (mgr *rbdManager) GetVolumeGroupSnapshotByID(
return nil, err
}

vgs, err := rbd_group.GetVolumeGroupSnapshot(ctx, id, mgr.csiID, creds, mgr)
vgs, err := rbd_group.GetVolumeGroupSnapshot(ctx, id, mgr.driverInstance, creds, mgr)
if err != nil {
return nil, fmt.Errorf("failed to get volume group with id %q: %w", id, err)
}
Expand Down Expand Up @@ -382,7 +382,7 @@ func (mgr *rbdManager) GetVolumeGroupSnapshotByName(
return nil, fmt.Errorf("failed to generate a unique CSI volume group with uuid %q: %w", uuid, err)
}

vgs, err := rbd_group.GetVolumeGroupSnapshot(ctx, csiID, mgr.csiID, mgr.creds, mgr)
vgs, err := rbd_group.GetVolumeGroupSnapshot(ctx, csiID, mgr.driverInstance, mgr.creds, mgr)
if err != nil {
return nil, fmt.Errorf("failed to get existing volume group snapshot with uuid %q: %w", uuid, err)
}
Expand Down Expand Up @@ -445,7 +445,7 @@ func (mgr *rbdManager) CreateVolumeGroupSnapshot(
return nil, fmt.Errorf("failed to generate a unique CSI volume group with uuid for %q: %w", uuid, err)
}

vgs, err := rbd_group.GetVolumeGroupSnapshot(ctx, groupID, mgr.csiID, mgr.creds, mgr)
vgs, err := rbd_group.GetVolumeGroupSnapshot(ctx, groupID, mgr.driverInstance, mgr.creds, mgr)
if vgs != nil {
log.DebugLog(ctx, "found existing volume group snapshot %q for id %q", vgs, groupID)

Expand Down Expand Up @@ -494,7 +494,7 @@ func (mgr *rbdManager) CreateVolumeGroupSnapshot(

log.DebugLog(ctx, "volume group snapshot %q contains %d snapshots: %v", name, len(snapshots), snapshots)

vgs, err = rbd_group.NewVolumeGroupSnapshot(ctx, groupID, mgr.csiID, mgr.creds, snapshots)
vgs, err = rbd_group.NewVolumeGroupSnapshot(ctx, groupID, mgr.driverInstance, mgr.creds, snapshots)
if err != nil {
return nil, fmt.Errorf("failed to create new volume group snapshot %q: %w", name, err)
}
Expand Down

0 comments on commit 3f4b385

Please sign in to comment.