change labeler to also handle longhorn labels

This commit is contained in:
Aaron Riedel 2023-09-15 21:52:32 +02:00
parent d22605c1d9
commit f720d00f0a
Signed by: aaron
GPG key ID: 643004654D40D577
2 changed files with 26 additions and 2 deletions

View file

@ -4,6 +4,7 @@ defaultSettings:
backupTargetCredentialSecret: longhorn-backup-target backupTargetCredentialSecret: longhorn-backup-target
replicaAutoBalance: best-effort replicaAutoBalance: best-effort
defaultLonghornStaticStorageClass: longhorn defaultLonghornStaticStorageClass: longhorn
createDefaultDiskLabeledNodes: true
ingress: ingress:
enabled: true enabled: true
ingressClassName: nginx ingressClassName: nginx

View file

@ -3,6 +3,21 @@ kind: Namespace
metadata: metadata:
name: node-labeler name: node-labeler
--- ---
apiVersion: v1
kind: ConfigMap
metadata:
name: labeler-script
namespace: node-labeler
data:
run.sh: |
#!/usr/bin/env sh
while true; do
kubectl get node $1 -o=jsonpath='{.metadata.labels}' | grep -q node-role.kubernetes.io/worker || kubectl label node $1 node-role.kubernetes.io/worker=
kubectl get node $1 -o=jsonpath='{.metadata.labels}' | grep -q node.longhorn.io/create-default-disk || kubectl label node $1 node.longhorn.io/create-default-disk='config'
kubectl get node $1 -o=jsonpath='{.metadata.annotations}' | grep -q node.longhorn.io/default-disks-config || kubectl annotate node $1 node.longhorn.io/default-disks-config='[ { "path":"/storage1", "allowScheduling":true }, { "name":"storage2", "path":"/storage2", "allowScheduling":true, "storageReserved":0 }]'
sleep 60
done
---
apiVersion: apps/v1 apiVersion: apps/v1
kind: DaemonSet kind: DaemonSet
metadata: metadata:
@ -21,6 +36,11 @@ spec:
- key: node-role.kubernetes.io/master - key: node-role.kubernetes.io/master
operator: Exists operator: Exists
effect: NoSchedule effect: NoSchedule
volumes:
- name: labeler-script
configMap:
name: labeler-script
defaultMode: 0777
containers: containers:
- name: labeler - name: labeler
image: bitnami/kubectl image: bitnami/kubectl
@ -29,8 +49,11 @@ spec:
valueFrom: valueFrom:
fieldRef: fieldRef:
fieldPath: spec.nodeName fieldPath: spec.nodeName
command: ["/bin/sh", "-c", "while true; do kubectl get node $(NODE_NAME) -o=jsonpath='{.metadata.labels}' | grep -q node-role.kubernetes.io/worker || kubectl label node $(NODE_NAME) node-role.kubernetes.io/worker=; sleep 60; done"] command: ["/bin/sh", "-c", "/labeler-script/run.sh $(NODE_NAME)"]
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /labeler-script
name: labeler-script
restartPolicy: Always restartPolicy: Always
--- ---
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
@ -41,7 +64,7 @@ metadata:
rules: rules:
- apiGroups: [""] - apiGroups: [""]
resources: ["nodes"] resources: ["nodes"]
verbs: ["get", "patch"] verbs: ["get", "patch", "list"]
--- ---
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding kind: ClusterRoleBinding