@@ -272,8 +272,46 @@ spec:
272272 defaultMode : 420
273273 secretName : {{ .Values.credentials.secret }}
274274 {{- end }}
275+ volumes :
276+ - name : state
277+ emptyDir : {}
275278 terminationGracePeriodSeconds : {{.Values.queueManager.terminationGracePeriodSeconds}}
276279 containers :
280+ - name : state-checker
281+ command :
282+ - sh
283+ - ' -c'
284+ - >
285+ sleep 20;
286+ while true; do
287+ sleep $(($RANDOM % 5 + 5));
288+ KUBE_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
289+ NAMESPACE=$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace)
290+ echo "Checking state of the queue manager"
291+ STATE=$(cat /etc/mqm/state/test)
292+ if [ $STATE -eq 0 ]; then
293+ echo "Queue manager is active"
294+ echo "patching the label:"
295+ curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
296+ --request PATCH \
297+ --header "Content-Type: application/json-patch+json" \
298+ --data '[ { "op": "replace", "path": "/metadata/labels/role", "value": "master" } ]' \
299+ https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/$NAMESPACE/pods/$HOSTNAME
300+ else
301+ echo "Queue manager is not active"
302+ echo "patching the label:"
303+ curl -sSk -H "Authorization: Bearer $KUBE_TOKEN" \
304+ --header "Content-Type: application/json-patch+json" \
305+ --request PATCH \
306+ --data '[ { "op": "replace", "path": "/metadata/labels/role", "value": "standby" } ]' \
307+ https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/$NAMESPACE/pods/$HOSTNAME
308+ fi
309+ done
310+ image : " {{ .Values.image.repository }}:{{ .Values.image.tag }}"
311+ imagePullPolicy : IfNotPresent
312+ volumeMounts :
313+ - mountPath : /etc/mqm/state
314+ name : state
277315 - name : qmgr
278316 image : " {{ .Values.image.repository }}:{{ .Values.image.tag }}"
279317 imagePullPolicy : {{ .Values.image.pullPolicy }}
@@ -371,6 +409,8 @@ spec:
371409 {{- else if .Values.web.manualConfig.secret.name }}
372410 volumeMounts :
373411 {{- end}}
412+ - name : state
413+ mountPath : /etc/mqm/state
374414 {{- if .Values.queueManager.nativeha.tls }}
375415 {{- if .Values.queueManager.nativeha.tls.secretName }}
376416 - name : ha-tls
@@ -493,7 +533,11 @@ spec:
493533 readinessProbe :
494534 exec :
495535 command :
496- - chkmqready
536+ - sh
537+ - ' -c'
538+ - >
539+ chkmqready;
540+ echo $? > /etc/mqm/state/test
497541 {{- if or .Values.queueManager.nativeha.enable .Values.queueManager.multiinstance.enable }}
498542 initialDelaySeconds : {{ .Values.readinessProbe.initialDelaySeconds | default 0 }}
499543 {{- else }}
0 commit comments