Skip to content

Commit 9f94693

Browse files
authored
Improve migration script Deployment handling (#412)
Helm could not apply some of the 1.0.0 changes to deployments because some fields were immutable. So, this adjusts the migration script to orphan the replicasets and delete the deployments. Then when helm upgrade recreates the deployments, they will adopt the orphaned replicasets and gradually recreate both replicasets and pods using the latest spec.
1 parent 209af8b commit 9f94693

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Stop generating the checksum labels for Auth Secret (#392) when existing secret provided or disabled (by @bmarick)
88
* Use `image.pullPolicy` for all containers including init containers that use `image.utilityImage`. (#397) (by @jk464)
99
* Add new `image.entrypoint` value to simplify using a custom entry point like `dumb-init` or `pid1` (if installed in the image). (#413) (by @cognifloyd)
10+
* Improve Deployments migration in `migrations/v1.0/standardize-labels.sh` by temporarily orphaning the old ReplicaSets. (#412) (by @cognifloyd)
1011

1112
## v1.0.0
1213
* Bump to latest CircleCI orb versions ([email protected] and [email protected] by @ZoeLeah)

migrations/v1.0/standardize-labels.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77
# so that helm upgrade will not create duplicate resources. The new label
88
# selectors do not match the old labels, so this script adds the new labels
99
# to the old resources. Thus, the new selectors will update them.
10+
#
11+
# NOTE: This will orphan all Pods, but they will be adopted by the new Deployments.
12+
# Specifically, we delete Deployment using propogationPolicy=Orphan,
13+
# and then when Helm creates the Deployments again, the selector will match the
14+
# current ReplicaSets (and their Pods) because we added the new labels.
15+
# Finally, the standard k8s Deployment upgrade will gradually replace old Pods.
1016

1117
# These env vars need to be set to use this script:
1218
# RELEASE_NAME (same as .Release.Name)
@@ -19,6 +25,9 @@ RELEASE_NAME=${RELEASE_NAME:-st2}
1925
NAMESPACE=${NAMESPACE:-default}
2026
CHART_NAME=${CHART_NAME:-stackstorm-ha} # see Chart.yaml
2127

28+
echo RELEASE_NAME=${RELEASE_NAME}
29+
echo NAMESPACE=${NAMESPACE}
30+
echo CHART_NAME=${CHART_NAME}
2231

2332
function klabel_app_instance() {
2433
kind=${1}
@@ -40,6 +49,17 @@ function klabel_app_name() {
4049
"app.kubernetes.io/name=${app}"
4150
}
4251

52+
function kdelete_cascade_orphan() {
53+
kind=${1}
54+
app=${2}
55+
kubectl delete "${kind}" \
56+
-n "${NAMESPACE}" \
57+
-l "vendor=stackstorm" \
58+
-l "release=${RELEASE_NAME}" \
59+
-l "app=${app}" \
60+
--cascade=orphan
61+
}
62+
4363
function k_get_app_names() {
4464
kind=${1}
4565
app=${2}
@@ -51,14 +71,17 @@ function k_get_app_names() {
5171
| jq -r '.items[] | select(.metadata.name | test("'"${app}"'")).metadata.labels.app'
5272
}
5373

74+
echo
5475
echo "Adding label app.kubernetes.io/instance=${RELEASE_NAME} (which will replace release=${RELEASE_NAME}) ..."
76+
echo
5577

5678
for kind in ConfigMap Secret Ingress Service ServiceAccount Deployment ReplicaSet Pod Job; do
5779
klabel_app_instance ${kind}
5880
done
5981

6082
echo
6183
echo "Adding label app.kubernetes.io/name=<app> (which will replace app=<app>) ..."
84+
echo
6285

6386
klabel_app_name ConfigMap st2
6487
klabel_app_name Secret st2
@@ -83,10 +106,12 @@ deployment_apps=(
83106
st2workflowengine
84107
)
85108
for app in "${deployment_apps[@]}"; do
86-
echo "Deployment app=${app} ..."
87-
klabel_app_name Deployment ${app}
109+
echo "ReplicaSet and Pods from Deployment app=${app} ..."
88110
klabel_app_name ReplicaSet ${app}
89111
klabel_app_name Pod ${app}
112+
echo "Deleting Deployment app=${app} (orphaning the ReplicaSets)..."
113+
kdelete_cascade_orphan Deployment ${app}
114+
# do not delete ReplicaSet or the Deployment will not adopt the pods
90115
done
91116

92117
service_apps=(
@@ -115,3 +140,7 @@ done
115140

116141
klabel_app_name ConfigMap st2tests
117142
klabel_app_name Pod st2tests
143+
144+
echo
145+
echo "ReplicaSets from Deployments have been orphaned, but new Deployments will adopt them."
146+
echo "Make sure to run helm upgrade soon to create the new Deployments."

0 commit comments

Comments
 (0)