Skip to content

Commit e30524c

Browse files
committed
Containers images, Manifest files
- Manifest files - Dockerfile for server - Dockerfile for csi - CSI pods deployment - Server pods deployment Signed-off-by: Aravinda VK <[email protected]>
1 parent 7d79853 commit e30524c

32 files changed

+1287
-242
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
glustercs_csi.egg-info
22
build
33
dist
4+
manifests/*.yaml

Makefile

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
.PHONY: help build-grpc
22

3+
NODE?=kube1
4+
BRICK?=/exports/data
5+
36
help:
4-
@echo " make build-grpc - To generate grpc Python Code"
7+
@echo " make build-grpc - To generate grpc Python Code"
8+
@echo " make build-containers - To create server, csi and Operator containers"
9+
@echo " make gen-manifest - To generate manifest files to deploy"
510

611
build-grpc:
712
python3 -m grpc_tools.protoc -I./csi/protos --python_out=csi --grpc_python_out=csi ./csi/protos/csi.proto
13+
14+
build-containers:
15+
bash build.sh
16+
17+
gen-manifest:
18+
@echo "Generating manifest files for node=${NODE} brick=${BRICK},"
19+
@echo "run the following commands"
20+
@echo
21+
@python3 extras/scripts/gen_manifest.py ${NODE} ${BRICK}

build.sh

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#! /bin/bash
2+
3+
set -e -o pipefail
4+
5+
REPO="${REPO:-aravindavk}"
6+
7+
RUNTIME_CMD=${RUNTIME_CMD:-docker}
8+
build="build"
9+
if [[ "${RUNTIME_CMD}" == "buildah" ]]; then
10+
build="bud"
11+
fi
12+
13+
# This sets the version variable to (hopefully) a semver compatible string. We
14+
# expect released versions to have a tag of vX.Y.Z (with Y & Z optional), so we
15+
# only look for those tags. For version info on non-release commits, we want to
16+
# include the git commit info as a "build" suffix ("+stuff" at the end). There
17+
# is also special casing here for when no tags match.
18+
VERSION_GLOB="v[0-9]*"
19+
# Get the nearest "version" tag if one exists. If not, this returns the full
20+
# git hash
21+
NEAREST_TAG="$(git describe --always --tags --match "$VERSION_GLOB" --abbrev=0)"
22+
# Full output of git describe for us to parse: TAG-<N>-g<hash>-<dirty>
23+
FULL_DESCRIBE="$(git describe --always --tags --match "$VERSION_GLOB" --dirty)"
24+
# If full matches against nearest, we found a valid tag earlier
25+
if [[ $FULL_DESCRIBE =~ ${NEAREST_TAG}-(.*) ]]; then
26+
# Build suffix is the last part of describe w/ "-" replaced by "."
27+
VERSION="$NEAREST_TAG+${BASH_REMATCH[1]//-/.}"
28+
else
29+
# We didn't find a valid tag, so assume version 0 and everything ends up
30+
# in build suffix.
31+
VERSION="0.0.0+g${FULL_DESCRIBE//-/.}"
32+
fi
33+
34+
BUILDDATE="$(date -u '+%Y-%m-%dT%H:%M:%S.%NZ')"
35+
36+
build_args=()
37+
build_args+=(--build-arg "version=$VERSION")
38+
build_args+=(--build-arg "builddate=$BUILDDATE")
39+
40+
# Print Docker version
41+
echo "=== $RUNTIME_CMD version ==="
42+
$RUNTIME_CMD version
43+
44+
IMAGE_NAME=glusterfsd
45+
DOCKERFILE=glusterfsd.Dockerfile
46+
47+
function build_container()
48+
{
49+
IMAGE_NAME=$1
50+
DOCKERFILE=$2
51+
$RUNTIME_CMD $build \
52+
-t "${REPO}/${IMAGE_NAME}" \
53+
"${build_args[@]}" \
54+
--network host \
55+
-f "$DOCKERFILE" \
56+
. ||
57+
exit 1
58+
}
59+
60+
build_container "kadalu-server" "server/Dockerfile"
61+
build_container "kadalu-csi" "csi/Dockerfile"

csi/Dockerfile

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
FROM docker.io/fedora:29
2+
3+
COPY extras/release6-fedora.repo /etc/yum.repos.d/glusterfs-6-rc0.repo
4+
5+
RUN yum update -y && \
6+
yum -y install procps-ng glusterfs-fuse xfsprogs && \
7+
yum clean all -y && \
8+
rm -rf /var/cache/yum && \
9+
rpm -qa | grep gluster | tee /gluster-rpm-versions.txt
10+
11+
# Install Python GRPC library and copy all CSI related files
12+
RUN python3 -m pip install grpcio googleapis-common-protos
13+
RUN mkdir -p /kadalu-csi
14+
15+
COPY csi/controllerserver.py /kadalu-csi/
16+
COPY csi/csi_pb2_grpc.py /kadalu-csi/
17+
COPY csi/csi_pb2.py /kadalu-csi/
18+
COPY csi/identityserver.py /kadalu-csi/
19+
COPY csi/main.py /kadalu-csi/
20+
COPY csi/nodeserver.py /kadalu-csi/
21+
COPY csi/utils.py /kadalu-csi/
22+
23+
ARG version="(unknown)"
24+
# Container build time (date -u '+%Y-%m-%dT%H:%M:%S.%NZ')
25+
ARG builddate="(unknown)"
26+
27+
LABEL build-date="${builddate}"
28+
LABEL io.k8s.description="KaDalu CSI driver"
29+
LABEL name="kadalu-csi"
30+
LABEL Summary="KaDalu CSI driver"
31+
LABEL vcs-type="git"
32+
LABEL vcs-url="https://github.com/aravindavk/kadalu"
33+
LABEL vendor="kadalu.gluster"
34+
LABEL version="${version}"
35+
36+
ENTRYPOINT ["/usr/bin/python3", "/kadalu-csi/main.py"]
37+
38+
# Debugging, Comment the above line and
39+
# uncomment below line
40+
# ENTRYPOINT ["tail", "-f", "/dev/null"]

csi/controllerserver.py

+46-56
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,72 @@
1-
from concurrent import futures
2-
import time
3-
import logging
4-
5-
import grpc
1+
import os
62

73
import csi_pb2
84
import csi_pb2_grpc
5+
from utils import mount_glusterfs, execute
96

10-
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
11-
HOSTVOL_MOUNTDIR = "/mnt/"
7+
HOSTVOL_MOUNTDIR = "/mnt"
128
GLUSTERFS_CMD = "/usr/sbin/glusterfs"
139
MOUNT_CMD = "/usr/bin/mount"
1410
UNMOUNT_CMD = "/usr/bin/umount"
15-
16-
17-
def get_value_from_context(context, key):
18-
for k, v in context:
19-
if k == key:
20-
return v
21-
22-
return ""
11+
mkfs_xfs_cmd = "/usr/sbin/mkfs.xfs"
2312

2413

2514
class ControllerServer(csi_pb2_grpc.ControllerServicer):
2615

2716
def CreateVolume(self, request, context):
2817
# TODO: Get Hosting Volume name from Storage Class Option
29-
hostVol = "ghostvol"
18+
hostVol = "glustervol"
3019
mntdir = os.path.join(HOSTVOL_MOUNTDIR, hostVol)
3120

3221
# # Try to mount the Host Volume, handle failure if already mounted
33-
# # TODO: Get Glusterfs command with static Volfile
34-
execute(GLUSTERFS_CMD,)
22+
mount_glusterfs(hostVol, mntdir)
3523

3624
# TODO: Get Volume capacity from PV claim
3725
pvsize = 1073741824 # 1GiB
38-
26+
3927
# TODO: get pvtype from storage class
4028
pvtype = "virtblock"
29+
volpath = os.path.join(mntdir, request.name)
4130
if pvtype == "virtblock":
4231
# Create a file with required size
32+
fd = os.open(volpath, os.O_CREAT | os.O_RDWR)
33+
os.close(fd)
34+
os.truncate(volpath, pvsize)
4335
# Mkfs.xfs or based on storage class option
44-
pass
36+
execute(mkfs_xfs_cmd, volpath)
4537
else:
4638
# Create a subdir
47-
# Set BackendQuota using RPC to sidecar container of each glusterfsd pod
48-
pass
39+
os.makedirs(volpath)
40+
# TODO: Set BackendQuota using RPC to sidecar
41+
# container of each glusterfsd pod
4942

5043
return csi_pb2.CreateVolumeResponse(
51-
volume_id=request.volume_id,
52-
capacity_bytes=pvsize,
53-
volume_context=[
54-
{"key": "glustervol", "value": hostVol},
55-
{"key": "pvtype", "value": pvtype}
56-
]
44+
volume={
45+
"volume_id": request.name,
46+
"capacity_bytes": pvsize,
47+
"volume_context": {
48+
"glustervol": hostVol,
49+
"pvtype": pvtype
50+
}
51+
}
5752
)
5853

5954
def DeleteVolume(self, request, context):
6055
# TODO: Get Hosting Volume name from Storage Class Option
61-
hostVol = "ghostvol"
56+
hostVol = "glustervol"
6257
mntdir = os.path.join(HOSTVOL_MOUNTDIR, hostVol)
6358

64-
# # Try to mount the Host Volume, handle failure if already mounted
65-
# # TODO: Get Glusterfs command with static Volfile
66-
execute(GLUSTERFS_CMD,)
59+
# Try to mount the Host Volume, handle
60+
# failure if already mounted
61+
mount_glusterfs(hostVol, mntdir)
6762

6863
# TODO: get pvtype from storage class
6964
pvtype = "virtblock"
65+
volpath = os.path.join(mntdir, request.name)
7066
if pvtype == "virtblock":
71-
# Remove file
72-
pass
67+
os.remove(volpath)
7368
else:
74-
# Remove directory
75-
pass
69+
os.removedirs(volpath)
7670

7771
return csi_pb2.DeleteVolumeResponse()
7872

@@ -86,24 +80,20 @@ def ListVolumes(self, request, context):
8680
# Listdir and return the list
8781
# Volume capacity need to be stored somewhere
8882
pass
89-
90-
def ControllerGetCapabilities(self, request, context):
91-
# TODO
92-
pass
93-
94-
95-
def main():
96-
logging.basicConfig()
97-
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
98-
csi_pb2_grpc.add_ControllerServicer_to_server(ControllerServer(), server)
99-
server.add_insecure_port('[::]:50051')
100-
server.start()
101-
try:
102-
while True:
103-
time.sleep(_ONE_DAY_IN_SECONDS)
104-
except KeyboardInterrupt:
105-
server.stop(0)
10683

107-
108-
if __name__ == '__main__':
109-
main()
84+
def ControllerGetCapabilities(self, request, context):
85+
capabilityType = csi_pb2.ControllerServiceCapability.RPC.Type.Value
86+
return csi_pb2.ControllerGetCapabilitiesResponse(
87+
capabilities=[
88+
{
89+
"rpc": {
90+
"type": capabilityType("CREATE_DELETE_VOLUME")
91+
}
92+
},
93+
{
94+
"rpc": {
95+
"type": capabilityType("LIST_VOLUMES")
96+
}
97+
}
98+
]
99+
)

csi/csi.Dockerfile

-27
This file was deleted.

csi/identityserver.py

+10-32
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
from concurrent import futures
2-
import time
3-
import logging
4-
5-
import grpc
6-
71
import csi_pb2
82
import csi_pb2_grpc
9-
10-
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
11-
12-
13-
DRIVER_NAME = "org.gluster.glusterfs"
14-
DRIVER_VERSION = "0.1.0"
3+
from utils import DRIVER_NAME, DRIVER_VERSION
154

165

176
class IdentityServer(csi_pb2_grpc.IdentityServicer):
@@ -23,27 +12,16 @@ def GetPluginInfo(self, request, context):
2312
)
2413

2514
def GetPluginCapabilities(self, request, context):
26-
# TODO: Update Capabilities
15+
capabilityType = csi_pb2.PluginCapability.Service.Type.Value
2716
return csi_pb2.GetPluginCapabilitiesResponse(
28-
capabilities=[]
17+
capabilities=[
18+
{
19+
"service": {
20+
"type": capabilityType("CONTROLLER_SERVICE")
21+
}
22+
}
23+
]
2924
)
3025

3126
def Probe(self, request, context):
32-
return csi_pb2.Probe()
33-
34-
35-
def main():
36-
logging.basicConfig()
37-
server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
38-
csi_pb2_grpc.add_IdentityServicer_to_server(IdentityServer(), server)
39-
server.add_insecure_port('[::]:50051')
40-
server.start()
41-
try:
42-
while True:
43-
time.sleep(_ONE_DAY_IN_SECONDS)
44-
except KeyboardInterrupt:
45-
server.stop(0)
46-
47-
48-
if __name__ == '__main__':
49-
main()
27+
return csi_pb2.ProbeResponse()

0 commit comments

Comments
 (0)