Initial release: poll until node Ready or NotReady.
This commit is contained in:
commit
0fa537065d
4 changed files with 138 additions and 0 deletions
22
.gitignore
vendored
Normal file
22
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# Secrets and credentials
|
||||
.env
|
||||
.env.*
|
||||
*.pem
|
||||
*.key
|
||||
*.p12
|
||||
credentials.json
|
||||
*-credentials*
|
||||
*secret*
|
||||
*.token
|
||||
|
||||
# Local tooling
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.pytest_cache/
|
||||
.venv/
|
||||
venv/
|
||||
|
||||
# Editor / OS
|
||||
.DS_Store
|
||||
*.swp
|
||||
*~
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2026 illusive-scarecrow
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
40
README.md
Normal file
40
README.md
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# wait-for-k8s-node-ready
|
||||
|
||||
Poll until a Kubernetes node reaches `Ready` or `NotReady`.
|
||||
|
||||
## Problem
|
||||
|
||||
Node maintenance scripts (drain, reboot, uncordon) need a reliable wait loop
|
||||
instead of fixed `sleep` calls. This script polls `kubectl` until the node
|
||||
reports the desired Ready condition or a timeout is reached.
|
||||
|
||||
## Requirements
|
||||
|
||||
- `bash`
|
||||
- `kubectl` configured for the target cluster
|
||||
- Permission to `get nodes`
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
./wait-for-k8s-node-ready.sh <node-name> <ready|notready> [timeout_seconds]
|
||||
```
|
||||
|
||||
Examples:
|
||||
|
||||
```bash
|
||||
./wait-for-k8s-node-ready.sh worker-1 notready 180
|
||||
./wait-for-k8s-node-ready.sh worker-1 ready 600
|
||||
```
|
||||
|
||||
Exit code `0` on success, `1` on timeout or invalid arguments.
|
||||
|
||||
## Limits
|
||||
|
||||
- Watches the `Ready` condition only.
|
||||
- Uses the current `kubectl` context; no context flag is provided.
|
||||
- Progress is printed as dots every two seconds.
|
||||
|
||||
## License
|
||||
|
||||
MIT — see [LICENSE](LICENSE).
|
||||
55
wait-for-k8s-node-ready.sh
Executable file
55
wait-for-k8s-node-ready.sh
Executable file
|
|
@ -0,0 +1,55 @@
|
|||
#!/bin/bash
|
||||
# Script Name: wait-for-k8s-node-ready.sh
|
||||
# Description:
|
||||
# v1.0.0 - 2026-06-08: Wait until a Kubernetes node reaches Ready or NotReady.
|
||||
#
|
||||
# Usage:
|
||||
# wait-for-k8s-node-ready.sh <node> <ready|notready> [timeout_seconds]
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
log() {
|
||||
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')] $*"
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 <node> <ready|notready> [timeout_seconds]"
|
||||
}
|
||||
|
||||
NODE="${1:-}"
|
||||
DESIRED="${2:-}"
|
||||
TIMEOUT="${3:-600}"
|
||||
|
||||
if [ -z "${NODE}" ] || [ -z "${DESIRED}" ]; then
|
||||
usage
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "${DESIRED}" in
|
||||
ready|Ready|READY) WANT="True"; LABEL="Ready" ;;
|
||||
notready|NotReady|NOTREADY) WANT="False"; LABEL="NotReady" ;;
|
||||
*) echo "Desired state must be ready or notready"; exit 1 ;;
|
||||
esac
|
||||
|
||||
log "Waiting for ${NODE} to become ${LABEL} (timeout: ${TIMEOUT}s)..."
|
||||
|
||||
end=$((SECONDS + TIMEOUT))
|
||||
while [ "${SECONDS}" -lt "${end}" ]; do
|
||||
current=$(kubectl get node "${NODE}" -o jsonpath='{.status.conditions[?(@.type=="Ready")].status}' 2>/dev/null || echo "Unknown")
|
||||
|
||||
if [ "${WANT}" = "False" ] && { [ "${current}" = "False" ] || [ "${current}" = "Unknown" ]; }; then
|
||||
log "Node ${NODE} is ${LABEL}."
|
||||
exit 0
|
||||
fi
|
||||
if [ "${WANT}" = "True" ] && [ "${current}" = "True" ]; then
|
||||
log "Node ${NODE} is ${LABEL}."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
printf "."
|
||||
sleep 2
|
||||
done
|
||||
|
||||
echo
|
||||
log "Timed out waiting for ${NODE} to become ${LABEL}."
|
||||
exit 1
|
||||
Loading…
Add table
Reference in a new issue