mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Start adding helm3 to ChartInflator and its coverage.
This commit is contained in:
31
Makefile
31
Makefile
@@ -261,18 +261,31 @@ $(MYGOBIN)/kubeval:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# linux only.
|
# linux only.
|
||||||
# This is for testing an example plugin that
|
# This is for testing an example plugin that uses helm to inflate a chart
|
||||||
# uses helm to inflate a chart for subsequent kustomization.
|
# for subsequent kustomization.
|
||||||
# Don't want to add a hard dependence in go.mod file
|
# Don't want to add a hard dependence in go.mod file to helm.
|
||||||
# to helm.
|
# Instead, download the binaries.
|
||||||
# Instead, download the binary.
|
$(MYGOBIN)/helmV2:
|
||||||
$(MYGOBIN)/helm:
|
|
||||||
( \
|
( \
|
||||||
set -e; \
|
set -e; \
|
||||||
d=$(shell mktemp -d); cd $$d; \
|
d=$(shell mktemp -d); cd $$d; \
|
||||||
wget https://storage.googleapis.com/kubernetes-helm/helm-v2.13.1-linux-amd64.tar.gz; \
|
tgzFile=helm-v2.13.1-linux-amd64.tar.gz; \
|
||||||
tar -xvzf helm-v2.13.1-linux-amd64.tar.gz; \
|
wget https://storage.googleapis.com/kubernetes-helm/$$tgzFile; \
|
||||||
mv linux-amd64/helm $(MYGOBIN); \
|
tar -xvzf $$tgzFile; \
|
||||||
|
mv linux-amd64/helm $(MYGOBIN)/helmV2; \
|
||||||
|
rm -rf $$d \
|
||||||
|
)
|
||||||
|
|
||||||
|
# Helm V3 differs from helm V2; downloading it to provide coverage for the
|
||||||
|
# chart inflator plugin under helm v3.
|
||||||
|
$(MYGOBIN)/helmV3:
|
||||||
|
( \
|
||||||
|
set -e; \
|
||||||
|
d=$(shell mktemp -d); cd $$d; \
|
||||||
|
tgzFile=helm-v3.2.0-rc.1-linux-amd64.tar.gz; \
|
||||||
|
wget https://get.helm.sh/$$tgzFile; \
|
||||||
|
tar -xvzf $$tgzFile; \
|
||||||
|
mv linux-amd64/helm $(MYGOBIN)/helmV3; \
|
||||||
rm -rf $$d \
|
rm -rf $$d \
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,14 @@ set -o pipefail
|
|||||||
|
|
||||||
rcAccumulator=0
|
rcAccumulator=0
|
||||||
|
|
||||||
|
# hack. We used to run test on travis, and disable certain tests
|
||||||
|
# when running on travis. Now we run on Prow, so look for that.
|
||||||
|
# https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md
|
||||||
|
# TODO: Make the code ignorant of the CI environment "brand name".
|
||||||
|
# brand name of the CI environment (replace "travis" and "prow" with "CI_env"
|
||||||
|
# or something).
|
||||||
|
TRAVIS=$PROW_JOB_ID
|
||||||
|
|
||||||
function onLinuxAndNotOnTravis {
|
function onLinuxAndNotOnTravis {
|
||||||
[[ ("linux" == "$(go env GOOS)") && (-z ${TRAVIS+x}) ]] && return
|
[[ ("linux" == "$(go env GOOS)") && (-z ${TRAVIS+x}) ]] && return
|
||||||
false
|
false
|
||||||
@@ -51,7 +59,8 @@ function scanDir {
|
|||||||
|
|
||||||
if onLinuxAndNotOnTravis; then
|
if onLinuxAndNotOnTravis; then
|
||||||
# Some of these tests have special deps.
|
# Some of these tests have special deps.
|
||||||
make $(go env GOPATH)/bin/helm
|
make $(go env GOPATH)/bin/helmV2
|
||||||
|
make $(go env GOPATH)/bin/helmV3
|
||||||
make $(go env GOPATH)/bin/kubeval
|
make $(go env GOPATH)/bin/kubeval
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
@@ -115,25 +115,69 @@ if [ -z "$releaseNamespace" ]; then
|
|||||||
releaseNamespace=default
|
releaseNamespace=default
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function doHelm {
|
function v2RunHelm {
|
||||||
$helmBin --home $helmHome $@
|
$helmBin --home $helmHome "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# The init command is extremely chatty
|
function v3RunHelm {
|
||||||
doHelm init --client-only >& /dev/null
|
XDG_CONFIG_DIR=$helmHome
|
||||||
|
$helmBin "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
function v2InitHelm {
|
||||||
|
# The init command is extremely chatty
|
||||||
|
v2RunHelm init --client-only >& /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
function v3InitHelm {
|
||||||
|
# Do nothing - there's no init command in helm v3
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
function v2PullChart {
|
||||||
if [ ! -d "$chartHome/$chartName" ]; then
|
if [ ! -d "$chartHome/$chartName" ]; then
|
||||||
doHelm fetch $chartVersionArg \
|
v2RunHelm fetch $chartVersionArg \
|
||||||
$chartRepoArg \
|
$chartRepoArg \
|
||||||
--untar \
|
--untar \
|
||||||
--untardir $chartHome \
|
--untardir $chartHome \
|
||||||
$chartNameArg
|
$chartNameArg
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
doHelm template \
|
function v3PullChart {
|
||||||
|
# TODO implement
|
||||||
|
echo "?? helmV3 pull --repo https://hub.helm.sh/charts/ stable/minecraft --destination /tmp/junk"
|
||||||
|
}
|
||||||
|
|
||||||
|
function v2InflateChart {
|
||||||
|
v2RunHelm template \
|
||||||
--name $releaseName \
|
--name $releaseName \
|
||||||
--namespace $releaseNamespace \
|
--namespace $releaseNamespace \
|
||||||
--values $valuesFile \
|
--values $valuesFile \
|
||||||
$chartHome/$chartName
|
$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
|
/bin/rm -rf $TMP_DIR
|
||||||
|
|||||||
@@ -14,27 +14,7 @@ import (
|
|||||||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This test requires having the helm binary on the PATH.
|
const expectedResources=`
|
||||||
//
|
|
||||||
// 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"))
|
|
||||||
}, `
|
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
data:
|
data:
|
||||||
rcon-password: Q0hBTkdFTUUh
|
rcon-password: Q0hBTkdFTUUh
|
||||||
@@ -84,5 +64,52 @@ spec:
|
|||||||
selector:
|
selector:
|
||||||
app: release-name-minecraft
|
app: release-name-minecraft
|
||||||
type: LoadBalancer
|
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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user