From 5ed3aa2ca4ea03c09625157c9aa22ef2fe7c0db1 Mon Sep 17 00:00:00 2001 From: topahadzi Date: Fri, 27 Oct 2023 15:26:37 +0700 Subject: [PATCH] add script test --- Dockerfile | 6 +++++- test.sh | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100755 test.sh diff --git a/Dockerfile b/Dockerfile index 23c91b3..2192a20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,4 +6,8 @@ RUN chmod +x kubectl RUN mv ./kubectl /usr/local/bin/ RUN curl -LO https://github.com/kvaps/kubectl-node-shell/raw/master/kubectl-node_shell RUN chmod +x ./kubectl-node_shell -RUN mv ./kubectl-node_shell /usr/local/bin/kubectl-node_shell \ No newline at end of file +RUN mv ./kubectl-node_shell /usr/local/bin/kubectl-node_shell + +COPY test.sh /app +WORKDIR /app +CMD ["/bin/sh","-c","/app/test.sh"] \ No newline at end of file diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..1632a9c --- /dev/null +++ b/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Define the label key and value you want to search for +LABEL=${NODE_LABEL:-} + +# Use `kubectl` to get the node name by label +NODE_NAMES=$(kubectl get nodes --selector="$LABEL" -o custom-columns=NAME:.metadata.name --no-headers) + + +if [ -z "$NODE_NAMES" ]; then + echo "No nodes found with the label $LABEL_KEY=$LABEL_VALUE." + exit 1 +fi + +for NODE_NAME in $NODE_NAMES; do + echo "Running command on node: $NODE_NAME" + kubectl node_shell $NODE_NAME -- reboot +done