From f765c65845ce70030cad0750ad334d043d1f2ee7 Mon Sep 17 00:00:00 2001 From: stoetti <31430612+stoetti@users.noreply.github.com> Date: Thu, 25 Jun 2020 10:51:16 +0200 Subject: [PATCH] fix #31 decomissioning for pod '0' (#61) * add graceful shutdown of nifi node #31 * add decomissioning when pod is stopped * move extraContainer in statefulset def * update README.md * fix typo * revert * update termintation in statefulset * correctly decomission node update terminationGracePeriod * update value.yaml * fix decomissioning for pod '0' Co-authored-by: Alexandre Nuttinck --- templates/statefulset.yaml | 67 +++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/templates/statefulset.yaml b/templates/statefulset.yaml index dc3c409d..32c97067 100644 --- a/templates/statefulset.yaml +++ b/templates/statefulset.yaml @@ -130,45 +130,46 @@ spec: exec bin/nifi.sh run & nifi_pid="$!" function offloadNode() { - echo executing preStop > /tmp/preStop.out FQDN=$(hostname -f) echo disconnecting node '$FQDN' - baseUrl=http://nifi-0.nifi-headless:8080 + {{- if .Values.properties.clusterSecure }} + servicePort={{ .Values.service.httpsPort }} + {{- else }} + servicePort={{ .Values.service.httpPort }} + {{- end }} + baseUrl=http://{{ template "apache-nifi.fullname" . }}:${servicePort} echo baseUrl ${baseUrl} - # no cluster without initial node - if [[ "$FQDN" != nifi-0.nifi-headless* ]]; then - echo "gracefully disconnecting node '$FQDN' from cluster" - ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json - nnid=$(jq --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .nodeId' nodes.json) - echo "disconnecting node ${nnid}" - ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi disconnect-node -nnid $nnid -u ${baseUrl} - echo "" - echo "wait until node has state 'DISCONNECTED'" - while [[ "$node_state" != "DISCONNECTED" ]]; do - sleep 1 - ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json - node_state=$(jq -r --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .status' nodes.json) - echo "state is '$node_state'" - done - echo "" - echo "node '${nnid}' was disconnected" - echo "offloading node" - ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi offload-node -nnid $nnid -u ${baseUrl} - echo "" - echo "wait until node has state 'OFFLOADED'" - while [[ "$node_state" != "OFFLOADED" ]]; do - sleep 1 - ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json - node_state=$(jq -r --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .status' nodes.json) - echo "state is '$node_state'" - done - fi + echo "gracefully disconnecting node '$FQDN' from cluster" + ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json + nnid=$(jq --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .nodeId' nodes.json) + echo "disconnecting node ${nnid}" + ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi disconnect-node -nnid $nnid -u ${baseUrl} + echo "" + echo "wait until node has state 'DISCONNECTED'" + while [[ "$node_state" != "DISCONNECTED" ]]; do + sleep 1 + ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json + node_state=$(jq -r --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .status' nodes.json) + echo "state is '$node_state'" + done + echo "" + echo "node '${nnid}' was disconnected" + echo "offloading node" + ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi offload-node -nnid $nnid -u ${baseUrl} + echo "" + echo "wait until node has state 'OFFLOADED'" + while [[ "$node_state" != "OFFLOADED" ]]; do + sleep 1 + ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi get-nodes -ot json -u ${baseUrl} > nodes.json + node_state=$(jq -r --arg FQDN "$FQDN" '.cluster.nodes[] | select(.address==$FQDN) | .status' nodes.json) + echo "state is '$node_state'" + done } deleteNode() { - echo "deleting node" - ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi delete-node -nnid ${nnid} -u ${baseUrl} - echo "node deleted" + echo "deleting node" + ${NIFI_TOOLKIT_HOME}/bin/cli.sh nifi delete-node -nnid ${nnid} -u ${baseUrl} + echo "node deleted" } trap 'echo Received trapped signal, beginning shutdown...;offloadNode;./bin/nifi.sh stop;deleteNode;exit 0;' TERM HUP INT;