Skip to content

Commit

Permalink
Add a flag --clean-up-orphaned-replica-sets to delete orphaned replic…
Browse files Browse the repository at this point in the history
…a sets when patching.
  • Loading branch information
qingling128 authored Jul 22, 2020
1 parent 50c8da5 commit 2e8361d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion kube/patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
set -e
set -u

CLEAN_UP_ORPHANED_REPLICA_SETS='--clean-up-orphaned-replica-sets'
usage() {
echo -e "Usage: $0 <deployment|statefulset> <name>\n"
echo -e "Usage: $0 <deployment|statefulset> <name> [${CLEAN_UP_ORPHANED_REPLICA_SETS}]\n"
}

if [ $# -le 1 ]; then
usage
exit 1
fi

SHOULD_CLEAN_UP=${3:-}

# Override to use a different Docker image name for the sidecar.
export SIDECAR_IMAGE_NAME=${SIDECAR_IMAGE_NAME:-'gcr.io/stackdriver-prometheus/stackdriver-prometheus-sidecar'}

Expand All @@ -37,3 +40,10 @@ spec:
- name: ${DATA_VOLUME}
mountPath: ${DATA_DIR}
"
if [[ "${SHOULD_CLEAN_UP}" == "${CLEAN_UP_ORPHANED_REPLICA_SETS}" ]]; then
# Delete the replica sets from the old deployment. If the Prometheus Server is
# a deployment that does not have `revisionHistoryLimit` set to 0, this is
# useful to avoid PVC conflicts between the old replica set and the new one
# that prevents the pod from entering a RUNNING state.
kubectl -n "${KUBE_NAMESPACE}" get rs | grep "$2-" | awk '{print $1}' | xargs kubectl delete -n "${KUBE_NAMESPACE}" rs
fi

0 comments on commit 2e8361d

Please sign in to comment.