Skip to content

Commit

Permalink
add script test
Browse files Browse the repository at this point in the history
  • Loading branch information
topahadzi committed Oct 27, 2023
1 parent 026cb9d commit 5ed3aa2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
RUN mv ./kubectl-node_shell /usr/local/bin/kubectl-node_shell

COPY test.sh /app
WORKDIR /app
CMD ["/bin/sh","-c","/app/test.sh"]
18 changes: 18 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5ed3aa2

Please sign in to comment.