m/node/kubernetes: fix attaching block PVs

Attaching a block PV to a container failed with the error:
"failed to create device node at target path: file exists".
This happened because there was already a directory at the path.
The directory should only be created for mounts, not for block devices.

I also extended the PV end-to-end test to add a block volume, and check
that it can be opened as a block device and has the expected size.

Change-Id: I40ca82cfcbfee1cb3196a900423f967b45790a64
Reviewed-on: https://review.monogon.dev/c/monogon/+/3623
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/node/kubernetes/csi.go b/metropolis/node/kubernetes/csi.go
index eb43ec0..40d54d0 100644
--- a/metropolis/node/kubernetes/csi.go
+++ b/metropolis/node/kubernetes/csi.go
@@ -101,11 +101,12 @@
 	default:
 		return nil, status.Error(codes.InvalidArgument, "unsupported access mode")
 	}
-	if err := os.MkdirAll(req.TargetPath, 0700); err != nil {
-		return nil, status.Errorf(codes.Internal, "unable to create requested target path: %v", err)
-	}
 	switch req.VolumeCapability.AccessType.(type) {
 	case *csi.VolumeCapability_Mount:
+		if err := os.MkdirAll(req.TargetPath, 0700); err != nil {
+			return nil, status.Errorf(codes.Internal, "unable to create requested target path: %v", err)
+		}
+
 		var mountFlags uintptr = unix.MS_BIND
 		if req.Readonly {
 			mountFlags |= unix.MS_RDONLY