Support setting command in go-getter plugin

This allows one to use non-kustomization remote source
This commit is contained in:
Yujun Zhang
2019-09-02 10:50:36 +08:00
parent ed91bce275
commit ed920afb2e
4 changed files with 221 additions and 25 deletions

View File

@@ -11,7 +11,8 @@
# metadata:
# name: example
# url: github.com/kustless/kustomize-examples.git
# # overlay: base # (optional) relative path in the package
# # subPath: base # (optional) relative path in the package
# # command: cat *.yaml # (optional) build command, default `kustomize build $subPath`
#
# download kustomize layes and build it to stdout
#
@@ -20,7 +21,7 @@
#
# TODO: cache downloads
set -e
set -ex
# YAML parsing function borrowed from ChartInflator
function parseYaml {
@@ -32,7 +33,8 @@ function parseYaml {
local t=${v#"${v%%[![:space:]]*}"} # trim leading space
if [ "$k" == "url" ]; then url=$t
elif [ "$k" == "overlay" ]; then overlay=$t
elif [ "$k" == "subPath" ]; then subPath=$t
elif [ "$k" == "command" ]; then command=$t
fi
done <"$file"
}
@@ -40,7 +42,13 @@ function parseYaml {
TMP_DIR=$(mktemp -d)
parseYaml $1
if [ -z "$command" ]; then
command="kustomize build"
fi
go-getter $url $TMP_DIR/got 2> /dev/null
kustomize build $TMP_DIR/got/$overlay
(cd $TMP_DIR/got/$subPath; $command)
/bin/rm -rf $TMP_DIR

View File

@@ -30,7 +30,7 @@ apiVersion: someteam.example.com/v1
kind: GoGetter
metadata:
name: example
url: github.com/kustless/kustomize-examples.git
url: github.com/kustless/kustomize-examples.git?ref=adef0a8
`)
th.AssertActualEqualsExpected(m, `
@@ -40,6 +40,66 @@ data:
enableRisky: "false"
kind: ConfigMap
metadata:
name: the-map
name: remote-cm
`)
}
func TestGoGetterCommand(t *testing.T) {
tc := plugins_test.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildExecPlugin(
"someteam.example.com", "v1", "GoGetter")
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
m := th.LoadAndRunGenerator(`
apiVersion: someteam.example.com/v1
kind: GoGetter
metadata:
name: example
url: github.com/kustless/kustomize-examples.git?ref=adef0a8
command: cat resources.yaml
`)
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
altGreeting: Good Morning!
enableRisky: "false"
kind: ConfigMap
metadata:
name: cm
`)
}
func TestGoGetterSubPath(t *testing.T) {
tc := plugins_test.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildExecPlugin(
"someteam.example.com", "v1", "GoGetter")
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
m := th.LoadAndRunGenerator(`
apiVersion: someteam.example.com/v1
kind: GoGetter
metadata:
name: example
url: github.com/kustless/kustomize-examples.git?ref=9ca07d2
subPath: dev
command: kustomize build --enable_alpha_plugins
`)
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
altGreeting: Good Morning!
enableRisky: "false"
kind: ConfigMap
metadata:
name: dev-remote-cm
`)
}