Skip to content

Commit f556e6d

Browse files
committed
Add support for injecting config-hash label to Helm release secret
This can be leveraged to detect whether or not the release was created by the current configuration of a HelmChart resource on the controller side. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
1 parent 90b1226 commit f556e6d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

entry

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
helm_update() {
4-
LINE="$(${HELM} ls -f "^${NAME}\$" --namespace ${TARGET_NAMESPACE} --output json | jq -r "${JQ_CMD}" | tr '[:upper:]' '[:lower:]')"
4+
LINE="$(${HELM} ls -f "^${NAME}\$" --namespace ${TARGET_NAMESPACE} --output json | jq -r "${JQ_RELEASE_EXPRESSION}" | tr '[:upper:]' '[:lower:]')"
55
IFS=, read -r INSTALLED_VERSION STATUS REVISION _ <<<${LINE}
66
VALUES=""
77

@@ -26,7 +26,7 @@ helm_update() {
2626
# No current version and status, safe to install
2727
if [[ "${INSTALLED_VERSION}" =~ ^(|null)$ ]] && [[ "${STATUS}" =~ ^(|null)$ ]]; then
2828
echo "Installing ${HELM} chart" >> ${TERM_LOG}
29-
${HELM} "$@" ${NAME_ARG} ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${VALUES}
29+
${HELM} "$@" ${NAME_ARG} ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${LABELS_ARG} ${VALUES}
3030
exit
3131
fi
3232

@@ -45,7 +45,7 @@ helm_update() {
4545
echo "Retrying upgrade of ${HELM} chart" >> ${TERM_LOG}
4646
echo "Retrying upgrade of ${NAME}"
4747
shift 1
48-
${HELM} upgrade "$@" ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${VALUES}
48+
${HELM} upgrade "$@" ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${LABELS_ARG} ${VALUES}
4949
exit
5050
else
5151
STATUS=failed
@@ -60,7 +60,7 @@ helm_update() {
6060
echo "Upgrading ${HELM} chart" >> ${TERM_LOG}
6161
echo "Upgrading ${NAME}"
6262
shift 1
63-
${HELM} upgrade "$@" ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${VALUES}
63+
${HELM} upgrade "$@" ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${LABELS_ARG} ${VALUES}
6464
exit
6565
fi
6666

@@ -72,7 +72,7 @@ helm_update() {
7272
echo Deleted
7373
# Try installing now that we've uninstalled
7474
echo "Installing ${HELM} chart" >> ${TERM_LOG}
75-
${HELM} "$@" ${NAME_ARG} ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${VALUES}
75+
${HELM} "$@" ${NAME_ARG} ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${LABELS_ARG} ${VALUES}
7676
exit
7777
else
7878
echo "Release status is '${STATUS}' and failure policy is '${FAILURE_POLICY}', not 'reinstall'; waiting for operator intervention" >> ${TERM_LOG}
@@ -83,7 +83,7 @@ helm_update() {
8383

8484
# No special status handling necessary, do whatever we were asked to do
8585
echo "Installing ${HELM} chart" >> ${TERM_LOG}
86-
${HELM} "$@" ${NAME_ARG} ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${VALUES}
86+
${HELM} "$@" ${NAME_ARG} ${NAME} "${CHART}" ${CA_FILE_ARG} ${INSECURE_TLS_ARG} ${PLAIN_HTTP_ARG} ${TIMEOUT_ARG} ${LABELS_ARG} ${VALUES}
8787
}
8888

8989
helm_repo_init() {
@@ -155,7 +155,9 @@ INSECURE_TLS_ARG=""
155155
PLAIN_HTTP_ARG=""
156156
TIMEOUT_ARG=""
157157
PASS_CREDENTIALS_ARG=""
158-
JQ_CMD='"\(.[0].chart),\(.[0].status),\(.[0].revision)"'
158+
LABELS_ARG=""
159+
CONFIG_HASH_KEY="helmcharts.helm.cattle.io/configHash"
160+
JQ_RELEASE_EXPRESSION='first|(.chart,.status,.revision)'
159161

160162
set -e -v
161163
if [[ ${KUBERNETES_SERVICE_HOST} =~ .*:.* ]]; then
@@ -201,6 +203,10 @@ if [[ -n "${TIMEOUT}" ]]; then
201203
TIMEOUT_ARG="--timeout ${TIMEOUT}"
202204
fi
203205

206+
if [[ -n "${CONFIG_HASH}" ]]; then
207+
LABELS_ARG="--labels ${CONFIG_HASH_KEY}=${CONFIG_HASH}"
208+
fi
209+
204210
helm_content_decode
205211
if [[ "$1" != "delete" ]]; then
206212
helm_repo_init

0 commit comments

Comments
 (0)