Skip to content

Commit 9818241

Browse files
committed
Fix the readiness probe using a sidecar container
1 parent 9efea5e commit 9818241

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: RoleBinding
3+
metadata:
4+
name: pod-labeler-binding
5+
namespace: ready-check
6+
roleRef:
7+
apiGroup: rbac.authorization.k8s.io
8+
kind: Role
9+
name: pod-labeler
10+
subjects:
11+
- kind: ServiceAccount
12+
name: {{ include "ibm-mq.fullname" ( . ) }}
13+
namespace: ready-check

charts/ibm-mq/templates/role.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: rbac.authorization.k8s.io/v1
2+
kind: Role
3+
metadata:
4+
name: pod-labeler
5+
namespace: ready-check
6+
rules:
7+
- apiGroups: [""]
8+
resources: ["pods"]
9+
verbs: ["get", "list","patch"]

charts/ibm-mq/templates/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ spec:
2626
name: qmgr
2727
selector:
2828
{{- include "ibm-mq.selectorLabels" . | nindent 4 }}
29+
role: master

charts/ibm-mq/templates/stateful-set.yaml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)