Skip to content

Commit ac8f73f

Browse files
committed
Add check for expected revision on upgrade and uninstall
Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
1 parent 180678e commit ac8f73f

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ RUN if [ "${TARGETARCH}" = "arm/v7" ]; then \
66
else \
77
ARCH="${TARGETARCH}" ; \
88
fi && \
9-
curl -sL https://get.helm.sh/helm-v3.19.5-linux-${ARCH}.tar.gz | tar xvzf - --strip-components=1 -C /usr/bin
9+
curl -sL https://get.helm.sh/helm-v3.20.1-linux-${ARCH}.tar.gz | tar xvzf - --strip-components=1 -C /usr/bin
1010
COPY entry /usr/bin/
1111

1212
FROM golang:1.25-alpine3.23 AS plugins
@@ -17,13 +17,13 @@ RUN go version
1717
RUN mkdir -p /go/src/github.com/k3s-io/helm-set-status && \
1818
curl -sL https://github.com/k3s-io/helm-set-status/archive/refs/tags/v0.3.0.tar.gz | tar xvzf - --strip-components=1 -C /go/src/github.com/k3s-io/helm-set-status && \
1919
cd /go/src/github.com/k3s-io/helm-set-status && \
20-
go mod edit --replace helm.sh/helm/v3=helm.sh/helm/v3@v3.19.5 && \
20+
go mod edit --replace helm.sh/helm/v3=helm.sh/helm/v3@v3.20.1 && \
2121
go mod tidy && \
2222
make install
2323
RUN mkdir -p /go/src/github.com/helm/helm-mapkubeapis && \
2424
curl -sL https://github.com/helm/helm-mapkubeapis/archive/refs/tags/v0.6.1.tar.gz | tar xvzf - --strip-components=1 -C /go/src/github.com/helm/helm-mapkubeapis && \
2525
cd /go/src/github.com/helm/helm-mapkubeapis && \
26-
go mod edit --replace helm.sh/helm/v3=helm.sh/helm/v3@v3.19.5 && \
26+
go mod edit --replace helm.sh/helm/v3=helm.sh/helm/v3@v3.20.1 && \
2727
go mod tidy && \
2828
make && \
2929
mkdir -p /root/.local/share/helm/plugins/helm-mapkubeapis && \

entry

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

88
for VALUES_FILE in /config/*.yaml; do
@@ -15,6 +15,9 @@ helm_update() {
1515
echo "No ${HELM} chart installed; nothing to delete" >> ${TERM_LOG}
1616
exit
1717
fi
18+
19+
check_revision ${REVISION}
20+
1821
echo "Uninstalling ${HELM} chart" >> ${TERM_LOG}
1922
${HELM} uninstall ${NAME} --namespace ${TARGET_NAMESPACE} --wait || true
2023
exit
@@ -27,6 +30,8 @@ helm_update() {
2730
exit
2831
fi
2932

33+
check_revision ${REVISION}
34+
3035
# If a previous helm operation was interrupted unexpectedly or release state is corrupted, set it to failed.
3136
if [[ "${STATUS}" =~ ^(pending-install|pending-upgrade|pending-rollback|superseded|uninstalling)$ ]]; then
3237
echo Previous helm job was interrupted, updating status from ${STATUS} to failed
@@ -124,6 +129,15 @@ helm_content_decode() {
124129
set +e
125130
}
126131

132+
check_revision() {
133+
REVISION="$1"
134+
if [[ -n "${EXPECTED_RELEASE_REVISION}" ]] && [[ "${EXPECTED_RELEASE_REVISION}" != "${REVISION}" ]]; then
135+
echo "Current release revision ${REVISION} does not match expected revision ${EXPECTED_RELEASE_REVISION}" >> ${TERM_LOG}
136+
echo "Current release revision ${REVISION} does not match expected revision ${EXPECTED_RELEASE_REVISION}"
137+
exit 64
138+
fi
139+
}
140+
127141
export CA_FILE=/config/ca-file.pem
128142
export CA_DIR=/ca-files
129143
export AUTH_DIR=/auth
@@ -138,7 +152,7 @@ INSECURE_TLS_ARG=""
138152
PLAIN_HTTP_ARG=""
139153
TIMEOUT_ARG=""
140154
PASS_CREDENTIALS_ARG=""
141-
JQ_CMD='"\(.[0].chart),\(.[0].status)"'
155+
JQ_CMD='"\(.[0].chart),\(.[0].status),\(.[0].revision)"'
142156

143157
set -e -v
144158
if [[ ${KUBERNETES_SERVICE_HOST} =~ .*:.* ]]; then

0 commit comments

Comments
 (0)