Skip to content

Instantly share code, notes, and snippets.

@monsterxx03
Created August 23, 2019 07:30
Show Gist options
  • Save monsterxx03/9046916fde705e73992a9857a5875ae2 to your computer and use it in GitHub Desktop.
Save monsterxx03/9046916fde705e73992a9857a5875ae2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
: '
Simulate `kubectl rollout restart` commnad in 1.15.
'
set -o pipefail
set -o nounset
set -o errexit
usage() {
cat <<EOF
Usage: kubectl restart -d <deployment name> -n <namespace>
example:
kubectl restart -d nginx -n test-ns
EOF
exit 0
}
[[ $# -eq 0 ]] && usage
NAMESPACE="default"
DEPLOYMENT=""
while getopts ":n:d:h" arg; do
case $arg in
n) # namespace
NAMESPACE=${OPTARG}
;;
d) # deployment name
DEPLOYMENT=${OPTARG}
;;
h) # Display help
usage
;;
*)
;;
esac
done
[[ -z $DEPLOYMENT ]] && echo "missing deployment name" && exit 1
kubectl patch deployment $DEPLOYMENT -n $NAMESPACE -p '{"spec": {"template": {"metadata": {"annotations": {"cliRestartAt": "'$(date +%s)'"}}}}}'
kubectl rollout status -n $NAMESPACE deployment/${DEPLOYMENT} -w
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment