Skip to content

Commit

Permalink
fix: Add support for prefixed fstype parameter (#71)
Browse files Browse the repository at this point in the history
* feat: Add support for prefixed fstype parameter

The old FsType parameter used for storageClasses has been deprecated
in favor of csi.storage.k8s.io/fstype, which is given special treatment
by the csi external-provisioner. Add support for this parameter and warn
if the deprecated version is being used
  • Loading branch information
David-T-White committed Mar 29, 2023
1 parent 7d64a67 commit ada6d02
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion example/storage-class.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ parameters:
csi.storage.k8s.io/controller-publish-secret-namespace: default
csi.storage.k8s.io/controller-expand-secret-name: seagate-exos-x-csi-secrets
csi.storage.k8s.io/controller-expand-secret-namespace: default
fsType: ext4 # Desired filesystem
csi.storage.k8s.io/fstype: ext4 # Desired filesystem
pool: A # Pool to use on the IQN to provision volumes
storageProtocol: iscsi # The storage interface (iscsi, fc, sas) being used for storage i/o
2 changes: 1 addition & 1 deletion example/storageclass-example1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ parameters:
csi.storage.k8s.io/controller-publish-secret-namespace: default
csi.storage.k8s.io/controller-expand-secret-name: seagate-exos-x-csi-secrets
csi.storage.k8s.io/controller-expand-secret-namespace: default
fsType: ext4 # Desired filesystem
csi.storage.k8s.io/fstype: ext4 # Desired filesystem
pool: A # Pool to use on the IQN to provision volumes
volPrefix: csi # Desired prefix for volume naming. 3 chars max; an underscore will be appended.
storageProtocol: iscsi # The storage interface (iscsi, fc, sas) being used for storage i/o
10 changes: 7 additions & 3 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,6 @@ func runPreflightChecks(parameters map[string]string, capabilities *[]*csi.Volum
return nil
}

if err := checkIfKeyExistsInConfig(common.FsTypeConfigKey); err != nil {
return err
}
if err := checkIfKeyExistsInConfig(common.PoolConfigKey); err != nil {
return err
}
Expand All @@ -290,6 +287,13 @@ func runPreflightChecks(parameters map[string]string, capabilities *[]*csi.Volum
if capability.GetAccessMode().GetMode() != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER {
return status.Error(codes.FailedPrecondition, "storage only supports ReadWriteOnce access mode")
}
if capability.GetMount().GetFsType() == "" {
if err := checkIfKeyExistsInConfig(common.FsTypeConfigKey); err != nil {
return status.Error(codes.FailedPrecondition, "no fstype specified in storage class")
} else {
klog.InfoS("storage class parameter "+common.FsTypeConfigKey+" is deprecated. Please migrate to 'csi.storage.k8s.io/fstype'", "parameter", common.FsTypeConfigKey)
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fcNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (fc *fcStorage) NodePublishVolume(ctx context.Context, req *csi.NodePublish
// check if previously unpublished devices were rediscovered by the scsi subsystem during Attach
checkPreviouslyRemovedDevices(ctx)

fsType := req.GetVolumeContext()[common.FsTypeConfigKey]
fsType := GetFsType(req)
err = EnsureFsType(fsType, path)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/iscsiNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (iscsi *iscsiStorage) NodePublishVolume(ctx context.Context, req *csi.NodeP
}
}

fsType := req.GetVolumeContext()[common.FsTypeConfigKey]
fsType := GetFsType(req)
err = EnsureFsType(fsType, path)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/sasNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (sas *sasStorage) NodePublishVolume(ctx context.Context, req *csi.NodePubli
// check if previously unpublished devices were rediscovered by the scsi subsystem during Attach
checkPreviouslyRemovedDevices(ctx)

fsType := req.GetVolumeContext()[common.FsTypeConfigKey]
fsType := GetFsType(req)
err = EnsureFsType(fsType, path)
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
Expand Down
9 changes: 9 additions & 0 deletions pkg/storage/storageService.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ func RemoveGatekeeper(volumeName string) {
gatekeepers.Unlock(volumeName)
}

// wrap the new FS type specification and fall back to the old parameter if necessary
func GetFsType(req *csi.NodePublishVolumeRequest) string {
fsType := ""
if fsType = req.GetVolumeCapability().GetMount().GetFsType(); fsType == "" {
fsType = req.GetVolumeContext()[common.FsTypeConfigKey]
}
return fsType
}

// CheckFs: Perform a file system validation
func CheckFs(path string, fstype string, context string) error {

Expand Down

0 comments on commit ada6d02

Please sign in to comment.