mirror of
https://github.com/TECHNOFAB11/kubenix.git
synced 2025-12-12 16:10:05 +01:00
Package Kubenix script (#62)
* Package Kubenix script * Update changelog * Fix hardcoded kubeconfig * Expose generated manifest with Kubenix CLI derivation passthru
This commit is contained in:
parent
5692af23e0
commit
c00c78b982
3 changed files with 93 additions and 74 deletions
61
pkgs/kubenix.sh
Normal file
61
pkgs/kubenix.sh
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -uo pipefail
|
||||
|
||||
function _help() {
|
||||
echo "
|
||||
kubenix - Kubernetes management with Nix
|
||||
|
||||
commands:
|
||||
"" - run diff, prompt for confirmation, then apply
|
||||
apply - create resources in target cluster
|
||||
diff - show a diff between configured and live resources
|
||||
render - print resource manifests to stdout
|
||||
|
||||
options:
|
||||
-h --help - show this menu
|
||||
"
|
||||
}
|
||||
|
||||
function _kubectl() {
|
||||
vals eval -fail-on-missing-key-in-map <$MANIFEST | kubectl $@
|
||||
}
|
||||
|
||||
# if no args given, add empty string
|
||||
[ $# -eq 0 ] && set -- ""
|
||||
|
||||
# parse arguments
|
||||
while test $# -gt 0; do
|
||||
case "$1" in
|
||||
|
||||
-h | --help)
|
||||
_help
|
||||
exit 0
|
||||
;;
|
||||
|
||||
"")
|
||||
_kubectl diff -f - --prune
|
||||
if [[ $? -eq 1 ]]; then
|
||||
read -p 'apply? [y/N]: ' response
|
||||
[[ $response == "y" ]] && _kubectl apply -f - --prune --all
|
||||
fi
|
||||
shift
|
||||
;;
|
||||
|
||||
render)
|
||||
vals eval <$MANIFEST
|
||||
shift
|
||||
;;
|
||||
|
||||
apply | diff)
|
||||
_kubectl $@ -f - --prune
|
||||
shift
|
||||
;;
|
||||
|
||||
*)
|
||||
_kubectl $@
|
||||
shift
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
Loading…
Add table
Add a link
Reference in a new issue