From 4d1eef4a813fecf249f550e889c9ccc2972d2367 Mon Sep 17 00:00:00 2001 From: Chufuyuan Date: Mon, 16 Dec 2019 17:09:37 +0800 Subject: [PATCH] [stable/graylog] fix the logic to determine master node. (#19552) * fix the logic to determine master node. When container was recreated or restart or other conditions, pod is not bing removed, then the master node may becomes a coordinator . This commit add a condition to check if master ip equals the ip of pod itself. If master ip equals the ip of pod itself, it is master node. fix https://github.com/helm/charts/issues/17550 Signed-off-by: fuyuan.chu * fix unexpected new line Signed-off-by: fuyuan.chu --- stable/graylog/Chart.yaml | 2 +- stable/graylog/templates/configmap.yaml | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/stable/graylog/Chart.yaml b/stable/graylog/Chart.yaml index 7be09851ab..64261ba4ee 100755 --- a/stable/graylog/Chart.yaml +++ b/stable/graylog/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v1 name: graylog home: https://www.graylog.org -version: 1.4.0 +version: 1.4.1 appVersion: 3.1 description: Graylog is the centralized log management solution built to open standards for capturing, storing, and enabling real-time analysis of terabytes of machine data. keywords: diff --git a/stable/graylog/templates/configmap.yaml b/stable/graylog/templates/configmap.yaml index 0f04277316..c06729fa51 100644 --- a/stable/graylog/templates/configmap.yaml +++ b/stable/graylog/templates/configmap.yaml @@ -141,15 +141,23 @@ data: MASTER_NAME="{{ template "graylog.fullname" . }}-master.{{ .Release.Namespace }}.svc.cluster.local" # Looking for Master IP MASTER_IP=`/k8s/kubectl --namespace {{ .Release.Namespace }} get pod -o jsonpath='{range .items[*]}{.metadata.name} {.status.podIP}{"\n"}{end}' -l graylog-role=master --field-selector=status.phase=Running|awk '{print $2}'` + SELF_IP=`/k8s/kubectl --namespace {{ .Release.Namespace }} get pod $HOSTNAME -o jsonpath='{.status.podIP}'` echo "Current master is $MASTER_IP" + echo "Self IP is $SELF_IP" if [[ -z "$MASTER_IP" ]]; then echo "Launching $HOSTNAME as master" export GRAYLOG_IS_MASTER="true" /k8s/kubectl --namespace {{ .Release.Namespace }} label --overwrite pod $HOSTNAME graylog-role="master" else - echo "Launching $HOSTNAME as coordinating" - export GRAYLOG_IS_MASTER="false" - /k8s/kubectl --namespace {{ .Release.Namespace }} label --overwrite pod $HOSTNAME graylog-role="coordinating" + # When container was recreated or restart, MASTER_IP == SELF_IP, running as master and no need to change label graylog-role="master" + if [ "$SELF_IP" == "$MASTER_IP" ];then + export GRAYLOG_IS_MASTER="true" + else + # MASTER_IP != SELF_IP, running as coordinating + echo "Launching $HOSTNAME as coordinating" + export GRAYLOG_IS_MASTER="false" + /k8s/kubectl --namespace {{ .Release.Namespace }} label --overwrite pod $HOSTNAME graylog-role="coordinating" + fi fi # Download plugins {{- if .Values.graylog.plugins }}