Skip to content

Commit

Permalink
fix(chart): move default file contents to chart values.yaml
Browse files Browse the repository at this point in the history
Fixed SeleniumHQ#2141
When it is imported as a sub-chart in another chart, files could not load

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Feb 23, 2024
1 parent 80856d3 commit 2d4eed2
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 150 deletions.
81 changes: 0 additions & 81 deletions charts/selenium-grid/configs/node/nodePreStop.sh

This file was deleted.

53 changes: 0 additions & 53 deletions charts/selenium-grid/configs/node/nodeProbe.sh

This file was deleted.

151 changes: 135 additions & 16 deletions charts/selenium-grid/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,6 @@ busConfigMap:
# Custom annotations for configmap
annotations: {}

# ConfigMap that contains common environment variables for browser nodes
nodeConfigMap:
# nameOverride:
# Default mode for ConfigMap is mounted as file
defaultMode: 0755
# File name of preStop script in ConfigMap
extraScriptsDirectory: "/opt/selenium"
extraScripts:
nodePreStop.sh:
nodeProbe.sh:
# Name of volume mount is used to mount scripts in the ConfigMap
scriptVolumeMountName:
# Custom annotations for configmap
annotations: {}

recorderConfigMap:
# nameOverride:
# Default mode for ConfigMap is mounted as file
Expand Down Expand Up @@ -149,7 +134,6 @@ uploaderConfigMap:
# Custom annotations for configmap
annotations: {}


# ConfigMap that contains common environment variables for Logging (https://www.selenium.dev/documentation/grid/configuration/cli_options/#logging)
loggingConfigMap:
# nameOverride:
Expand Down Expand Up @@ -1186,3 +1170,138 @@ jaeger:
enabled: false
query:
enabled: false

# ConfigMap that contains common environment variables for browser nodes
nodeConfigMap:
# nameOverride:
# Default mode for ConfigMap is mounted as file
defaultMode: 0755
# File name of preStop script in ConfigMap
extraScriptsDirectory: "/opt/selenium"
extraScripts:
nodePreStop.sh: |
#!/bin/bash
function on_exit() {
rm -rf /tmp/preStopOutput
}
trap on_exit EXIT
# Set headers if Node Registration Secret is set
if [ ! -z "${SE_REGISTRATION_SECRET}" ];
then
HEADERS="X-REGISTRATION-SECRET: ${SE_REGISTRATION_SECRET}"
else
HEADERS="X-REGISTRATION-SECRET;"
fi
function is_full_distributed_mode() {
if [ -n "${SE_DISTRIBUTOR_HOST}" ] && [ -n "${SE_DISTRIBUTOR_PORT}" ]; then
DISTRIBUTED_MODE=true
echo "Detected full distributed mode: ${DISTRIBUTED_MODE}. Since SE_DISTRIBUTOR_HOST and SE_DISTRIBUTOR_PORT are set in Node ConfigMap"
else
DISTRIBUTED_MODE=false
echo "Detected full distributed mode: ${DISTRIBUTED_MODE}"
fi
}
is_full_distributed_mode
function signal_distributor_to_drain_node() {
if [ "${DISTRIBUTED_MODE}" = true ]; then
echo "Signaling Distributor to drain node"
set -x
curl -k -X POST ${SE_SERVER_PROTOCOL}://${SE_DISTRIBUTOR_HOST}:${SE_DISTRIBUTOR_PORT}/se/grid/distributor/node/${NODE_ID}/drain --header "${HEADERS}"
set +x
fi
}
function signal_hub_to_drain_node() {
if [ "${DISTRIBUTED_MODE}" = false ]; then
echo "Signaling Hub to drain node"
curl -k -X POST ${SE_GRID_URL}/se/grid/distributor/node/${NODE_ID}/drain --header "${HEADERS}"
fi
}
function signal_node_to_drain() {
echo "Signaling Node to drain itself"
curl -k -X POST ${SE_SERVER_PROTOCOL}://127.0.0.1:${SE_NODE_PORT}/se/grid/node/drain --header "${HEADERS}"
}
function replace_localhost_by_service_name() {
internal="${SE_HUB_HOST:-$SE_ROUTER_HOST}:${SE_HUB_PORT:-$SE_ROUTER_PORT}"
echo "SE_NODE_GRID_URL: ${SE_NODE_GRID_URL}"
if [[ "${SE_NODE_GRID_URL}" == *"/localhost"* ]]; then
SE_GRID_URL=${SE_NODE_GRID_URL//localhost/${internal}}
elif [[ "${SE_NODE_GRID_URL}" == *"/127.0.0.1"* ]]; then
SE_GRID_URL=${SE_NODE_GRID_URL//127.0.0.1/${internal}}
elif [[ "${SE_NODE_GRID_URL}" == *"/0.0.0.0"* ]]; then
SE_GRID_URL=${SE_NODE_GRID_URL//0.0.0.0/${internal}}
else
SE_GRID_URL=${SE_NODE_GRID_URL}
fi
echo "Set SE_GRID_URL internally: ${SE_GRID_URL}"
}
replace_localhost_by_service_name
if curl -sfk ${SE_SERVER_PROTOCOL}://127.0.0.1:${SE_NODE_PORT}/status > /tmp/preStopOutput; then
NODE_ID=$(jq -r '.value.node.nodeId' /tmp/preStopOutput)
if [ -n "${NODE_ID}" ]; then
echo "Current Node ID is: ${NODE_ID}"
signal_hub_to_drain_node
signal_distributor_to_drain_node
echo
fi
signal_node_to_drain
# Wait for the current session to be finished if any
while curl -sfk ${SE_SERVER_PROTOCOL}://127.0.0.1:${SE_NODE_PORT}/status -o /tmp/preStopOutput;
do
echo "Node preStop is waiting for current session to be finished if any. Node details: message: $(jq -r '.value.message' /tmp/preStopOutput || "unknown"), availability: $(jq -r '.value.node.availability' /tmp/preStopOutput || "unknown")"
sleep 1;
done
else
echo "Node is already drained. Shutting down gracefully!"
fi
nodeProbe.sh: |
#!/bin/bash
function on_exit() {
rm -rf /tmp/nodeProbe${ID}
rm -rf /tmp/gridProbe${ID}
}
trap on_exit EXIT
ID=$(echo $RANDOM)
function replace_localhost_by_service_name() {
internal="${SE_HUB_HOST:-$SE_ROUTER_HOST}:${SE_HUB_PORT:-$SE_ROUTER_PORT}"
echo "SE_NODE_GRID_URL: ${SE_NODE_GRID_URL}"
if [[ "${SE_NODE_GRID_URL}" == *"/localhost"* ]]; then
SE_GRID_URL=${SE_NODE_GRID_URL//localhost/${internal}}
elif [[ "${SE_NODE_GRID_URL}" == *"/127.0.0.1"* ]]; then
SE_GRID_URL=${SE_NODE_GRID_URL//127.0.0.1/${internal}}
elif [[ "${SE_NODE_GRID_URL}" == *"/0.0.0.0"* ]]; then
SE_GRID_URL=${SE_NODE_GRID_URL//0.0.0.0/${internal}}
else
SE_GRID_URL=${SE_NODE_GRID_URL}
fi
echo "Set SE_GRID_URL internally: ${SE_GRID_URL}"
}
replace_localhost_by_service_name
if curl -sfk ${SE_SERVER_PROTOCOL}://127.0.0.1:${SE_NODE_PORT}/status -o /tmp/nodeProbe${ID}; then
NODE_ID=$(jq -r '.value.node.nodeId' /tmp/nodeProbe${ID})
NODE_STATUS=$(jq -r '.value.node.availability' /tmp/nodeProbe${ID})
if [ -n "${NODE_ID}" ]; then
echo "Node responds the ID: ${NODE_ID} with status: ${NODE_STATUS}"
else
echo "Wait for the Node to report its status"
exit 1
fi
curl -sfk "${SE_GRID_URL}/status" -o /tmp/gridProbe${ID}
GRID_NODE_ID=$(jq -e ".value.nodes[].id|select(. == \"${NODE_ID}\")" /tmp/gridProbe${ID} | tr -d '"' || true)
if [ -n "${GRID_NODE_ID}" ]; then
echo "Grid responds a matched Node ID: ${GRID_NODE_ID}"
fi
if [ "${NODE_STATUS}" = "UP" ] && [ -n "${NODE_ID}" ] && [ -n "${GRID_NODE_ID}" ] && [ "${NODE_ID}" = "${GRID_NODE_ID}" ]; then
echo "Node ID: ${NODE_ID} is found in the Grid. The registration is successful."
exit 0
else
echo "Node ID: ${NODE_ID} is not found in the Grid. The registration could be in progress."
exit 1
fi
else
echo "Wait for the Node to report its status"
exit 1
fi
# Name of volume mount is used to mount scripts in the ConfigMap
scriptVolumeMountName:
# Custom annotations for configmap
annotations: {}

0 comments on commit 2d4eed2

Please sign in to comment.