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
replicaAutoBalance: best-effort
defaultLonghornStaticStorageClass: longhorn
createDefaultDiskLabeledNodes: true
ingress:
enabled: true
ingressClassName: nginx

View file

@ -3,6 +3,21 @@ kind: Namespace
metadata:
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
kind: DaemonSet
metadata:
@ -21,6 +36,11 @@ spec:
- key: node-role.kubernetes.io/master
operator: Exists
effect: NoSchedule
volumes:
- name: labeler-script
configMap:
name: labeler-script
defaultMode: 0777
containers:
- name: labeler
image: bitnami/kubectl
@ -29,8 +49,11 @@ spec:
valueFrom:
fieldRef:
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
volumeMounts:
- mountPath: /labeler-script
name: labeler-script
restartPolicy: Always
---
apiVersion: rbac.authorization.k8s.io/v1
@ -41,7 +64,7 @@ metadata:
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "patch"]
verbs: ["get", "patch", "list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding