Skip to content

Commit bef7dd7

Browse files
authored
Add helm-set-status plugin to handle pending releases (#28)
* Add helm-set-status plugin to handle pending releases Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
1 parent 8e72577 commit bef7dd7

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

entry

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,25 @@ helm_update() {
3333
exit
3434
fi
3535

36-
# Upgrade only if the status is already deployed, or if a previous upgrade was interrupted
37-
if [[ "${STATUS}" =~ ^(deployed|pending-upgrade)$ ]]; then
36+
# If a previous helm_v3 operation was interrupted unexpectedly, set it to failed.
37+
if [[ "${STATUS}" =~ ^(pending-install|pending-upgrade|pending-rollback)$ ]] && [[ "${HELM}" == "helm_v3" ]]; then
38+
echo Previous helm job was interrupted, updating status from ${STATUS} to failed
39+
${HELM} set-status ${NAME} failed --namespace ${TARGET_NAMESPACE}
40+
41+
# Upgrades can be retried; install and rollback will be handled as failure below.
42+
# If this upgrade also fails, retries of the job will handle that as failure due to the release state change.
43+
if [[ "${STATUS}" == "pending-upgrade" ]]; then
44+
echo "Retrying upgrade of ${NAME}"
45+
shift 1
46+
${HELM} upgrade "$@" ${NAME} ${CHART} ${TIMEOUT_ARG} ${VALUES}
47+
exit
48+
else
49+
STATUS=failed
50+
fi
51+
fi
52+
53+
# Upgrade only if the chart is already deployed
54+
if [[ "${STATUS}" == "deployed" ]]; then
3855
echo Already installed ${NAME}, upgrading
3956
shift 1
4057
${HELM} upgrade "$@" ${NAME} ${CHART} ${TIMEOUT_ARG} ${VALUES}

package/Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,18 @@ RUN mv /usr/bin/helm /usr/bin/helm_v2
66
RUN curl https://get.helm.sh/helm-v3.5.4-linux-${ARCH}.tar.gz | tar xvzf - --strip-components=1 -C /usr/bin
77
RUN mv /usr/bin/helm /usr/bin/helm_v3
88

9+
FROM golang:1.16-alpine3.12 as plugins
10+
RUN apk add -U curl ca-certificates build-base binutils-gold
11+
ARG ARCH
12+
COPY --from=extract /usr/bin/helm_v3 /usr/bin/helm
13+
RUN mkdir -p /go/src/github.com/k3s-io/helm-set-status && \
14+
curl -L https://github.com/k3s-io/helm-set-status/archive/refs/tags/v0.1.1.tar.gz | tar xvzf - --strip-components=1 -C /go/src/github.com/k3s-io/helm-set-status && \
15+
make -C /go/src/github.com/k3s-io/helm-set-status install
16+
917
FROM alpine:3.12
1018
RUN apk add -U --no-cache ca-certificates jq bash git
1119
COPY --from=extract /usr/bin/helm_v2 /usr/bin/helm_v3 /usr/bin/tiller /usr/bin/
20+
COPY --from=plugins /root/.local/share/helm/plugins/ /root/.local/share/helm/plugins/
1221
COPY entry /usr/bin/
1322
ENTRYPOINT ["entry"]
1423
ENV STABLE_REPO_URL=https://charts.helm.sh/stable/

0 commit comments

Comments
 (0)