mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Support setting command in go-getter plugin
This allows one to use non-kustomization remote source
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user