-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunhelm.sh
More file actions
executable file
·68 lines (53 loc) · 1.9 KB
/
unhelm.sh
File metadata and controls
executable file
·68 lines (53 loc) · 1.9 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
[ -z "$DEBUG" ] || set -x
set -eo pipefail
HDIR="$PWD/helm"
export HELM_CACHE_HOME="$HDIR/cache"
export HELM_CONFIG_HOME="$HDIR/config"
export HELM_DATA_HOME="$HDIR/data"
export HELM_REPOSITORY_CACHE="$HDIR/repository"
export HELM_REPOSITORY_CONFIG="$HDIR/repositories.yaml"
[ $# -eq 0 ] && >&2 echo "First arg must be a value file path" && exit 1
VALUES=$1
IREPO="# unhelm-template-repo:"
CHART=$(echo $VALUES | cut -d'.' -f1)
NAME=$(echo $VALUES | cut -d'.' -f2)
! grep "^$IREPO" $VALUES && echo "Failed to find \"$IREPO \" in $VALUES" && exit 1
REPO=$(cat $VALUES | grep "^$IREPO" | cut -d' ' -f3)
echo "=> repo=$REPO chart=$CHART name=$NAME"
ORIGIN=$(echo $REPO | sed 's|.*://||' | sed 's|/$||' | sed 's|/|-|')
helm repo add $ORIGIN $REPO
helm repo update
helm show chart $ORIGIN/$CHART | grep ersion
BASE="./$CHART/$NAME"
echo "$BASE" | grep '//' || rm -r "./$BASE" 2>/dev/null || true
mkdir -p $BASE
echo "=> Generating a Kustomize base"
cat << EOF > $BASE/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
EOF
helm template $CHART $ORIGIN/$CHART -f $VALUES \
--namespace unhelm-namespace-placeholder \
--output-dir $BASE \
| sed "s|wrote $BASE/|- ./|" \
| sort | uniq \
| tee -a $BASE/kustomization.yaml
echo "=> Looking for namespace references"
mkdir -p .namespace-test
cat << EOF > .namespace-test/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: unhelm-namespace-replaced
resources:
- .$BASE
EOF
NSINFO=$BASE/unhelm-namespace-placeholder.txt
cat << EOF > $NSINFO
Note the following instances of namespace strings that Kustomize won't replace
=============================================================================
EOF
kustomize build .namespace-test | grep -C 5 unhelm-namespace-placeholder >> $NSINFO || true
cat $NSINFO | grep unhelm-namespace-placeholder | wc -l || true
echo "=> Done"