Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 83b10fa

Browse files
committed
improve provisioning, avoid using more than 63 chars
1 parent ed6c1d8 commit 83b10fa

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# CHANGELOG
22

3+
## 2020-04-29 1.2.8
4+
5+
* Improve PV name provisioning as a hash of the Namespace+PVC string. Avoid using more than the 63 characater limit.
6+
* Bump python version to 3.9.4
7+
8+
## 2020-03-24 1.2.7
9+
10+
* Merge upstream security fixes.
11+
312
## 2020-02-12 1.2.6
413

514
* Add new argument `--forcePvInit` which forces PV initialization without annotations on the PVC.

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.7.3-alpine3.9
1+
FROM python:3.9.4-alpine3.13
22

33
RUN pip install jinja2 kubernetes
44

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGE=juliohm/k8s-nfs-provisioner
2-
TAG=1.2.7
2+
TAG=1.2.8
33

44
build:
55
docker build -t $(IMAGE):latest .

rootfs/usr/local/bin/controller.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import urllib3
1313
import os
1414
import controllerargs
15+
import hashlib
1516

1617
args = controllerargs.p.parse_args()
1718

@@ -45,6 +46,7 @@
4546
################################################################################
4647
def init_pv_data(pvc, sc):
4748
pvcfullname = pvc.metadata.namespace + '-' + pvc.metadata.name
49+
pvcfullname = "pvc-"+hashlib.md5(pvcfullname.encode()).hexdigest()
4850
logging.info("PVC "+pvcfullname+". Initializing NFS share directories")
4951

5052
if pvc.metadata.annotations and ANNOTATION_INITPERMS in pvc.metadata.annotations and pvc.metadata.annotations[ANNOTATION_INITPERMS] == "false":
@@ -150,6 +152,8 @@ def provision_pv(pvc):
150152
pvname = pvc.metadata.namespace + "-" + pvc.metadata.name
151153
if pvNamePrefix:
152154
pvname = pvNamePrefix + "-" + pvname
155+
if len(pvname) > 63:
156+
pvname = "pv-"+hashlib.md5(pvname.encode()).hexdigest()
153157

154158
pv = coreapi.list_persistent_volume(field_selector="metadata.name="+pvname)
155159
if len(pv.items) > 0:
@@ -166,8 +170,8 @@ def provision_pv(pvc):
166170
pv.metadata = kubernetes.client.V1ObjectMeta()
167171
pv.metadata.name = pvname
168172
pv.metadata.labels = dict()
169-
pv.metadata.labels[LABEL_PVCNAME] = pvc.metadata.name
170-
pv.metadata.labels[LABEL_PVCNAMESPACE] = pvc.metadata.namespace
173+
pv.metadata.labels[LABEL_PVCNAME] = pvc.metadata.name[:63]
174+
pv.metadata.labels[LABEL_PVCNAMESPACE] = pvc.metadata.namespace[:63]
171175
pv.metadata.labels[LABEL_STORAGECLASSNAME] = scname
172176
pv.spec = kubernetes.client.V1PersistentVolumeSpec()
173177
pv.status = kubernetes.client.V1PersistentVolumeStatus()
@@ -275,6 +279,7 @@ def remove_pv(pvc):
275279
eventtype = event["type"]
276280
pvc = event["object"]
277281
pvcfullname = pvc.metadata.namespace+"-"+pvc.metadata.name
282+
pvcfullname = "pvc-"+hashlib.md5(pvcfullname.encode()).hexdigest()
278283
try:
279284
logging.debug("Event: "+eventtype+" "+pvcfullname)
280285
if eventtype == "ADDED":

0 commit comments

Comments
 (0)