Skip to content

Commit

Permalink
Add mkfs options parameter to volume context
Browse files Browse the repository at this point in the history
  • Loading branch information
sujeet01 committed Sep 24, 2024
1 parent 8138d73 commit e3160be
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o $(BINARY_NAME) -v ./cmd/

docker-build:
docker build $(BUILDARGS) -t ${IMG} -f Dockerfile .
docker build $(BUILDARGS) -t ${IMG} -f Dockerfile . --load

docker-push:
docker push ${IMG}
Expand Down
2 changes: 2 additions & 0 deletions pkg/driver/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const (
ParameterNodeID = "node_id"
// ParameterDeviceName is the device name parameter
ParameterDeviceName = "device_name"
// ParameterMkfsOptions is the name of the parameter used to specify the options for the mkfs command
ParameterMkfsOptions = "mkfs_options"

CSIDriverName = "csi.ironcore.dev"
topologyKey = "topology." + CSIDriverName + "/zone"
Expand Down
6 changes: 6 additions & 0 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func (d *driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
fstype = FSTypeExt4
}

mkfsOptions, ok := params[ParameterMkfsOptions]
if !ok {
mkfsOptions = ""
}

volumeClass, ok := params[ParameterType]
if !ok {
return nil, status.Errorf(codes.Internal, "Required parameter %s is missing", ParameterType)
Expand Down Expand Up @@ -136,6 +141,7 @@ func (d *driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
ParameterVolumePool: volumePoolName,
ParameterCreationTime: time.Unix(volume.CreationTimestamp.Unix(), 0).String(),
ParameterFSType: fstype,
ParameterMkfsOptions: mkfsOptions,
},
ContentSource: req.GetVolumeContentSource(),
AccessibleTopology: accessibleTopology,
Expand Down
16 changes: 12 additions & 4 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/container-storage-interface/spec/lib/go/csi"
"golang.org/x/sys/unix"
Expand All @@ -33,7 +34,8 @@ var (

func (d *driver) NodeStageVolume(_ context.Context, req *csi.NodeStageVolumeRequest) (*csi.NodeStageVolumeResponse, error) {
klog.InfoS("Staging volume on node ", "Volume", req.GetVolumeId(), "StagingTargetPath", req.GetStagingTargetPath())
fstype := req.GetVolumeContext()[ParameterFSType]
volumeContext := req.GetVolumeContext()
fstype := volumeContext[ParameterFSType]
devicePath := req.PublishContext[ParameterDeviceName]

klog.InfoS("Check if the device path exists")
Expand All @@ -47,7 +49,7 @@ func (d *driver) NodeStageVolume(_ context.Context, req *csi.NodeStageVolumeRequ
}

readOnly := false
if req.GetVolumeContext()["readOnly"] == "true" {
if volumeContext["readOnly"] == "true" {
readOnly = true
}
mountOptions := req.GetVolumeCapability().GetMount().GetMountFlags()
Expand All @@ -69,15 +71,21 @@ func (d *driver) NodeStageVolume(_ context.Context, req *csi.NodeStageVolumeRequ
}

var options []string

if readOnly {
options = append(options, "ro")
} else {
options = append(options, "rw")
}
options = append(options, mountOptions...)

var formatOptions []string
mkfsOptions, exists := volumeContext[ParameterMkfsOptions]
if exists && mkfsOptions != "" {
formatOptions = append(formatOptions, strings.Split(mkfsOptions, " ")...)
}

klog.InfoS("Format and mount the volume")
if err = d.mounter.FormatAndMount(devicePath, targetPath, fstype, options); err != nil {
if err = d.mounter.FormatAndMountSensitiveWithFormatOptions(devicePath, targetPath, fstype, options, nil, formatOptions); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to mount volume %s [%s] to %s: %v", devicePath, fstype, targetPath, err)
}
klog.InfoS("Staged volume on node", "Volume", req.GetVolumeId())
Expand Down
4 changes: 2 additions & 2 deletions pkg/driver/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ var _ = Describe("Node", func() {
It("should fail if the mount operation fails", func(ctx SpecContext) {
mockMounter.EXPECT().IsLikelyNotMountPoint(targetPath).Return(true, nil)
mockOS.EXPECT().MkdirAll(targetPath, os.FileMode(0750)).Return(nil)
mockMounter.EXPECT().FormatAndMount(devicePath, targetPath, fstype, mountOptions).Return(errors.New("failed to mount volume"))
mockMounter.EXPECT().FormatAndMountSensitiveWithFormatOptions(devicePath, targetPath, fstype, mountOptions, nil, nil).Return(errors.New("failed to mount volume"))
_, err := drv.NodeStageVolume(ctx, req)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("Failed to mount volume"))
Expand All @@ -126,7 +126,7 @@ var _ = Describe("Node", func() {
It("should stage the volume", func(ctx SpecContext) {
mockMounter.EXPECT().IsLikelyNotMountPoint(targetPath).Return(true, nil)
mockOS.EXPECT().MkdirAll(targetPath, os.FileMode(0750)).Return(nil)
mockMounter.EXPECT().FormatAndMount(devicePath, targetPath, fstype, mountOptions).Return(nil)
mockMounter.EXPECT().FormatAndMountSensitiveWithFormatOptions(devicePath, targetPath, fstype, mountOptions, nil, nil).Return(nil)
_, err := drv.NodeStageVolume(ctx, req)
Expect(err).NotTo(HaveOccurred())
})
Expand Down
12 changes: 6 additions & 6 deletions pkg/utils/mount/mock_mountutils_unix.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/utils/mount/mountutils_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
// SafeFormatAndMount). Defined it explicitly so that it can be mocked.
type MountWrapper interface {
k8smountutils.Interface
FormatAndMount(source string, target string, fstype string, options []string) error
FormatAndMountSensitiveWithFormatOptions(source string, target string, fstype string, options []string, sensitiveOptions []string, formatOptions []string) error
NewResizeFs() (Resizefs, error)
}

Expand Down

0 comments on commit e3160be

Please sign in to comment.