Skip to content

Commit

Permalink
csi: handle the case where 'kadalu' storageclass is used (#416)
Browse files Browse the repository at this point in the history
* csi: handle the case where 'kadalu' storageclass is used
* add test case of testing 'kadalu' as the storageclass

Fixes: #399
Signed-off-by: Amar Tumballi <amar@kadalu.io>
  • Loading branch information
amarts committed Jan 19, 2021
1 parent ca11822 commit d70fffe
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 13 deletions.
46 changes: 33 additions & 13 deletions csi/controllerserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging
import time
import random
import json

import grpc

Expand Down Expand Up @@ -80,8 +81,30 @@ def CreateVolume(self, request, context):
"Got list of hosting Volumes",
volumes=",".join(v['name'] for v in host_volumes)
))
hostvol = None
ext_volume = None
data = {}
hostvoltype = filters.get("hostvol_type", None)
if not hostvoltype:
# This means, the request came on 'kadalu' storage class type.

# Randomize the entries so we can issue PV from different storage
random.shuffle(host_volumes)

hostvol = mount_and_select_hosting_volume(host_volumes, pvsize)
if hostvol is None:
errmsg = "No Hosting Volumes available, add more storage"
logging.error(errmsg)
context.set_details(errmsg)
context.set_code(grpc.StatusCode.RESOURCE_EXHAUSTED)
return csi_pb2.CreateVolumeResponse()

info_file_path = os.path.join(VOLINFO_DIR, "%s.info" % hostvol)
with open(info_file_path) as info_file:
data = json.load(info_file)

hostvoltype = data['type']

if hostvoltype == 'External':
ext_volume = check_external_volume(request, host_volumes)

Expand Down Expand Up @@ -172,17 +195,17 @@ def CreateVolume(self, request, context):
context.set_code(grpc.StatusCode.INVALID_ARGUMENT)
return csi_pb2.CreateVolumeResponse()

if not hostvol:
# Randomize the entries so we can issue PV from different storage
random.shuffle(host_volumes)

# Randomize the entries so we can issue PV from different storage
random.shuffle(host_volumes)

hostvol = mount_and_select_hosting_volume(host_volumes, pvsize)
if hostvol is None:
errmsg = "No Hosting Volumes available, add more storage"
logging.error(errmsg)
context.set_details(errmsg)
context.set_code(grpc.StatusCode.RESOURCE_EXHAUSTED)
return csi_pb2.CreateVolumeResponse()
hostvol = mount_and_select_hosting_volume(host_volumes, pvsize)
if hostvol is None:
errmsg = "No Hosting Volumes available, add more storage"
logging.error(errmsg)
context.set_details(errmsg)
context.set_code(grpc.StatusCode.RESOURCE_EXHAUSTED)
return csi_pb2.CreateVolumeResponse()

mntdir = os.path.join(HOSTVOL_MOUNTDIR, hostvol)
if pvtype == PV_TYPE_VIRTBLOCK:
Expand All @@ -204,9 +227,6 @@ def CreateVolume(self, request, context):

update_free_size(hostvol, request.name, -pvsize)

if not hostvoltype:
hostvoltype = "unknown"

send_analytics_tracker("pvc-%s" % hostvoltype, uid)
return csi_pb2.CreateVolumeResponse(
volume={
Expand Down
34 changes: 34 additions & 0 deletions examples/sample-external-kadalu-storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,37 @@ spec:
persistentVolumeClaim:
claimName: pv-ext-kadalu
restartPolicy: OnFailure

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pv-ext-kadalu-1
spec:
storageClassName: kadalu # Add 'kadalu.external.' to name from KadaluStorage kind
accessModes:
- ReadWriteMany
resources:
requests:
storage: 50Mi # This needs to be set using 'kadalu-quotad'

---
apiVersion: v1
kind: Pod
metadata:
name: pod-ext-kadalu-1
labels:
app: sample-app
spec:
containers:
- name: sample-app
image: docker.io/kadalu/sample-pv-check-app:latest
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: "/mnt/pv"
name: csivol
volumes:
- name: csivol
persistentVolumeClaim:
claimName: pv-ext-kadalu-1
restartPolicy: OnFailure

0 comments on commit d70fffe

Please sign in to comment.