forked from kubernetes-sigs/kustomize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChartInflatorExec
executable file
·90 lines (72 loc) · 1.97 KB
/
ChartInflatorExec
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
set -e
# Helm chart inflator
# Reads a file like this
#
# apiVersion: kustomize.config.k8s.io/v1
# kind: ChartInflatorExec
# metadata:
# name: notImportantHere
# chartName: nameOfStableChart
# values: /abs/path/to/local/values/file
# chartHome: /abs/path/local/chart/storage
# helmHome: /abs/path/to/helm/config
# helmBin: /abs/path/to/helmBin
#
# fetches the given chart from stable/$chartName,
# and inflates it to stdout, using the given values file.
#
# chartDir default: $TMP_DIR/charts
# chartDir default:
# Example execution:
# ./plugins/kustomize.config.k8s.io/v1/ChartInflatorExec configFile.yaml
# Yaml parsing is a ridiculous thing to do in bash,
# but let's try:
function parseYaml {
local file=$1
while read -r line
do
local k=${line%:*}
local v=${line#*:}
[ "$k" == "chartName" ] && chartName=$v
[ "$k" == "chartHome" ] && chartHome=$v
[ "$k" == "values" ] && valuesFile=$v
[ "$k" == "helmHome" ] && helmHome=$v
[ "$k" == "helmBin" ] && helmBin=$v
done <"$file"
# Trim leading space
chartName="${chartName#"${chartName%%[![:space:]]*}"}"
chartHome="${chartHome#"${chartHome%%[![:space:]]*}"}"
valuesFile="${valuesFile#"${valuesFile%%[![:space:]]*}"}"
helmBin="${helmBin#"${helmBin%%[![:space:]]*}"}"
}
TMP_DIR=$(mktemp -d)
parseYaml $1
# Where all the files generated by 'helm init' live.
if [ -z "$helmHome" ]; then
helmHome=$TMP_DIR/dotHelm
fi
# Where helm charts are unpacked.
if [ -z "$chartHome" ]; then
chartHome=$TMP_DIR/charts
fi
if [ -z "$helmBin" ]; then
helmBin=helm
fi
if [ -z "$valuesFile" ]; then
valuesFile=$chartHome/$chartName/values.yaml
fi
function doHelm {
$helmBin --home $helmHome $@
}
# The init command is extremely chatty
doHelm init --client-only >& /dev/null
if [ ! -d "$chartHome/$chartName" ]; then
doHelm fetch --untar \
--untardir $chartHome \
stable/$chartName
fi
doHelm template \
--values $valuesFile \
$chartHome/$chartName
/bin/rm -rf $TMP_DIR