Skip to content

Commit

Permalink
Add helm-set-status plugin to handle pending releases (#28)
Browse files Browse the repository at this point in the history
* Add helm-set-status plugin to handle pending releases

Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond authored Jun 16, 2021
1 parent 8e72577 commit bef7dd7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
21 changes: 19 additions & 2 deletions entry
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,25 @@ helm_update() {
exit
fi

# Upgrade only if the status is already deployed, or if a previous upgrade was interrupted
if [[ "${STATUS}" =~ ^(deployed|pending-upgrade)$ ]]; then
# If a previous helm_v3 operation was interrupted unexpectedly, set it to failed.
if [[ "${STATUS}" =~ ^(pending-install|pending-upgrade|pending-rollback)$ ]] && [[ "${HELM}" == "helm_v3" ]]; then
echo Previous helm job was interrupted, updating status from ${STATUS} to failed
${HELM} set-status ${NAME} failed --namespace ${TARGET_NAMESPACE}

# Upgrades can be retried; install and rollback will be handled as failure below.
# If this upgrade also fails, retries of the job will handle that as failure due to the release state change.
if [[ "${STATUS}" == "pending-upgrade" ]]; then
echo "Retrying upgrade of ${NAME}"
shift 1
${HELM} upgrade "$@" ${NAME} ${CHART} ${TIMEOUT_ARG} ${VALUES}
exit
else
STATUS=failed
fi
fi

# Upgrade only if the chart is already deployed
if [[ "${STATUS}" == "deployed" ]]; then
echo Already installed ${NAME}, upgrading
shift 1
${HELM} upgrade "$@" ${NAME} ${CHART} ${TIMEOUT_ARG} ${VALUES}
Expand Down
9 changes: 9 additions & 0 deletions package/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,18 @@ RUN mv /usr/bin/helm /usr/bin/helm_v2
RUN curl https://get.helm.sh/helm-v3.5.4-linux-${ARCH}.tar.gz | tar xvzf - --strip-components=1 -C /usr/bin
RUN mv /usr/bin/helm /usr/bin/helm_v3

FROM golang:1.16-alpine3.12 as plugins
RUN apk add -U curl ca-certificates build-base binutils-gold
ARG ARCH
COPY --from=extract /usr/bin/helm_v3 /usr/bin/helm
RUN mkdir -p /go/src/github.com/k3s-io/helm-set-status && \
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 && \
make -C /go/src/github.com/k3s-io/helm-set-status install

FROM alpine:3.12
RUN apk add -U --no-cache ca-certificates jq bash git
COPY --from=extract /usr/bin/helm_v2 /usr/bin/helm_v3 /usr/bin/tiller /usr/bin/
COPY --from=plugins /root/.local/share/helm/plugins/ /root/.local/share/helm/plugins/
COPY entry /usr/bin/
ENTRYPOINT ["entry"]
ENV STABLE_REPO_URL=https://charts.helm.sh/stable/
Expand Down

0 comments on commit bef7dd7

Please sign in to comment.