Skip to content

Commit

Permalink
add inputs for registry image and preboot command
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg May committed Aug 24, 2020
1 parent 8cbaec6 commit a50be91
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.zip
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
kubectl node-restart --selector node-role.kubernetes.io/master
```

- execute a command prior to reboot labels

```bash
kubectl node-restart all --command "echo 'hello world'"
```

- perform a dry-run

```bash
Expand All @@ -42,4 +48,16 @@

```bash
kubectl node-restart all --sleep 120
```
```

- Pull the Alpine image from a private registry

```bash
kubectl node-restart all --registry myregistry.local/library/alpine:3.9
```


<!--
zip v1.0.1.zip node-restart.sh LICENSE
openssl dgst -sha256 v1.0.1.zip
-->
21 changes: 18 additions & 3 deletions node-restart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ force=false
dryrun=false
blue='\033[0;34m'
nocolor='\033[0m'
rebootcommand='touch /node-restart-flag && reboot'

function print_usage() {
echo "Usage: kubectl node-restart [<options>]"
Expand All @@ -20,6 +21,10 @@ function print_usage() {
echo ""
echo "-s|--sleep Sleep delay between restarting Nodes (default 20s)"
echo ""
echo "-r|--registry Pull Alpine image from an alternate registry"
echo ""
echo "-c|--command Pre-restart command to be executed"
echo ""
echo "-h|--help Print usage and exit"
}

Expand Down Expand Up @@ -50,6 +55,16 @@ do
shift
shift
;;
-r|--registry)
image="$2"
shift
shift
;;
-c|--command)
rebootcommand="$2 && touch /node-restart-flag && reboot"
shift
shift
;;
-h|--help)
print_usage
exit 0
Expand Down Expand Up @@ -109,7 +124,7 @@ if [ "$allnodes" == "true" ]; then
done
elif [ ! -z "$selector" ]; then
nodes=$(kubectl get nodes --selector=$selector -o jsonpath={.items[*].metadata.name})
echo -e "${blue}Targeting nodes:${nocolor}"
echo -e "${blue}Targeting selective nodes:${nocolor}"
for node in $nodes; do
echo " $node"
done
Expand Down Expand Up @@ -139,7 +154,7 @@ for node in $nodes; do
if $dryrun; then
echo "kubectl create job $pod"
else
cat <<EOT | kubectl apply -f -
cat << EOT | kubectl apply -f -
apiVersion: batch/v1
kind: Job
metadata:
Expand All @@ -159,7 +174,7 @@ spec:
- name: $pod
image: $image
command: [ "nsenter", "--target", "1", "--mount", "--uts", "--ipc", "--pid", "--", "bash", "-c" ]
args: [ "if [ -f /node-restart-flag ]; then rm /node-restart-flag && exit 0; else touch /node-restart-flag && reboot && exit 1; fi" ]
args: [ "if [ -f /node-restart-flag ]; then rm /node-restart-flag && exit 0; else $rebootcommand && exit 1; fi" ]
securityContext:
privileged: true
restartPolicy: Never
Expand Down
8 changes: 4 additions & 4 deletions node-restart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ kind: Plugin
metadata:
name: node-restart
spec:
version: "v1.0.0"
version: "v1.0.1"
platforms:
- selector:
matchExpressions:
- {key: os, operator: In, values: [darwin, linux]}
uri: https://github.com/MnrGreg/kubectl-node-restart/releases/download/v1.0.0/v1.0.0.zip
sha256: "44db0eee9603085652837d26c5352287864f158b557f78ae19325724640535f8"
uri: https://github.com/MnrGreg/kubectl-node-restart/releases/download/v1.0.1/v1.0.1.zip
sha256: "3ab20f10179111f54410f4ac41ef15231aeba6e7bf6a24b7cf3a54d30a293ce4"
files:
- from: "*.sh"
to: "."
- from: "LICENSE"
to: "."
bin: "node-restart.sh"
shortDescription: >-
Restart cluster nodes sequentially & gracefully
Restart cluster nodes sequentially and gracefully
homepage: https://github.com/mnrgreg/kubectl-node-restart
caveats: |
Execution of this plugin requires Kubernetes cluster-admin Rolebindings
Expand Down

0 comments on commit a50be91

Please sign in to comment.