Skip to content

Commit

Permalink
Make parameter pool optional in CephFS storageclass
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel-Pivonka <dpivonka@redhat.com>
  • Loading branch information
Daniel-Pivonka authored and mergify[bot] committed Aug 7, 2019
1 parent 5b461a0 commit 0063727
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/deploy-cephfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ is used to define in which namespace you want the configmaps to be stored
| `clusterID` | yes | String representing a Ceph cluster, must be unique across all Ceph clusters in use for provisioning, cannot be greater than 36 bytes in length, and should remain immutable for the lifetime of the Ceph cluster in use |
| `fsName` | yes | CephFS filesystem name into which the volume shall be created |
| `mounter` | no | Mount method to be used for this volume. Available options are `kernel` for Ceph kernel client and `fuse` for Ceph FUSE driver. Defaults to "default mounter", see command line arguments. |
| `pool` | yes | Ceph pool into which the volume shall be created |
| `pool` | no | Ceph pool into which volume data shall be stored |
| `csi.storage.k8s.io/provisioner-secret-name`, `csi.storage.k8s.io/node-stage-secret-name` | for Kubernetes | Name of the Kubernetes Secret object containing Ceph client credentials. Both parameters should have the same value |
| `csi.storage.k8s.io/provisioner-secret-namespace`, `csi.storage.k8s.io/node-stage-secret-namespace` | for Kubernetes | Namespaces of the above Secret objects |

Expand Down
9 changes: 8 additions & 1 deletion e2e/cephfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ var _ = Describe("cephfs", func() {
createFileSystem(f.ClientSet)
createConfigMap(cephfsDirPath, f.ClientSet, f)
deployCephfsPlugin()
createCephfsStorageClass(f.ClientSet, f)
createCephfsSecret(f.ClientSet, f)
})

Expand Down Expand Up @@ -85,6 +84,14 @@ var _ = Describe("cephfs", func() {
Fail(err.Error())
}

By("create a storage class with pool and a PVC then Bind it to an app", func() {
createCephfsStorageClass(f.ClientSet, f, true)
validatePVCAndAppBinding(pvcPath, appPath, f)
deleteResource(cephfsExamplePath + "storageclass.yaml")
})

createCephfsStorageClass(f.ClientSet, f, false)

By("create and delete a PVC", func() {
By("create a PVC and Bind it to an app", func() {
validatePVCAndAppBinding(pvcPath, appPath, f)
Expand Down
6 changes: 4 additions & 2 deletions e2e/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,13 @@ func getSnapshot(path string) v1alpha1.VolumeSnapshot {
return sc
}

func createCephfsStorageClass(c kubernetes.Interface, f *framework.Framework) {
func createCephfsStorageClass(c kubernetes.Interface, f *framework.Framework, enablePool bool) {
scPath := fmt.Sprintf("%s/%s", cephfsExamplePath, "storageclass.yaml")
sc := getStorageClass(scPath)
sc.Parameters["pool"] = "myfs-data0"
sc.Parameters["fsName"] = "myfs"
if enablePool {
sc.Parameters["pool"] = "myfs-data0"
}
opt := metav1.ListOptions{
LabelSelector: "app=rook-ceph-tools",
}
Expand Down
4 changes: 2 additions & 2 deletions examples/cephfs/storageclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ parameters:
# CephFS filesystem name into which the volume shall be created
fsName: myfs

# Ceph pool into which the volume shall be created
pool: cephfs_data
# (optional) Ceph pool into which volume data shall be stored
# pool: cephfs_data

# The secrets have to contain user and/or Ceph admin credentials.
csi.storage.k8s.io/provisioner-secret-name: csi-cephfs-secret
Expand Down
18 changes: 13 additions & 5 deletions pkg/cephfs/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ func createVolume(volOptions *volumeOptions, cr *util.Credentials, volID volumeI
klog.V(4).Infof("cephfs: created subvolume group csi")
cephfsInit = true
}
err := execCommandErr(
"ceph",

args := []string{
"fs",
"subvolume",
"create",
Expand All @@ -104,12 +104,20 @@ func createVolume(volOptions *volumeOptions, cr *util.Credentials, volID volumeI
strconv.FormatInt(bytesQuota, 10),
"--group_name",
csiSubvolumeGroup,
"--pool_layout", volOptions.Pool,
"--mode", "777",
"-m", volOptions.Monitors,
"-c", util.CephConfigPath,
"-n", cephEntityClientPrefix+cr.ID,
"--keyfile="+cr.KeyFile)
"-n", cephEntityClientPrefix + cr.ID,
"--keyfile=" + cr.KeyFile,
}

if volOptions.Pool != "" {
args = append(args, "--pool_layout", volOptions.Pool)
}

err := execCommandErr(
"ceph",
args[:]...)
if err != nil {
klog.Errorf("failed to create subvolume %s(%s) in fs %s", string(volID), err, volOptions.FsName)
return err
Expand Down
4 changes: 2 additions & 2 deletions pkg/cephfs/volumeoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func newVolumeOptions(requestName string, size int64, volOptions, secret map[str
return nil, err
}

if err = extractOption(&opts.Pool, "pool", volOptions); err != nil {
if err = extractOptionalOption(&opts.Pool, "pool", volOptions); err != nil {
return nil, err
}

Expand Down Expand Up @@ -218,7 +218,7 @@ func newVolumeOptionsFromVolID(volID string, volOpt, secrets map[string]string)
}

if volOpt != nil {
if err = extractOption(&volOptions.Pool, "pool", volOpt); err != nil {
if err = extractOptionalOption(&volOptions.Pool, "pool", volOpt); err != nil {
return nil, nil, err
}

Expand Down

0 comments on commit 0063727

Please sign in to comment.