Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion internal/driver/nodeserver_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ func (ns *NodeServer) mountVolume(ctx context.Context, devicePath string, req *c

stagingTargetPath := req.GetStagingTargetPath()
volumeCapability := req.GetVolumeCapability()
volumeID := req.GetVolumeId()

volumeName, err := ns.getMountSource(ctx, volumeID)
if err != nil {
return errInternal("Failed to get volume name: %v", err)
}

// Retrieve the file system type and mount options from the volume capability
fsType, mountOptions := getFSTypeAndMountOptions(ctx, volumeCapability)
Expand All @@ -289,8 +295,8 @@ func (ns *NodeServer) mountVolume(ctx context.Context, devicePath string, req *c
// Check if LUKS encryption is enabled and prepare the LUKS volume if needed
luksContext := getLuksContext(req.GetSecrets(), req.GetVolumeContext(), VolumeLifecycleNodeStageVolume)
if luksContext.EncryptionEnabled {
var err error
log.V(4).Info("preparing luks volume", "devicePath", devicePath)
luksContext.VolumeName = volumeName
fmtAndMountSource, err = ns.formatLUKSVolume(ctx, devicePath, &luksContext)
if err != nil {
return err
Expand Down
12 changes: 10 additions & 2 deletions internal/driver/nodeserver_helpers_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestNodeServer_mountVolume_linux(t *testing.T) {
name: "Success - Mount the volume",
devicePath: "/tmp/test_success_noluks",
req: &csi.NodeStageVolumeRequest{
VolumeId: "test_success_noluks",
VolumeId: "123-test_success_noluks",
},
expectMounterCalls: func(m *mocks.MockMounter) {
m.EXPECT().MountSensitive("/tmp/test_success_noluks", "", "ext4", []string{"defaults"}, emptyStringArray).Return(nil)
Expand All @@ -52,7 +52,7 @@ func TestNodeServer_mountVolume_linux(t *testing.T) {
name: "Error - Unable to mount the volume",
devicePath: "/tmp/test_error_noluks",
req: &csi.NodeStageVolumeRequest{
VolumeId: "test_error_noluks",
VolumeId: "123-test_error_noluks",
},
expectMounterCalls: func(m *mocks.MockMounter) {
m.EXPECT().MountSensitive("/tmp/test_error_noluks", "", "ext4", []string{"defaults"}, emptyStringArray).Return(fmt.Errorf("Couldn't mount."))
Expand All @@ -68,6 +68,14 @@ func TestNodeServer_mountVolume_linux(t *testing.T) {
},
wantErr: true,
},
{
name: "Error - No volume ID",
devicePath: "/tmp/test_error_noluks",
req: &csi.NodeStageVolumeRequest{
VolumeId: "",
},
wantErr: true,
},
}

for _, tt := range tests {
Expand Down
13 changes: 7 additions & 6 deletions internal/driver/nodeserver_luks_encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

func TestNodeServer_mountVolume_luks(t *testing.T) {
var emptyStringArray []string
volumeID := "123-test"
tests := []struct {
name string
devicePath string
Expand All @@ -33,7 +34,7 @@ func TestNodeServer_mountVolume_luks(t *testing.T) {
name: "Success - mount LUKS volume",
devicePath: "/tmp/test",
req: &csi.NodeStageVolumeRequest{
VolumeId: "test",
VolumeId: volumeID,
VolumeContext: map[string]string{
LuksEncryptedAttribute: "true",
LuksCipherAttribute: "aes-xts-plain64",
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestNodeServer_mountVolume_luks(t *testing.T) {
name: "Success - already formatted",
devicePath: "/tmp/test",
req: &csi.NodeStageVolumeRequest{
VolumeId: "test",
VolumeId: volumeID,
VolumeContext: map[string]string{
LuksEncryptedAttribute: "true",
LuksCipherAttribute: "aes-xts-plain64",
Expand Down Expand Up @@ -114,7 +115,7 @@ func TestNodeServer_mountVolume_luks(t *testing.T) {
name: "Error - unable to initialize LUKS volume by path",
devicePath: "/tmp/test",
req: &csi.NodeStageVolumeRequest{
VolumeId: "test",
VolumeId: volumeID,
VolumeContext: map[string]string{
LuksEncryptedAttribute: "true",
LuksCipherAttribute: "aes-xts-plain64",
Expand All @@ -138,7 +139,7 @@ func TestNodeServer_mountVolume_luks(t *testing.T) {
name: "Error - unable to format LUKS volume",
devicePath: "/tmp/test",
req: &csi.NodeStageVolumeRequest{
VolumeId: "test",
VolumeId: volumeID,
VolumeContext: map[string]string{
LuksEncryptedAttribute: "true",
LuksCipherAttribute: "aes-xts-plain64",
Expand Down Expand Up @@ -166,7 +167,7 @@ func TestNodeServer_mountVolume_luks(t *testing.T) {
name: "Error - unable to add keyslot to LUKS volume",
devicePath: "/tmp/test",
req: &csi.NodeStageVolumeRequest{
VolumeId: "test",
VolumeId: volumeID,
VolumeContext: map[string]string{
LuksEncryptedAttribute: "true",
LuksCipherAttribute: "aes-xts-plain64",
Expand Down Expand Up @@ -195,7 +196,7 @@ func TestNodeServer_mountVolume_luks(t *testing.T) {
name: "Error - unable to activate LUKS volume",
devicePath: "/tmp/test",
req: &csi.NodeStageVolumeRequest{
VolumeId: "test",
VolumeId: volumeID,
VolumeContext: map[string]string{
LuksEncryptedAttribute: "true",
LuksCipherAttribute: "aes-xts-plain64",
Expand Down
Loading