mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Merge pull request #1019 from monopole/addIfToInflator
Mods to chart inflator plugin
This commit is contained in:
@@ -42,7 +42,7 @@ func TestChartInflatorExecPlugin(t *testing.T) {
|
|||||||
defer tc.Reset()
|
defer tc.Reset()
|
||||||
|
|
||||||
tc.BuildExecPlugin(
|
tc.BuildExecPlugin(
|
||||||
"builtin", "", "ChartInflatorExec")
|
"someteam.example.com", "v1", "ChartInflatorExec")
|
||||||
|
|
||||||
th := NewKustTestHarnessWithPluginConfig(
|
th := NewKustTestHarnessWithPluginConfig(
|
||||||
t, "/app", plugin.ActivePluginConfig())
|
t, "/app", plugin.ActivePluginConfig())
|
||||||
@@ -53,11 +53,11 @@ namePrefix: LOOOOOOOONG-
|
|||||||
`)
|
`)
|
||||||
|
|
||||||
th.writeF("/app/chartInflatorExec.yaml", `
|
th.writeF("/app/chartInflatorExec.yaml", `
|
||||||
apiVersion: builtin
|
apiVersion: someteam.example.com/v1
|
||||||
kind: ChartInflatorExec
|
kind: ChartInflatorExec
|
||||||
metadata:
|
metadata:
|
||||||
name: notImportantHere
|
name: notImportantHere
|
||||||
chart: minecraft
|
chartName: minecraft
|
||||||
`)
|
`)
|
||||||
|
|
||||||
m, err := th.makeKustTarget().MakeCustomizedResMap()
|
m, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||||
|
|||||||
@@ -9,18 +9,22 @@ set -e
|
|||||||
# kind: ChartInflatorExec
|
# kind: ChartInflatorExec
|
||||||
# metadata:
|
# metadata:
|
||||||
# name: notImportantHere
|
# name: notImportantHere
|
||||||
# chart: chartName
|
# chartName: nameOfStableChart
|
||||||
# values: /absolute/path/to/values/file
|
# values: /abs/path/to/local/values/file
|
||||||
# helmBin: /absolute/path/to/helmBin
|
# chartHome: /abs/path/local/chart/storage
|
||||||
|
# helmHome: /abs/path/to/helm/config
|
||||||
|
# helmBin: /abs/path/to/helmBin
|
||||||
#
|
#
|
||||||
# fetches the given chart from stable/$chartName,
|
# fetches the given chart from stable/$chartName,
|
||||||
# and inflates it to stdout, using the given values file.
|
# and inflates it to stdout, using the given values file.
|
||||||
#
|
#
|
||||||
|
# chartDir default: $TMP_DIR/charts
|
||||||
|
# chartDir default:
|
||||||
|
|
||||||
# Example execution:
|
# Example execution:
|
||||||
# ./plugins/kustomize.config.k8s.io/v1/ChartInflatorExec configFile.yaml
|
# ./plugins/kustomize.config.k8s.io/v1/ChartInflatorExec configFile.yaml
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Yaml parsing is a ridiculous thing to do in bash,
|
# Yaml parsing is a ridiculous thing to do in bash,
|
||||||
# but let's try:
|
# but let's try:
|
||||||
function parseYaml {
|
function parseYaml {
|
||||||
@@ -30,48 +34,57 @@ function parseYaml {
|
|||||||
local k=${line%:*}
|
local k=${line%:*}
|
||||||
local v=${line#*:}
|
local v=${line#*:}
|
||||||
|
|
||||||
[ "$k" == "chart" ] && chartName=$v
|
[ "$k" == "chartName" ] && chartName=$v
|
||||||
|
[ "$k" == "chartHome" ] && chartHome=$v
|
||||||
[ "$k" == "values" ] && valuesFile=$v
|
[ "$k" == "values" ] && valuesFile=$v
|
||||||
|
[ "$k" == "helmHome" ] && helmHome=$v
|
||||||
[ "$k" == "helmBin" ] && helmBin=$v
|
[ "$k" == "helmBin" ] && helmBin=$v
|
||||||
done <"$file"
|
done <"$file"
|
||||||
|
|
||||||
# Trim leading space
|
# Trim leading space
|
||||||
chartName="${chartName#"${chartName%%[![:space:]]*}"}"
|
chartName="${chartName#"${chartName%%[![:space:]]*}"}"
|
||||||
|
chartHome="${chartHome#"${chartHome%%[![:space:]]*}"}"
|
||||||
valuesFile="${valuesFile#"${valuesFile%%[![:space:]]*}"}"
|
valuesFile="${valuesFile#"${valuesFile%%[![:space:]]*}"}"
|
||||||
helmBin="${helmBin#"${helmBin%%[![:space:]]*}"}"
|
helmBin="${helmBin#"${helmBin%%[![:space:]]*}"}"
|
||||||
}
|
}
|
||||||
|
|
||||||
TMP_DIR=$(mktemp -d)
|
TMP_DIR=$(mktemp -d)
|
||||||
|
|
||||||
# Where all the files generated by 'helm init' live.
|
|
||||||
HELM_HOME=$TMP_DIR/dotHelm
|
|
||||||
|
|
||||||
# Where helm charts are unpacked.
|
|
||||||
CHART_HOME=$TMP_DIR/charts
|
|
||||||
|
|
||||||
parseYaml $1
|
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
|
if [ -z "$helmBin" ]; then
|
||||||
helmBin=/usr/local/bin/helm
|
helmBin=helm
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$valuesFile" ]; then
|
if [ -z "$valuesFile" ]; then
|
||||||
valuesFile=$CHART_HOME/$chartName/values.yaml
|
valuesFile=$chartHome/$chartName/values.yaml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function doHelm {
|
function doHelm {
|
||||||
$helmBin --home $HELM_HOME $@
|
$helmBin --home $helmHome $@
|
||||||
}
|
}
|
||||||
|
|
||||||
# The init command is extremely chatty
|
# The init command is extremely chatty
|
||||||
doHelm init --client-only >& /dev/null
|
doHelm init --client-only >& /dev/null
|
||||||
|
|
||||||
doHelm fetch --untar \
|
if [ ! -d "$chartHome/$chartName" ]; then
|
||||||
--untardir $CHART_HOME \
|
doHelm fetch --untar \
|
||||||
|
--untardir $chartHome \
|
||||||
stable/$chartName
|
stable/$chartName
|
||||||
|
fi
|
||||||
|
|
||||||
doHelm template \
|
doHelm template \
|
||||||
--values $valuesFile \
|
--values $valuesFile \
|
||||||
$CHART_HOME/$chartName
|
$chartHome/$chartName
|
||||||
|
|
||||||
/bin/rm -rf $TMP_DIR
|
/bin/rm -rf $TMP_DIR
|
||||||
Reference in New Issue
Block a user