-
Notifications
You must be signed in to change notification settings - Fork 3
/
helm
executable file
·37 lines (36 loc) · 1.61 KB
/
helm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#! /bin/sh
all_cmds=$(helm.bin | grep -A50 "Available Commands" | grep -B50 "Flags:" | tail -n+2 | head -n-2 | awk '{ print $1 }')
# Move --kube-context option at the end for easier parsing
cmd=$(echo "$@" | sed 's/\(--kube-context [a-zA-Z0-9\-]* \)\(.*\)/\2 \1/g')
arg=$(echo "${cmd}" | cut -d " " -f1)
cmd=$(echo "$cmd" | sed 's/--kube-context $//g')
# helm secrets only supports a few helm commands
if [ "${arg}" = "template" ] || [ "${arg}" = "install" ] || [ "${arg}" = "upgrade" ] || [ "${arg}" = "lint" ] || [ "${arg}" = "diff" ]
then
# Helm secrets add some useless outputs to every commands including template, namely
# 'remove: <secret-path>.dec' for every decoded secrets.
# As argocd use helm template output to compute the resources to apply, these outputs
# will cause a parsing error from argocd, so we need to remove them.
# We cannot use exec here as we need to pipe the output so we call helm in a subprocess and
# handle the return code ourselves.
tmp_err=$(mktemp)
if [ ${HELM_OCTOPUS_ENABLED:=0} -eq 1 ]; then
out=$(helm.bin octopus --plugin=secrets $cmd 2>"${tmp_err}")
else
out=$(helm.bin secrets $cmd 2>"${tmp_err}")
fi
code=$?
if [ $code -eq 0 ]; then
# printf insted of echo here because we really don't want any backslash character processing
printf '%s\n' "$out" | sed -E "/^removed '.+\.dec'$/d" | grep -v '\[helm-secrets\]'
rm "${tmp_err}"
exit 0
else
cat "${tmp_err}" > /dev/stderr
rm "${tmp_err}"
exit $code
fi
else
# helm.bin is the original helm binary
exec helm.bin $cmd
fi