Skip to content

Commit

Permalink
make helper pod configurable and add xfs quota example
Browse files Browse the repository at this point in the history
  • Loading branch information
nicktming authored and yasker committed Oct 15, 2020
1 parent c3192ec commit 8740885
Show file tree
Hide file tree
Showing 18 changed files with 625 additions and 96 deletions.
54 changes: 48 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,49 @@ data:
}
setup: |-
#!/bin/sh
path=$1
mkdir -m 0777 -p ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
mkdir -m 0777 -p ${absolutePath}
teardown: |-
#!/bin/sh
path=$1
rm -rf ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
rm -rf ${absolutePath}
helperPod.yaml: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
containers:
- name: helper-pod
image: busybox
```

Expand All @@ -158,12 +195,17 @@ The configuration must obey following rules:
3. No duplicate paths allowed for one node.
4. No duplicate node allowed.

#### Scripts `setup` and `teardown`
#### Scripts `setup` and `teardown` and `helperPod.yaml`

The script `setup` will be executed before the volume is created, to prepare the directory on the node for the volume.

The script `teardown` will be executed after the volume is deleted, to cleanup the directory on the node for the volume.

The yaml file `helperPod.yaml` will be created by local-path-storage to execute `setup` or `teardown` script with three paramemters `-p <path> -s <size> -m <mode>` :
* path: the absolute path provisioned on the node
- size: pvc.Spec.resources.requests.storage in bytes
* mode: pvc.Spec.VolumeMode

#### Reloading

The provisioner supports automatic configuration reloading. Users can change the configuration using `kubectl apply` or `kubectl edit` with config map `local-path-config`. There is a delay between when the user updates the config map and the provisioner picking it up.
Expand Down Expand Up @@ -198,7 +240,7 @@ git clone https://github.com/rancher/local-path-provisioner.git
cd local-path-provisioner
go build
kubectl apply -f debug/config.yaml
./local-path-provisioner --debug start --namespace=local-path-storage
./local-path-provisioner --debug start --service-account-name=default
```

### example
Expand Down
45 changes: 41 additions & 4 deletions debug/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,47 @@ data:
}
setup: |-
#!/bin/sh
path=$1
mkdir -m 0777 -p ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
mkdir -m 0777 -p ${absolutePath}
teardown: |-
#!/bin/sh
path=$1
rm -rf ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
rm -rf ${absolutePath}
helperPod.yaml: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
containers:
- name: helper-pod
image: busybox
6 changes: 4 additions & 2 deletions deploy/chart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ default values.
| `nodeSelector` | Node labels for Local Path Provisioner pod assignment | `{}` |
| `tolerations` | Node taints to tolerate | `[]` |
| `affinity` | Pod affinity | `{}` |
| `configmap.setup` | Configuration of script to execute setup operations on each node | #!/bin/sh<br>path=$1<br>mkdir -m 0777 -p ${path} |
| `configmap.teardown` | Configuration of script to execute teardown operations on each node | #!/bin/sh<br>path=$1<br>rm -rf ${path} |
| `configmap.setup` | Configuration of script to execute setup operations on each node | #!/bin/sh<br>while getopts "m:s:p:" opt<br>do<br>&emsp;case $opt in <br>&emsp;&emsp;p)<br>&emsp;&emsp;absolutePath=$OPTARG<br>&emsp;&emsp;;;<br>&emsp;&emsp;s)<br>&emsp;&emsp;sizeInBytes=$OPTARG<br>&emsp;&emsp;;;<br>&emsp;&emsp;m)<br>&emsp;&emsp;volMode=$OPTARG<br>&emsp;&emsp;;;<br>&emsp;esac<br>done<br>mkdir -m 0777 -p ${absolutePath} |
| `configmap.teardown` | Configuration of script to execute teardown operations on each node | #!/bin/sh<br>while getopts "m:s:p:" opt<br>do<br>&emsp;case $opt in <br>&emsp;&emsp;p)<br>&emsp;&emsp;absolutePath=$OPTARG<br>&emsp;&emsp;;;<br>&emsp;&emsp;s)<br>&emsp;&emsp;sizeInBytes=$OPTARG<br>&emsp;&emsp;;;<br>&emsp;&emsp;m)<br>&emsp;&emsp;volMode=$OPTARG<br>&emsp;&emsp;;;<br>&emsp;esac<br>done<br>rm -rf ${absolutePath} |
| `configmap.name` | configmap name | `local-path-config` |
| `configmap.helperPod` | helper pod yaml file | apiVersion: v1<br>kind: Pod<br>metadata:<br>&emsp;name: helper-pod<br>spec:<br>&emsp;containers:<br>&emsp;- name: helper-pod<br>&emsp;&emsp;image: busybox |


Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,

Expand Down
2 changes: 1 addition & 1 deletion deploy/chart/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
{{ include "local-path-provisioner.labels" . | indent 4 }}
rules:
- apiGroups: [""]
resources: ["nodes", "persistentvolumeclaims"]
resources: ["nodes", "persistentvolumeclaims", "configmaps"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["endpoints", "persistentvolumes", "pods"]
Expand Down
3 changes: 3 additions & 0 deletions deploy/chart/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ data:
{{ .Values.configmap.setup | nindent 4 }}
teardown: |-
{{ .Values.configmap.teardown | nindent 4 }}
helperPod.yaml: |-
{{ .Values.configmap.helperPod | nindent 4 }}
51 changes: 46 additions & 5 deletions deploy/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,52 @@ configmap:
# specify the custom script for setup and teardown
setup: |-
#!/bin/sh
path=$1
mkdir -m 0777 -p ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
mkdir -m 0777 -p ${absolutePath}
teardown: |-
#!/bin/sh
path=$1
rm -rf ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
rm -rf ${absolutePath}
# specify the custom helper pod yaml
helperPod: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
containers:
- name: helper-pod
image: busybox
46 changes: 42 additions & 4 deletions deploy/example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,48 @@ data:
}
setup: |-
#!/bin/sh
path=$1
mkdir -m 0777 -p ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
mkdir -m 0777 -p ${absolutePath}
teardown: |-
#!/bin/sh
path=$1
rm -rf ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
rm -rf ${absolutePath}
helperPod.yaml: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
containers:
- name: helper-pod
image: busybox
48 changes: 43 additions & 5 deletions deploy/local-path-storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
name: local-path-provisioner-role
rules:
- apiGroups: [""]
resources: ["nodes", "persistentvolumeclaims"]
resources: ["nodes", "persistentvolumeclaims", "configmaps"]
verbs: ["get", "list", "watch"]
- apiGroups: [""]
resources: ["endpoints", "persistentvolumes", "pods"]
Expand Down Expand Up @@ -104,10 +104,48 @@ data:
}
setup: |-
#!/bin/sh
path=$1
mkdir -m 0777 -p ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
mkdir -m 0777 -p ${absolutePath}
teardown: |-
#!/bin/sh
path=$1
rm -rf ${path}
while getopts "m:s:p:" opt
do
case $opt in
p)
absolutePath=$OPTARG
;;
s)
sizeInBytes=$OPTARG
;;
m)
volMode=$OPTARG
;;
esac
done
rm -rf ${absolutePath}
helperPod.yaml: |-
apiVersion: v1
kind: Pod
metadata:
name: helper-pod
spec:
containers:
- name: helper-pod
image: busybox
3 changes: 3 additions & 0 deletions examples/quota/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
From centos:7
RUN yum install -y xfsprogs

18 changes: 18 additions & 0 deletions examples/quota/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Overview
this is an example to enable quota for xfs

# Usage
> 1. build a helper image using the sample dockerfile to replace helper image xxx/storage-xfs-quota:v0.1 at configmap(helperPod.yaml) of debug.yaml.
> 2. use the sample setup and teardown script at configmap of debug.yaml
Notice:
> 1. make sure the path at nodePathMap is the mountpoint of xfs which enables pquota
# debug
```Bash
> git clone https://github.com/rancher/local-path-provisioner.git
> cd local-path-provisioner
> go build
> kubectl apply -f debug.yaml
> ./local-path-provisioner --debug start --namespace=local-path-storage
```
Loading

0 comments on commit 8740885

Please sign in to comment.