Skip to content

Commit 79ee4bc

Browse files
fix(provisioning): register topologyKeys from env rather than all the custom node labels
Signed-off-by: huangfangfeng <[email protected]>
1 parent 671a21b commit 79ee4bc

File tree

5 files changed

+98
-21
lines changed

5 files changed

+98
-21
lines changed

deploy/lvm-operator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1371,6 +1371,8 @@ spec:
13711371
value: openebs
13721372
- name: METRICS_LISTEN_ADDRESS
13731373
value: :9500
1374+
- name: ALLOWED_TOPOLOGIES
1375+
value: "kubernetes.io/hostname,"
13741376
volumeMounts:
13751377
- name: plugin-dir
13761378
mountPath: /plugin

deploy/yamls/lvm-driver.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,8 @@ spec:
10021002
value: openebs
10031003
- name: METRICS_LISTEN_ADDRESS
10041004
value: :9500
1005+
- name: ALLOWED_TOPOLOGIES
1006+
value: "kubernetes.io/hostname,"
10051007
volumeMounts:
10061008
- name: plugin-dir
10071009
mountPath: /plugin

docs/faq.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
### 1. How to add custom topology key
22

3-
To add custom topology key, we can label all the nodes with the required key and value :-
3+
To add custom topology key:
4+
* Label the nodes with the required key and value.
5+
* Set env variables in the LVM driver daemonset yaml(openebs-lvm-node), if already deployed, you can edit the daemonSet directly.
6+
* "openebs.io/nodename" has been added as default topology key.
7+
* Create storageclass with above specific labels keys.
8+
49

510
```sh
611
$ kubectl label node k8s-node-1 openebs.io/rack=rack1
@@ -10,12 +15,28 @@ $ kubectl get nodes k8s-node-1 --show-labels
1015
NAME STATUS ROLES AGE VERSION LABELS
1116
k8s-node-1 Ready worker 16d v1.17.4 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node-1,kubernetes.io/os=linux,node-role.kubernetes.io/worker=true,openebs.io/rack=rack1
1217

18+
19+
$ kubectl get ds -n kube-system openebs-lvm-node -o yaml
20+
...
21+
env:
22+
- name: OPENEBS_NODE_ID
23+
valueFrom:
24+
fieldRef:
25+
fieldPath: spec.nodeName
26+
- name: OPENEBS_CSI_ENDPOINT
27+
value: unix:///plugin/csi.sock
28+
- name: OPENEBS_NODE_DRIVER
29+
value: agent
30+
- name: LVM_NAMESPACE
31+
value: openebs
32+
- name: ALLOWED_TOPOLOGIES
33+
value: "openebs.io/rack"
34+
1335
```
1436
It is recommended is to label all the nodes with the same key, they can have different values for the given keys, but all keys should be present on all the worker node.
1537

16-
Once we have labeled the node, we can install the lvm driver. The driver will pick the node labels and add that as the supported topology key. If the driver is already installed and you want to add a new topology information, you can label the node with the topology information and then restart the LVM-LocalPV CSI driver daemon sets (openebs-lvm-node) are required so that the driver can pick the labels and add them as supported topology keys. We should restart the pod in kube-system namespace with the name as openebs-lvm-node-[xxxxx] which is the node agent pod for the LVM-LocalPV Driver.
38+
Once we have labeled the node, we can install the lvm driver. The driver will pick the keys from env "ALLOWED_TOPOLOGIES" and add that as the supported topology key. If the driver is already installed and you want to add a new topology information, you can edit the LVM-LocalPV CSI driver daemon sets (openebs-lvm-node).
1739

18-
Note that restart of LVM LocalPV CSI driver daemon sets are must in case, if we are going to use WaitForFirstConsumer as volumeBindingMode in storage class. In case of immediate volume binding mode, restart of daemon set is not a must requirement, irrespective of sequence of labelling the node either prior to install lvm driver or after install. However it is recommended to restart the daemon set if we are labeling the nodes after the installation.
1940

2041
```sh
2142
$ kubectl get pods -n kube-system -l role=openebs-lvm
@@ -49,12 +70,7 @@ spec:
4970
- name: local.csi.openebs.io
5071
nodeID: k8s-node-1
5172
topologyKeys:
52-
- beta.kubernetes.io/arch
53-
- beta.kubernetes.io/os
54-
- kubernetes.io/arch
55-
- kubernetes.io/hostname
56-
- kubernetes.io/os
57-
- node-role.kubernetes.io/worker
73+
- openebs.io/nodename
5874
- openebs.io/rack
5975
```
6076
@@ -78,4 +94,4 @@ allowedTopologies:
7894
7995
The LVM LocalPV CSI driver will schedule the PV to the nodes where label "openebs.io/rack" is set to "rack1".
8096
81-
Note that if storageclass is using Immediate binding mode and topology key is not mentioned then all the nodes should be labeled using same key, that means, same key should be present on all nodes, nodes can have different values for those keys. If nodes are labeled with different keys i.e. some nodes are having different keys, then LVMPV's default scheduler can not effectively do the volume capacity based scheduling. Here, in this case the CSI provisioner will pick keys from any random node and then prepare the preferred topology list using the nodes which has those keys defined and LVMPV scheduler will schedule the PV among those nodes only.
97+
Note that if storageclass is using Immediate binding mode and storageclass allowedTopologies is not mentioned then all the nodes should be labeled using "ALLOWED_TOPOLOGIES" keys, that means, "ALLOWED_TOPOLOGIES" keys should be present on all nodes, nodes can have different values for those keys. If some nodes don't have those keys, then LVMPV's default scheduler can not effectively do the volume capacity based scheduling. Here, in this case the CSI provisioner will pick keys from any random node and then prepare the preferred topology list using the nodes which has those keys defined and LVMPV scheduler will schedule the PV among those nodes only.

docs/storageclasses.md

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,57 @@ allowedTopologies:
314314
- node-2
315315
```
316316

317+
At the same time, you must set env variables in the LVM-LocalPV CSI driver daemon sets (openebs-lvm-node) so that it can pick the node label as the supported topology. It add "openebs.io/nodename" as default topology key. If the key doesn't exist in the node labels when the CSI LVM driver register, the key will not add to the topologyKeys. Set more than one keys separated by commas.
318+
319+
```yaml
320+
env:
321+
- name: OPENEBS_NODE_ID
322+
valueFrom:
323+
fieldRef:
324+
fieldPath: spec.nodeName
325+
- name: OPENEBS_CSI_ENDPOINT
326+
value: unix:///plugin/csi.sock
327+
- name: OPENEBS_NODE_DRIVER
328+
value: agent
329+
- name: LVM_NAMESPACE
330+
value: openebs
331+
- name: ALLOWED_TOPOLOGIES
332+
value: "test1,test2"
333+
```
334+
335+
We can verify that key has been registered successfully with the LVM LocalPV CSI Driver by checking the CSI node object yaml :-
336+
337+
```yaml
338+
$ kubectl get csinodes pawan-node-1 -oyaml
339+
apiVersion: storage.k8s.io/v1
340+
kind: CSINode
341+
metadata:
342+
creationTimestamp: "2020-04-13T14:49:59Z"
343+
name: k8s-node-1
344+
ownerReferences:
345+
- apiVersion: v1
346+
kind: Node
347+
name: k8s-node-1
348+
uid: fe268f4b-d9a9-490a-a999-8cde20c4dadb
349+
resourceVersion: "4586341"
350+
selfLink: /apis/storage.k8s.io/v1/csinodes/k8s-node-1
351+
uid: 522c2110-9d75-4bca-9879-098eb8b44e5d
352+
spec:
353+
drivers:
354+
- name: local.csi.openebs.io
355+
nodeID: k8s-node-1
356+
topologyKeys:
357+
- openebs.io/nodename
358+
- test1
359+
- test2
360+
```
361+
362+
If you want to change topology keys, just set new env(ALLOWED_TOPOLOGIES) .Check [faq](./faq.md#1-how-to-add-custom-topology-key) for more details.
363+
364+
```
365+
$ kubectl edit ds -n kube-system openebs-lvm-node
366+
```
367+
317368
Here we can have volume group of name “lvmvg” created on the nvme disks and want to use this high performing LVM volume group for the applications that need higher IOPS. We can use the above SorageClass to create the PVC and deploy the application using that.
318369
319370
The LVM-LocalPV driver will create the Volume in the volume group “lvmvg” present on the node with fewer of volumes provisioned among the given node list. In the above StorageClass, if there provisioned volumes on node-1 are less, it will create the volume on node-1 only. Alternatively, we can use `volumeBindingMode: WaitForFirstConsumer` to let the k8s select the node where the volume should be provisioned.
@@ -327,13 +378,7 @@ user@k8s-master:~ $ kubectl label node k8s-node-1 openebs.io/lvmvg=nvme
327378
node/k8s-node-1 labeled
328379
```
329380
330-
Now, restart the LVM-LocalPV Driver (if already deployed, otherwise please ignore) so that it can pick the new node label as the supported topology. Check [faq](./faq.md#1-how-to-add-custom-topology-key) for more details.
331-
332-
```
333-
$ kubectl delete po -n kube-system -l role=openebs-lvm
334-
```
335-
336-
Now, we can create the StorageClass like this:
381+
Add "openebs.io/lvmvg" to the LVM-LocalPV CSI driver daemon sets env(ALLOWED_TOPOLOGIES). Now, we can create the StorageClass like this:
337382
338383
```yaml
339384
apiVersion: storage.k8s.io/v1

pkg/driver/agent.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package driver
1919
import (
2020
"errors"
2121
"net/http"
22+
"os"
2223
"strings"
2324
"sync"
2425

@@ -324,11 +325,22 @@ func (ns *node) NodeGetInfo(
324325
* }
325326
*/
326327

327-
// support all the keys that node has
328-
topology := node.Labels
329-
330328
// add driver's topology key
331-
topology[lvm.LVMTopologyKey] = ns.driver.config.NodeID
329+
topology := map[string]string{
330+
lvm.LVMTopologyKey: ns.driver.config.NodeID,
331+
}
332+
333+
// support topologykeys from env ALLOWED_TOPOLOGIES
334+
allowedTopologies := os.Getenv("ALLOWED_TOPOLOGIES")
335+
allowedKeys := strings.Split(allowedTopologies, ",")
336+
for _, key := range allowedKeys {
337+
if key != "" {
338+
v, ok := node.Labels[key]
339+
if ok {
340+
topology[key] = v
341+
}
342+
}
343+
}
332344

333345
return &csi.NodeGetInfoResponse{
334346
NodeId: ns.driver.config.NodeID,

0 commit comments

Comments
 (0)