Skip to content

Commit 2e8361d

Browse files
authored
Add a flag --clean-up-orphaned-replica-sets to delete orphaned replica sets when patching.
1 parent 50c8da5 commit 2e8361d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

kube/patch.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
set -e
44
set -u
55

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

1011
if [ $# -le 1 ]; then
1112
usage
1213
exit 1
1314
fi
1415

16+
SHOULD_CLEAN_UP=${3:-}
17+
1518
# Override to use a different Docker image name for the sidecar.
1619
export SIDECAR_IMAGE_NAME=${SIDECAR_IMAGE_NAME:-'gcr.io/stackdriver-prometheus/stackdriver-prometheus-sidecar'}
1720

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

0 commit comments

Comments
 (0)