Skip to content
This repository was archived by the owner on Aug 14, 2021. It is now read-only.

Commit

Permalink
Support fstype other then ext4 (#38)
Browse files Browse the repository at this point in the history
This commit will extend the provisioner to support
other filesystem i.e. XFS, ext3 etc. Ext4 will be the default fstype
for openebs volumes. But can be changed via storageclass parameter
key/value for example "openebs.io/fstype : xfs"


---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: openebs-percona
  provisioner: openebs.io/provisioner-iscsi
parameters:
  openebs.io/storage-pool: "default"
  openebs.io/jiva-replica-count: "1"
  openebs.io/volume-monitor: "true"
  openebs.io/capacity: 5G
  openebs.io/fstype: "xfs"
    ---

Also this PR adds OPENEBS_VALID_FSTYPE ENV config parameter

OPENEBS_VALID_FSTYPE can be exported as supported fstype for
openebs volume. This can be set as ENV in openebs-provisioner pod 
deployment.for example: OPENEBS_VALID_FSTYPE="ext3,btrfs,zfs"

Signed-off-by: prateekpandey14 <[email protected]>
  • Loading branch information
prateekpandey14 authored and kmova committed May 7, 2018
1 parent 4605b22 commit f95698c
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ install: true

before_script:
# Download kubectl, which is a requirement for using minikube.
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.7.5/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.4/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# Download minikube.
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
- sudo minikube start --vm-driver=none --kubernetes-version=v1.7.5
- sudo minikube start --vm-driver=none --bootstrapper=localkube --kubernetes-version=v1.9.4
# Fix the kubectl context, as it's often stale.
- minikube update-context
# Wait for Kubernetes to be up and ready.
Expand Down
50 changes: 49 additions & 1 deletion openebs/openebs-provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ const (
// BetaStorageClassAnnotation represents the beta/previous StorageClass annotation.
// It's currently still used and will be held for backwards compatibility
BetaStorageClassAnnotation = "volume.beta.kubernetes.io/storage-class"
//defaultFSType
defaultFSType = "ext4"
)

// validFSType represents the valid fstype supported by openebs volume
// New supported type can be added using OPENEBS_VALID_FSTYPE env
var validFSType = []string{"ext4", "xfs"}

type openEBSProvisioner struct {
// Maya-API Server URI running in the cluster
mapiURI string
Expand Down Expand Up @@ -164,6 +170,10 @@ func (p *openEBSProvisioner) Provision(options controller.VolumeOptions) (*v1.Pe
volAnnotations["alpha.dashboard.kubernetes.io/links"] = "{" + strings.Join(userLinks, ",") + "}"
}

fsType, err := parseClassParameters(options.Parameters)
if err != nil {
return nil, err
}
pv := &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: options.PVName,
Expand All @@ -180,7 +190,7 @@ func (p *openEBSProvisioner) Provision(options controller.VolumeOptions) (*v1.Pe
TargetPortal: targetPortal,
IQN: iqn,
Lun: 0,
FSType: "ext4",
FSType: fsType,
ReadOnly: false,
},
},
Expand Down Expand Up @@ -281,3 +291,41 @@ func GetStorageClassName(options controller.VolumeOptions) *string {
}
return options.PVC.Spec.StorageClassName
}

// parseClassParameters extract the new fstype other then "ext4"(dafault) which
// can be changed via "openebs.io/fstype" key and env OPENEBS_VALID_FSTYPE
func parseClassParameters(params map[string]string) (string, error) {
var fsType string
for k, v := range params {
switch strings.ToLower(k) {
case "openebs.io/fstype":
fsType = v
}
}
if len(fsType) == 0 {
fsType = defaultFSType
}

//Get openebs supported fstype from ENV variable
validENVFSType := os.Getenv("OPENEBS_VALID_FSTYPE")
if validENVFSType != "" {
slices := strings.Split(validENVFSType, ",")
for _, s := range slices {
validFSType = append(validFSType, s)
}
}
if !isValid(fsType, validFSType) {
return "", fmt.Errorf("Filesystem %s is not supported", fsType)
}
return fsType, nil
}

// isValid checks the validity of fstype returns true if supported
func isValid(value string, list []string) bool {
for _, v := range list {
if v == value {
return true
}
}
return false
}
104 changes: 104 additions & 0 deletions openebs/openebs-provisioner_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package main

import (
"fmt"
"os"
"reflect"
"testing"
)

func TestParseClassParameters(t *testing.T) {
cases := map[string]struct {
cfgs map[string]string
expectErr error
expectfstype string
}{
"Dafault fstype": {
cfgs: map[string]string{"openebs.io/fstype": ""},
expectErr: nil,
expectfstype: "ext4",
},
"ext4 fstype": {
cfgs: map[string]string{"openebs.io/fstype": "ext4"},
expectErr: nil,
expectfstype: "ext4",
},
"xfs fstype": {
cfgs: map[string]string{"openebs.io/fstype": "xfs"},
expectErr: nil,
expectfstype: "xfs",
},
"Invalid fstype": {
cfgs: map[string]string{"openebs.io/fstype": "nfs"},
expectErr: fmt.Errorf("Filesystem nfs is not supported"),
expectfstype: "",
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
fstype, err := parseClassParameters(tc.cfgs)
if !reflect.DeepEqual(err, tc.expectErr) {
t.Errorf("Expected %v, got %v", tc.expectErr, err)
}
if !reflect.DeepEqual(fstype, tc.expectfstype) {
t.Errorf("Expected %v, got %v", tc.expectfstype, fstype)
}
})
}
}

func TestParseClassENVParameters(t *testing.T) {
cases := map[string]struct {
cfgs map[string]string
expectErr error
expectfstype string
}{
"Dafault fstype": {
cfgs: map[string]string{"openebs.io/fstype": ""},
expectErr: nil,
expectfstype: "ext4",
},
"ext4 fstype": {
cfgs: map[string]string{"openebs.io/fstype": "ext4"},
expectErr: nil,
expectfstype: "ext4",
},
"ENV fstype nfs": {
cfgs: map[string]string{"openebs.io/fstype": "nfs"},
expectErr: nil,
expectfstype: "nfs",
},
"Invalid fstype": {
cfgs: map[string]string{"openebs.io/fstype": "abcd"},
expectErr: fmt.Errorf("Filesystem abcd is not supported"),
expectfstype: "",
},
"ENV fstype btrfs": {
cfgs: map[string]string{"openebs.io/fstype": "btrfs"},
expectErr: nil,
expectfstype: "btrfs",
},
"ENV fstype zfs": {
cfgs: map[string]string{"openebs.io/fstype": "zfs"},
expectErr: nil,
expectfstype: "zfs",
},
}

for name, tc := range cases {
t.Run(name, func(t *testing.T) {

os.Setenv("OPENEBS_VALID_FSTYPE", "nfs,btrfs,zfs")
defer os.Unsetenv("OPENEBS_VALID_FSTYPE")

fstype, err := parseClassParameters(tc.cfgs)
if !reflect.DeepEqual(err, tc.expectErr) {
t.Errorf("Expected %v, got %v", tc.expectErr, err)
}
if !reflect.DeepEqual(fstype, tc.expectfstype) {
t.Errorf("Expected %v, got %v", tc.expectfstype, fstype)
}
})
}
}

0 comments on commit f95698c

Please sign in to comment.