Skip to content

Commit 6ccc9e5

Browse files
committed
Make fstype configurable in external provisioner
At present the fstype is set to `ext4` if nothing is passed in storage-class. However a SP could prefer to have different fstype for many reasons for their driver/volumes. This patch enables SP who is using the external-provisioner to choose the default fstype which they want to have it. Fix# #328 Signed-off-by: Humble Chirammal <[email protected]>
1 parent 4aa560e commit 6ccc9e5

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

cmd/csi-provisioner/csi-provisioner.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ var (
7373
metricsAddress = flag.String("metrics-address", "", "The TCP network address where the prometheus metrics endpoint will listen (example: `:8080`). The default is empty string, which means metrics endpoint is disabled.")
7474
metricsPath = flag.String("metrics-path", "/metrics", "The HTTP path where prometheus metrics will be exposed. Default is `/metrics`.")
7575

76+
defaultFSType = flag.String("default-fstype", "ext4", "Specify the filesystem type of the volume. If not specified, external-provisioner will set default as `ext4`.")
77+
7678
featureGates map[string]bool
7779
provisionController *controller.ProvisionController
7880
version = "unknown"
@@ -224,6 +226,7 @@ func main() {
224226
csiNodeLister,
225227
nodeLister,
226228
*extraCreateMetadata,
229+
*defaultFSType,
227230
)
228231

229232
provisionController = controller.NewProvisionController(

pkg/controller/controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ const (
116116
backoffFactor = 1.2
117117
backoffSteps = 10
118118

119-
defaultFSType = "ext4"
120-
121119
snapshotKind = "VolumeSnapshot"
122120
snapshotAPIGroup = snapapi.GroupName // "snapshot.storage.k8s.io"
123121
pvcKind = "PersistentVolumeClaim" // Native types don't require an API group
@@ -208,6 +206,7 @@ type csiProvisioner struct {
208206
timeout time.Duration
209207
identity string
210208
volumeNamePrefix string
209+
defaultFSType string
211210
volumeNameUUIDLength int
212211
config *rest.Config
213212
driverName string
@@ -284,6 +283,7 @@ func NewCSIProvisioner(client kubernetes.Interface,
284283
csiNodeLister storagelistersv1beta1.CSINodeLister,
285284
nodeLister corelisters.NodeLister,
286285
extraCreateMetadata bool,
286+
defaultFSType string,
287287
) controller.Provisioner {
288288

289289
csiClient := csi.NewControllerClient(grpcClient)
@@ -295,6 +295,7 @@ func NewCSIProvisioner(client kubernetes.Interface,
295295
timeout: connectionTimeout,
296296
identity: identity,
297297
volumeNamePrefix: volumeNamePrefix,
298+
defaultFSType: defaultFSType,
298299
volumeNameUUIDLength: volumeNameUUIDLength,
299300
driverName: driverName,
300301
pluginCapabilities: pluginCapabilities,
@@ -496,7 +497,7 @@ func (p *csiProvisioner) ProvisionExt(options controller.ProvisionOptions) (*v1.
496497
return nil, controller.ProvisioningFinished, fmt.Errorf("fstype specified in parameters with both \"fstype\" and \"%s\" keys", prefixedFsTypeKey)
497498
}
498499
if len(fsType) == 0 {
499-
fsType = defaultFSType
500+
fsType = p.defaultFSType
500501
}
501502

502503
capacity := options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)]

pkg/controller/controller_test.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var (
6767

6868
driverNameAnnotation = map[string]string{annStorageProvisioner: driverName}
6969
translatedKey = "translated"
70+
defaultfsType = "ext4"
7071
)
7172

7273
type csiConnection struct {
@@ -405,7 +406,7 @@ func TestCreateDriverReturnsInvalidCapacityDuringProvision(t *testing.T) {
405406

406407
pluginCaps, controllerCaps := provisionCapabilities()
407408
csiProvisioner := NewCSIProvisioner(nil, 5*time.Second, "test-provisioner", "test",
408-
5, csiConn.conn, nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), nil, nil, nil, false)
409+
5, csiConn.conn, nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), nil, nil, nil, false, defaultfsType)
409410

410411
// Requested PVC with requestedBytes storage
411412
deletePolicy := v1.PersistentVolumeReclaimDelete
@@ -1662,7 +1663,7 @@ func runProvisionTest(t *testing.T, k string, tc provisioningTestcase, requested
16621663

16631664
pluginCaps, controllerCaps := provisionCapabilities()
16641665
csiProvisioner := NewCSIProvisioner(clientSet, 5*time.Second, "test-provisioner", "test", 5, csiConn.conn,
1665-
nil, provisionDriverName, pluginCaps, controllerCaps, supportsMigrationFromInTreePluginName, false, csitrans.New(), nil, nil, nil, tc.withExtraMetadata)
1666+
nil, provisionDriverName, pluginCaps, controllerCaps, supportsMigrationFromInTreePluginName, false, csitrans.New(), nil, nil, nil, tc.withExtraMetadata, defaultfsType)
16661667

16671668
out := &csi.CreateVolumeResponse{
16681669
Volume: &csi.Volume{
@@ -2398,7 +2399,7 @@ func TestProvisionFromSnapshot(t *testing.T) {
23982399

23992400
pluginCaps, controllerCaps := provisionFromSnapshotCapabilities()
24002401
csiProvisioner := NewCSIProvisioner(clientSet, 5*time.Second, "test-provisioner", "test", 5, csiConn.conn,
2401-
client, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), nil, nil, nil, false)
2402+
client, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), nil, nil, nil, false, defaultfsType)
24022403

24032404
out := &csi.CreateVolumeResponse{
24042405
Volume: &csi.Volume{
@@ -2572,7 +2573,7 @@ func TestProvisionWithTopologyEnabled(t *testing.T) {
25722573
defer close(stopChan)
25732574

25742575
csiProvisioner := NewCSIProvisioner(clientSet, 5*time.Second, "test-provisioner", "test", 5,
2575-
csiConn.conn, nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), scLister, csiNodeLister, nodeLister, false)
2576+
csiConn.conn, nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), scLister, csiNodeLister, nodeLister, false, defaultfsType)
25762577

25772578
pv, err := csiProvisioner.Provision(controller.ProvisionOptions{
25782579
StorageClass: &storagev1.StorageClass{},
@@ -2627,7 +2628,7 @@ func TestProvisionWithTopologyDisabled(t *testing.T) {
26272628
clientSet := fakeclientset.NewSimpleClientset()
26282629
pluginCaps, controllerCaps := provisionWithTopologyCapabilities()
26292630
csiProvisioner := NewCSIProvisioner(clientSet, 5*time.Second, "test-provisioner", "test", 5,
2630-
csiConn.conn, nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), nil, nil, nil, false)
2631+
csiConn.conn, nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), nil, nil, nil, false, defaultfsType)
26312632

26322633
out := &csi.CreateVolumeResponse{
26332634
Volume: &csi.Volume{
@@ -2799,7 +2800,7 @@ func runDeleteTest(t *testing.T, k string, tc deleteTestcase) {
27992800
pluginCaps, controllerCaps := provisionCapabilities()
28002801
scLister, _, _, _ := listers(clientSet)
28012802
csiProvisioner := NewCSIProvisioner(clientSet, 5*time.Second, "test-provisioner", "test", 5,
2802-
csiConn.conn, nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), scLister, nil, nil, false)
2803+
csiConn.conn, nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), scLister, nil, nil, false, defaultfsType)
28032804

28042805
err = csiProvisioner.Delete(tc.persistentVolume)
28052806
if tc.expectErr && err == nil {
@@ -3501,7 +3502,7 @@ func TestProvisionFromPVC(t *testing.T) {
35013502
}
35023503

35033504
csiProvisioner := NewCSIProvisioner(clientSet, 5*time.Second, "test-provisioner", "test", 5, csiConn.conn,
3504-
nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), nil, nil, nil, false)
3505+
nil, driverName, pluginCaps, controllerCaps, "", false, csitrans.New(), nil, nil, nil, false, defaultfsType)
35053506

35063507
pv, err := csiProvisioner.Provision(tc.volOpts)
35073508
if tc.expectErr && err == nil {
@@ -3580,7 +3581,7 @@ func TestProvisionWithMigration(t *testing.T) {
35803581
pluginCaps, controllerCaps := provisionCapabilities()
35813582
csiProvisioner := NewCSIProvisioner(clientSet, 5*time.Second, "test-provisioner",
35823583
"test", 5, csiConn.conn, nil, driverName, pluginCaps, controllerCaps,
3583-
inTreePluginName, false, mockTranslator, nil, nil, nil, false)
3584+
inTreePluginName, false, mockTranslator, nil, nil, nil, false, defaultfsType)
35843585

35853586
// Set up return values (AnyTimes to avoid overfitting on implementation)
35863587

@@ -3740,7 +3741,7 @@ func TestDeleteMigration(t *testing.T) {
37403741
pluginCaps, controllerCaps := provisionCapabilities()
37413742
csiProvisioner := NewCSIProvisioner(clientSet, 5*time.Second, "test-provisioner",
37423743
"test", 5, csiConn.conn, nil, driverName, pluginCaps, controllerCaps, "",
3743-
false, mockTranslator, nil, nil, nil, false)
3744+
false, mockTranslator, nil, nil, nil, false, defaultfsType)
37443745

37453746
// Set mock return values (AnyTimes to avoid overfitting on implementation details)
37463747
mockTranslator.EXPECT().IsPVMigratable(gomock.Any()).Return(tc.expectTranslation).AnyTimes()

0 commit comments

Comments
 (0)