Skip to content

Commit cdfc90b

Browse files
committed
add migrations/standardize-labels.sh
1 parent 12d7981 commit cdfc90b

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

migrations/standardize-labels.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
# We switched to the standard labels recommend in Helm's "Best Practices" doc.
4+
# https://helm.sh/docs/chart_best_practices/labels/#standard-labels
5+
#
6+
# This script adds those labels to all the resources in an existing release,
7+
# so that helm upgrade will not create duplicate resources. The new label
8+
# selectors do not match the old labels, so this script adds the new labels
9+
# to the old resources. Thus, the new selectors will update them.
10+
11+
# These env vars need to be set to use this script:
12+
# RELEASE_NAME (same as .Release.Name)
13+
# NAMESPACE (same as .Release.Namespace)
14+
#
15+
# For example:
16+
# RELEASE_NAME=st2 NAMESPACE=st2 migrations/standardize-labels.sh
17+
18+
RELEASE_NAME=${RELEASE_NAME:-st2}
19+
NAMESPACE=${NAMESPACE:-default}
20+
CHART_NAME=${CHART_NAME:-stackstorm-ha} # see Chart.yaml
21+
22+
23+
function klabel_app_instance() {
24+
kind=${1}
25+
kubectl label "${kind}" \
26+
-n "${NAMESPACE}" \
27+
-l "vendor=stackstorm" \
28+
-l "release=${RELEASE_NAME}" \
29+
"app.kubernetes.io/instance=${RELEASE_NAME}"
30+
}
31+
32+
function klabel_app_name() {
33+
kind=${1}
34+
app=${2}
35+
kubectl label "${kind}" \
36+
-n "${NAMESPACE}" \
37+
-l "vendor=stackstorm" \
38+
-l "release=${RELEASE_NAME}" \
39+
-l "app=${app}" \
40+
"app.kubernetes.io/name=${app}"
41+
}
42+
43+
for kind in ConfigMap Secret Ingress Service ServiceAccount Deployment ReplicaSet Pod Job; do
44+
klabel_app_instance ${kind}
45+
done
46+
47+
klabel_app_name ConfigMap st2
48+
klabel_app_name Secret st2
49+
klabel_app_name Secret st2chatops
50+
klabel_app_name Secret ${CHART_NAME} # for ServiceAccount
51+
klabel_app_name ServiceAccount ${CHART_NAME}
52+
klabel_app_name Ingress ingress
53+
54+
for app in st2actionrunner st2api st2auth st2chatops st2client st2garbagecollector st2notifier st2rulesengine st2scheduler st2stream st2timersengine st2web st2workflowengine; do
55+
klabel_app_name Deployment ${app}
56+
klabel_app_name ReplicaSet ${app}
57+
klabel_app_name Pod ${app}
58+
done
59+
60+
for app in st2api st2auth st2chatops st2stream st2web; do
61+
klabel_app_name Service ${app}
62+
done
63+
64+
for app in st2 st2-apply-rbac-definitions st2-register-content; do
65+
klabel_app_name Job ${app}
66+
klabel_app_name Pod ${app}
67+
done

0 commit comments

Comments
 (0)