From 6df9b4832a82a717b14f629b50624cfa25400799 Mon Sep 17 00:00:00 2001 From: Kiefer Chang Date: Tue, 14 Sep 2021 16:12:26 +0800 Subject: [PATCH] Promote nodes by setting machine labels Switch to the preferred way to promote agent to server in Rancher by setting the following labels on corresponding machines: ``` rke.cattle.io/control-plane-role: "true" rke.cattle.io/etcd-role: "true" ``` Signed-off-by: Kiefer Chang --- .../charts/harvester/templates/configmap.yaml | 43 +++++++++++++++++++ .../master/node/promote_controller.go | 27 ++++++------ 2 files changed, 58 insertions(+), 12 deletions(-) diff --git a/deploy/charts/harvester/templates/configmap.yaml b/deploy/charts/harvester/templates/configmap.yaml index 7633ba856b..fd1a21c09a 100644 --- a/deploy/charts/harvester/templates/configmap.yaml +++ b/deploy/charts/harvester/templates/configmap.yaml @@ -21,3 +21,46 @@ data: mode: {{ .Values.service.vip.mode }} hwAddress: {{ .Values.service.vip.hwAddress | quote }} loadBalancerIP: {{ .Values.service.vip.loadBalancerIP | quote }} + +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: harvester-helpers + labels: +{{ include "harvester.labels" . | indent 4 }} +data: + promote.sh: |- + {{`KUBECTL="/host/$(readlink /host/var/lib/rancher/rke2/bin)/kubectl" + CUSTOM_MACHINE=$($KUBECTL get node $HOSTNAME -o go-template=$'{{index .metadata.annotations "cluster.x-k8s.io/machine"}}\n') + + until $KUBECTL get machines.cluster.x-k8s.io $CUSTOM_MACHINE -n fleet-local &> /dev/null + do + echo Waiting for custom machine $CUSTOM_MACHINE... + sleep 2 + done + + VIP=$($KUBECTL get configmap vip -n harvester-system -o=jsonpath='{.data.ip}') + cat > /host/etc/rancher/rke2/config.yaml.d/90-harvester-server.yaml < /etc/rancher/rke2/config.yaml.d/90-harvester-server.yaml <