Start adding helm3 to ChartInflator and its coverage.

This commit is contained in:
jregan
2020-04-21 19:31:53 -07:00
parent c75a47322b
commit 98414e8bf6
4 changed files with 142 additions and 49 deletions

View File

@@ -115,25 +115,69 @@ if [ -z "$releaseNamespace" ]; then
releaseNamespace=default
fi
function doHelm {
$helmBin --home $helmHome $@
function v2RunHelm {
$helmBin --home $helmHome "$@"
}
# The init command is extremely chatty
doHelm init --client-only >& /dev/null
function v3RunHelm {
XDG_CONFIG_DIR=$helmHome
$helmBin "$@"
}
if [ ! -d "$chartHome/$chartName" ]; then
doHelm fetch $chartVersionArg \
$chartRepoArg \
--untar \
--untardir $chartHome \
$chartNameArg
fi
function v2InitHelm {
# The init command is extremely chatty
v2RunHelm init --client-only >& /dev/null
}
doHelm template \
--name $releaseName \
--namespace $releaseNamespace \
--values $valuesFile \
$chartHome/$chartName
function v3InitHelm {
# Do nothing - there's no init command in helm v3
true
}
function v2PullChart {
if [ ! -d "$chartHome/$chartName" ]; then
v2RunHelm fetch $chartVersionArg \
$chartRepoArg \
--untar \
--untardir $chartHome \
$chartNameArg
fi
}
function v3PullChart {
# TODO implement
echo "?? helmV3 pull --repo https://hub.helm.sh/charts/ stable/minecraft --destination /tmp/junk"
}
function v2InflateChart {
v2RunHelm template \
--name $releaseName \
--namespace $releaseNamespace \
--values $valuesFile \
$chartHome/$chartName
}
function v3InflateChart {
# TODO implement
true
}
HELM_VERSION=$($helmBin version -c --short)
case $HELM_VERSION in
'Client: v2'*)
v2InitHelm
v2PullChart
v2InflateChart
;;
v3*)
v3InitHelm
v3PullChart
v3InflateChart
;;
*)
echo "[!] Unsupported 'helm' version '${HELM_VERSION}'" 1>&2 && exit 1
;;
esac
/bin/rm -rf $TMP_DIR

View File

@@ -14,27 +14,7 @@ import (
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
// This test requires having the helm binary on the PATH.
//
// TODO: Download and inflate the chart, and check that
// in for the test.
func TestChartInflator(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepExecPlugin("someteam.example.com", "v1", "ChartInflator")
defer th.Reset()
m := th.LoadAndRunGenerator(`
apiVersion: someteam.example.com/v1
kind: ChartInflator
metadata:
name: notImportantHere
chartName: minecraft`)
chartName := regexp.MustCompile("chart: minecraft-[0-9.]+")
th.AssertActualEqualsExpectedWithTweak(m,
func(x []byte) []byte {
return chartName.ReplaceAll(x, []byte("chart: minecraft-SOMEVERSION"))
}, `
const expectedResources=`
apiVersion: v1
data:
rcon-password: Q0hBTkdFTUUh
@@ -84,5 +64,52 @@ spec:
selector:
app: release-name-minecraft
type: LoadBalancer
`
// This test requires having "helmV2" (presumably helm V2 series) on the PATH.
//
// TODO: Download and inflate the chart, and check that
// in for the test.
func TestHelmV2ChartInflator(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepExecPlugin("someteam.example.com", "v1", "ChartInflator")
defer th.Reset()
m := th.LoadAndRunGenerator(`
apiVersion: someteam.example.com/v1
kind: ChartInflator
metadata:
name: notImportantHere
chartName: minecraft
helmBin: helmV2
`)
chartName := regexp.MustCompile("chart: minecraft-[0-9.]+")
th.AssertActualEqualsExpectedWithTweak(m,
func(x []byte) []byte {
return chartName.ReplaceAll(x, []byte("chart: minecraft-SOMEVERSION"))
}, expectedResources)
}
// This test requires having "helmV3" (presumably helm V3 series) on the PATH.
//
func disabled_TestHelmV3ChartInflator(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepExecPlugin("someteam.example.com", "v1", "ChartInflator")
defer th.Reset()
m := th.LoadAndRunGenerator(`
apiVersion: someteam.example.com/v1
kind: ChartInflator
metadata:
name: notImportantHere
chartName: minecraft
helmBin: helmV3
`)
chartName := regexp.MustCompile("chart: minecraft-[0-9.]+")
th.AssertActualEqualsExpectedWithTweak(m,
func(x []byte) []byte {
return chartName.ReplaceAll(x, []byte("chart: minecraft-SOMEVERSION"))
}, expectedResources)
}