Skip to content

Commit 8652239

Browse files
author
Barkha Choithani
committed
added checks for configuring group
1 parent d242792 commit 8652239

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

charts/templates/statefulset.yaml

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,28 @@ spec:
2929
- sh
3030
- '-c'
3131
- |
32-
echo '### Begin configuring group ###'
33-
34-
HOST_RESP_CODE=`curl --anyauth -m 20 -s -o /dev/null -w "%{http_code}" -X GET http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/hosts --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
35-
if [[ ${HOST_RESP_CODE} -eq 200 ]]; then
36-
GROUP_CFG_TEMPLATE='{"group-name":"%s"}'
37-
GROUP_CFG=$(printf "$GROUP_CFG_TEMPLATE" "$MARKLOGIC_GROUP")
38-
GROUP_RESP_CODE=`curl --anyauth -m 20 -s -o /dev/null -w "%{http_code}" -X GET http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/${MARKLOGIC_GROUP} --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
39-
40-
if [[ ${GROUP_RESP_CODE} -eq 200 ]]; then
41-
echo "Group $MARKLOGIC_GROUP is already configured on the MarkLogic cluster."
42-
else
43-
echo "Group $MARKLOGIC_GROUP does not exist, creating $MARKLOGIC_GROUP on the MarkLogic cluster"
44-
curl --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD} -m 20 -s -X POST -d "${GROUP_CFG}" -H "Content-type: application/json" http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups
45-
fi
32+
echo '### Begin init container execution ###'
33+
if [[ $POD_NAME != *-0 ]]; then
34+
echo "This is not a first host in this cluster, not configuring group."
4635
else
47-
echo "Bootstrap host not found"
36+
HOST_RESP_CODE=`curl --anyauth -m 20 -s -o /dev/null -w "%{http_code}" -X GET http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/hosts --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
37+
if [[ ${HOST_RESP_CODE} -ne 200 ]]; then
38+
echo "Bootstrap host not found."
39+
else
40+
echo "Configuring group on the MarkLogic cluster."
41+
GROUP_CFG_TEMPLATE='{"group-name":"%s"}'
42+
GROUP_CFG=$(printf "$GROUP_CFG_TEMPLATE" "$MARKLOGIC_GROUP")
43+
GROUP_RESP_CODE=`curl --anyauth -m 20 -s -o /dev/null -w "%{http_code}" -X GET http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups/${MARKLOGIC_GROUP} --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD}`
44+
45+
if [[ ${GROUP_RESP_CODE} -eq 200 ]]; then
46+
echo "Group $MARKLOGIC_GROUP is already configured on the MarkLogic cluster."
47+
else
48+
echo "Group $MARKLOGIC_GROUP does not exist, creating $MARKLOGIC_GROUP on the MarkLogic cluster"
49+
curl --anyauth --user ${MARKLOGIC_ADMIN_USERNAME}:${MARKLOGIC_ADMIN_PASSWORD} -m 20 -s -X POST -d "${GROUP_CFG}" -H "Content-type: application/json" http://${MARKLOGIC_BOOTSTRAP_HOST}:8002/manage/v2/groups
50+
fi
51+
fi
4852
fi
49-
echo '### init container execution completed ###'
53+
echo '### Init container execution completed ###'
5054
env:
5155
- name: MARKLOGIC_GROUP
5256
value: {{ .Values.group.name }}
@@ -60,6 +64,10 @@ spec:
6064
secretKeyRef:
6165
name: {{ include "marklogic.fullname" . }}
6266
key: password
67+
- name: POD_NAME
68+
valueFrom:
69+
fieldRef:
70+
fieldPath: metadata.name
6371
envFrom:
6472
- configMapRef:
6573
name: {{ include "marklogic.fullname" . }}

0 commit comments

Comments
 (0)