From e7108a474909119e737ef33e7e9aed06e07ed1b2 Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Tue, 2 Jan 2024 15:14:23 +0100 Subject: [PATCH 1/3] Only download kubectl and provide volume if graylog version is < 4.2.0-0 Signed-off-by: tuxBurner --- charts/graylog/templates/statefulset.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/charts/graylog/templates/statefulset.yaml b/charts/graylog/templates/statefulset.yaml index 0ce8f33..fdbe327 100644 --- a/charts/graylog/templates/statefulset.yaml +++ b/charts/graylog/templates/statefulset.yaml @@ -7,6 +7,7 @@ metadata: {{- with .Values.graylog.customLabels }} {{ . | toYaml | indent 4 }} {{- end }} +{{ $graylogVersion := .Values.graylog.image.tag | default .Chart.AppVersion }} spec: serviceName: {{ template "graylog.service.headless.name" . }} replicas: {{ .Values.graylog.replicas }} @@ -72,12 +73,14 @@ spec: rm -rf /usr/share/graylog/data/journal/messagejournal-0 rm -rf /usr/share/graylog/data/journal/recovery-point-offset-checkpoint {{- end }} + {{- if semverCompare "< 4.2.0-0" ( $graylogVersion ) }} {{- if .Values.graylog.init.kubectlLocation }} wget {{ .Values.graylog.init.kubectlLocation }} -O /k8s/kubectl {{- else }} wget https://storage.googleapis.com/kubernetes-release/release/{{ .Values.graylog.init.kubectlVersion | default .Capabilities.KubeVersion.Version }}/bin/linux/amd64/kubectl -O /k8s/kubectl {{- end }} chmod +x /k8s/kubectl + {{- end }} GRAYLOG_HOME=/usr/share/graylog chown -R 1100:1100 ${GRAYLOG_HOME}/data/ @@ -89,8 +92,10 @@ spec: volumeMounts: - name: journal mountPath: /usr/share/graylog/data/journal + {{- if semverCompare "< 4.2.0-0" ( $graylogVersion ) }} - name: kubectl mountPath: /k8s + {{- end }} {{- if .Values.graylog.init.resources }} resources: {{ toYaml .Values.graylog.init.resources | indent 12 }} @@ -224,12 +229,13 @@ spec: - name: files mountPath: /etc/graylog/server {{- end }} + {{- if semverCompare "< 4.2.0-0" ( $graylogVersion ) }} - name: kubectl mountPath: /k8s + {{- end }} {{- if .Values.graylog.extraVolumeMounts }} {{ toYaml .Values.graylog.extraVolumeMounts | nindent 12 }} {{- end }} - {{ $graylogVersion := .Values.graylog.image.tag | default .Chart.AppVersion }} {{- if semverCompare "< 4.2.0-0" ( $graylogVersion ) }} lifecycle: preStop: @@ -271,8 +277,10 @@ spec: configMap: name: {{ template "graylog.fullname" . }}-files {{- end }} + {{- if semverCompare "< 4.2.0-0" ( $graylogVersion ) }} - name: kubectl emptyDir: {} + {{- end }} {{- if .Values.graylog.extraVolumes }} {{ toYaml .Values.graylog.extraVolumes | nindent 8 }} {{- end }} From 9c66710e0e6a116fc614246ad787a3b1f299ebb3 Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Tue, 2 Jan 2024 15:18:44 +0100 Subject: [PATCH 2/3] Bumped chart version to 2.3.5 --- charts/graylog/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/graylog/Chart.yaml b/charts/graylog/Chart.yaml index c449a48..da3642a 100755 --- a/charts/graylog/Chart.yaml +++ b/charts/graylog/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: graylog home: https://www.graylog.org -version: 2.3.4 +version: 2.3.5 appVersion: 5.0.3 description: Graylog is the centralized log management solution built to open standards for capturing, storing, and enabling real-time analysis of terabytes From 5ed06cb47d2daa79402d20d315f8cf0ef73d2af9 Mon Sep 17 00:00:00 2001 From: tuxBurner Date: Tue, 2 Jan 2024 17:43:04 +0100 Subject: [PATCH 3/3] Removed master detection and added env POD_NAME --- charts/graylog/templates/configmap.yaml | 60 +++++++++++------------ charts/graylog/templates/statefulset.yaml | 6 +++ 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/charts/graylog/templates/configmap.yaml b/charts/graylog/templates/configmap.yaml index acbb6b7..9a610cc 100644 --- a/charts/graylog/templates/configmap.yaml +++ b/charts/graylog/templates/configmap.yaml @@ -162,36 +162,36 @@ data: find ${GRAYLOG_HOME}/plugins-default/ -type f -exec cp {} ${GRAYLOG_PLUGIN_DIR} \; # Looking for Master IP retry=1 - for i in {0..2} - do - 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" - retry=$((retry+1)) - [[ ! -z "$MASTER_IP" ]] && break - echo "[Try ${retry}/3] Waiting for master node..." - sleep 2 - done - if [[ -z "$MASTER_IP" ]]; then - echo "Launching $HOSTNAME as master" - export GRAYLOG_IS_MASTER="true" - export GRAYLOG_IS_LEADER="true" - /k8s/kubectl --namespace {{ .Release.Namespace }} label --overwrite pod $HOSTNAME graylog-role="master" - else - # 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 - echo "Launching $HOSTNAME as master" - export GRAYLOG_IS_MASTER="true" - export GRAYLOG_IS_LEADER="true" - else - # MASTER_IP != SELF_IP, running as coordinating - echo "Launching $HOSTNAME as coordinating" - export GRAYLOG_IS_MASTER="false" - export GRAYLOG_IS_LEADER="false" - /k8s/kubectl --namespace {{ .Release.Namespace }} label --overwrite pod $HOSTNAME graylog-role="coordinating" - fi - fi + #for i in {0..2} + #do + # 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" + # retry=$((retry+1)) + # [[ ! -z "$MASTER_IP" ]] && break + # echo "[Try ${retry}/3] Waiting for master node..." + # sleep 2 + #done + #if [[ -z "$MASTER_IP" ]]; then + # echo "Launching $HOSTNAME as master" + # export GRAYLOG_IS_MASTER="true" + # export GRAYLOG_IS_LEADER="true" + # /k8s/kubectl --namespace {{ .Release.Namespace }} label --overwrite pod $HOSTNAME graylog-role="master" + #else + # # 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 + # echo "Launching $HOSTNAME as master" + # export GRAYLOG_IS_MASTER="true" + # export GRAYLOG_IS_LEADER="true" + # else + # # MASTER_IP != SELF_IP, running as coordinating + # echo "Launching $HOSTNAME as coordinating" + # export GRAYLOG_IS_MASTER="false" + # export GRAYLOG_IS_LEADER="false" + # /k8s/kubectl --namespace {{ .Release.Namespace }} label --overwrite pod $HOSTNAME graylog-role="coordinating" + # fi + #fi # Download plugins {{- if .Values.graylog.plugins.proxy.enabled }} export https_proxy={{ .Values.graylog.plugins.proxy.host }} diff --git a/charts/graylog/templates/statefulset.yaml b/charts/graylog/templates/statefulset.yaml index fdbe327..3145de6 100644 --- a/charts/graylog/templates/statefulset.yaml +++ b/charts/graylog/templates/statefulset.yaml @@ -110,6 +110,12 @@ spec: command: - /entrypoint.sh env: + # Kubernetes Auto Master Selection + # https://go2docs.graylog.org/5-0/downloading_and_installing_graylog/docker_installation.htm#KubernetesAutomaticMasterSelection + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name - name: GRAYLOG_SERVER_JAVA_OPTS {{- $javaOpts := .Values.graylog.javaOpts }} {{- if .Values.graylog.heapSize }}