Skip to content

Commit

Permalink
Remove helm v2 support
Browse files Browse the repository at this point in the history
Signed-off-by: Brad Davidson <[email protected]>
  • Loading branch information
brandond committed Jul 30, 2024
1 parent bbf9df2 commit 234d5bc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 67 deletions.
79 changes: 17 additions & 62 deletions entry
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/bin/bash

helm_update() {
if [[ "${HELM}" == "helm_v3" ]]; then
LINE="$(${HELM} ls --all -f "^${NAME}\$" --namespace ${TARGET_NAMESPACE} --output json | jq -r "${JQ_CMD}" | tr '[:upper:]' '[:lower:]')"
else
LINE="$(${HELM} ls --all "^${NAME}\$" --output json | jq -r "${JQ_CMD}" | tr '[:upper:]' '[:lower:]')"
fi
LINE="$(${HELM} ls --all -f "^${NAME}\$" --namespace ${TARGET_NAMESPACE} --output json | jq -r "${JQ_CMD}" | tr '[:upper:]' '[:lower:]')"
IFS=, read -r INSTALLED_VERSION STATUS _ <<<${LINE}
VALUES=""

Expand All @@ -19,14 +15,8 @@ helm_update() {
echo "No ${HELM} chart installed; nothing to delete" >> ${TERM_LOG}
exit
fi
if [[ "${HELM}" == "helm_v3" ]]; then
echo "Uninstalling ${HELM} chart" >> ${TERM_LOG}
${HELM} uninstall ${NAME} --namespace ${TARGET_NAMESPACE} --wait || true
else
echo "Deleting and purging ${HELM} chart" >> ${TERM_LOG}
${HELM} delete ${NAME} || true
${HELM} "$@" --purge ${NAME}
fi
echo "Uninstalling ${HELM} chart" >> ${TERM_LOG}
${HELM} uninstall ${NAME} --namespace ${TARGET_NAMESPACE} --wait || true
exit
fi

Expand All @@ -37,8 +27,8 @@ helm_update() {
exit
fi

# 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
# If a previous helm operation was interrupted unexpectedly, set it to failed.
if [[ "${STATUS}" =~ ^(pending-install|pending-upgrade|pending-rollback)$ ]]; then
echo Previous helm job was interrupted, updating status from ${STATUS} to failed
echo "Resetting ${HELM} release status from '${STATUS}' to 'failed'" >> ${TERM_LOG}
${HELM} set-status ${NAME} failed --namespace ${TARGET_NAMESPACE}
Expand All @@ -59,11 +49,7 @@ helm_update() {
# Upgrade only if the chart is already deployed
if [[ "${STATUS}" == "deployed" ]]; then
echo "Already installed ${NAME}"
if [[ "${HELM}" == "helm_v3" ]]; then
${HELM} mapkubeapis ${NAME} --namespace ${TARGET_NAMESPACE}
else
${HELM} mapkubeapis ${NAME} --v2
fi
${HELM} mapkubeapis ${NAME} --namespace ${TARGET_NAMESPACE}

echo "Upgrading ${HELM} chart" >> ${TERM_LOG}
echo "Upgrading ${NAME}"
Expand All @@ -75,13 +61,8 @@ helm_update() {
# The chart is in a bad state; try uninstalling it first
if [[ "${STATUS}" =~ ^(deleted|failed|null|unknown)$ ]]; then
if [[ "${FAILURE_POLICY:-reinstall}" == "reinstall" ]]; then
if [[ "${HELM}" == "helm_v3" ]]; then
echo "Uninstalling ${STATUS} ${HELM} chart" >> ${TERM_LOG}
${HELM} uninstall ${NAME} --namespace ${TARGET_NAMESPACE} --wait
else
echo "Purging ${STATUS} ${HELM} chart" >> ${TERM_LOG}
${HELM} "$@" --purge ${NAME}
fi
echo "Uninstalling ${STATUS} ${HELM} chart" >> ${TERM_LOG}
${HELM} uninstall ${NAME} --namespace ${TARGET_NAMESPACE} --wait
echo Deleted
# Try installing now that we've uninstalled
echo "Installing ${HELM} chart" >> ${TERM_LOG}
Expand All @@ -107,22 +88,13 @@ helm_repo_init() {
return
fi

if [[ "${HELM}" == "helm_v3" ]]; then
if [[ ${CHART} == stable/* ]]; then
${HELM} repo add ${CA_FILE_ARG} stable ${STABLE_REPO_URL}
${HELM} repo update
fi
else
${HELM} repo update --strict || ${HELM} repo remove stable
if [[ ${CHART} == stable/* ]]; then
${HELM} repo add ${CA_FILE_ARG} stable ${STABLE_REPO_URL}
${HELM} repo update
fi

if [[ -n "${REPO}" ]]; then
if [[ -f "${AUTH_DIR}/username" ]] && [[ -f "${AUTH_DIR}/password" ]]; then
if [[ "${HELM}" == "helm_v2" ]]; then
echo "Repo authentication is not supported with v2 charts" >> ${TERM_LOG}
echo "Repo authentication is not supported with v2 charts"
exit 1
fi
if [[ "${AUTH_PASS_CREDENTIALS}" == "true" ]]; then
PASS_CREDENTIALS_ARG="--pass-credentials"
fi
Expand Down Expand Up @@ -158,7 +130,7 @@ export TERM_LOG=/dev/termination-log
export SSL_CERT_FILE=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
export SSL_CERT_DIR=/etc/ssl/certs
export HELM_TLS_CA_CERT=${SSL_CERT_FILE}
HELM="helm_v3"
HELM="helm"
NAME_ARG=""
CA_FILE_ARG=""
TIMEOUT_ARG=""
Expand All @@ -175,23 +147,10 @@ fi

set +v -x

if [[ "${BOOTSTRAP}" != "true" ]]; then
tiller --listen=127.0.0.1:44134 --storage=secret &
export HELM_HOST=127.0.0.1:44134

helm_v2 init --skip-refresh --client-only --stable-repo-url ${STABLE_REPO_URL}
V2_CHART_EXISTS=$(timeout -s KILL 30 helm_v2 ls --all "^${NAME}\$" --output json | jq -r '.Releases | length')
fi

if [[ "${V2_CHART_EXISTS}" == "1" ]] || [[ "${HELM_VERSION}" == "v2" ]]; then
if [[ "${BOOTSTRAP}" == "true" ]]; then
echo "Can't bootstrap ${HELM} chart" >> ${TERM_LOG}
echo "Error: bootstrap flag can't be set with helm version 2 charts, please remove the bootstrap flag and update the chart"
exit 1
fi
HELM="helm_v2"
NAME_ARG="--name"
JQ_CMD='"\(.Releases[0].AppVersion),\(.Releases[0].Status)"'
if [[ "${HELM_VERSION}" == "v2" ]]; then
echo "Helm v2 is EOL effective 2020-11-13; upgrade your chart to helm v3" >> ${TERM_LOG}
echo "Helm v2 is EOL effective 2020-11-13; upgrade your chart to helm v3"
exit 1
fi

shopt -s nullglob
Expand All @@ -211,11 +170,7 @@ if [[ -f "/tmp/ca-file.pem" ]]; then
fi

if [[ -n "${TIMEOUT}" ]]; then
if [[ "${HELM}" == "helm_v3" ]]; then
TIMEOUT_ARG="--timeout ${TIMEOUT}"
else
echo "Warning: timeout flag can't be set with version 2 charts, using default timeout"
fi
TIMEOUT_ARG="--timeout ${TIMEOUT}"
fi

helm_content_decode
Expand Down
7 changes: 2 additions & 5 deletions package/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
FROM alpine:3.20 as extract
RUN apk add -U curl ca-certificates
ARG ARCH
RUN curl -sL https://get.helm.sh/helm-v2.17.0-linux-${ARCH}.tar.gz | tar xvzf - --strip-components=1 -C /usr/bin
RUN mv /usr/bin/helm /usr/bin/helm_v2
RUN curl -sL https://get.helm.sh/helm-v3.15.3-linux-${ARCH}.tar.gz | tar xvzf - --strip-components=1 -C /usr/bin
RUN mv /usr/bin/helm /usr/bin/helm_v3
COPY entry /usr/bin/

FROM golang:1.22-alpine3.20 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
COPY --from=extract /usr/bin/helm /usr/bin/helm
RUN mkdir -p /go/src/github.com/k3s-io/helm-set-status && \
curl -sL https://github.com/k3s-io/helm-set-status/archive/refs/tags/v0.2.0.tar.gz | tar xvzf - --strip-components=1 -C /go/src/github.com/k3s-io/helm-set-status && \
cd /go/src/github.com/k3s-io/helm-set-status && \
Expand All @@ -37,7 +34,7 @@ RUN apk --no-cache upgrade && \
adduser -D -u 1000 -s /bin/bash klipper-helm
WORKDIR /home/klipper-helm
COPY --chown=1000:1000 --from=plugins /root/.local/share/helm/plugins/ /home/klipper-helm/.local/share/helm/plugins/
COPY --from=extract /usr/bin/helm_v2 /usr/bin/helm_v3 /usr/bin/tiller /usr/bin/entry /usr/bin/
COPY --from=extract /usr/bin/helm /usr/bin/entry /usr/bin/
ENTRYPOINT ["entry"]
ENV STABLE_REPO_URL=https://charts.helm.sh/stable/
ENV TIMEOUT=
Expand Down

0 comments on commit 234d5bc

Please sign in to comment.