-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/bin/bash | ||
# Copyright 2019 The Kubernetes Authors. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# HashiCorp go-getter | ||
# | ||
# Reads a file like this | ||
# | ||
# apiVersion: someteam.example.com/v1 | ||
# kind: GoGetter | ||
# metadata: | ||
# name: example | ||
# url: github.com/kustless/kustomize-examples.git | ||
# # overlay: base # (optional) relative path in the package | ||
# | ||
# download kustomize layes and build it to stdout | ||
# | ||
# Example execution: | ||
# ./plugin/someteam.example.com/v1/gogetter/GoGetter configFile.yaml | ||
# | ||
# TODO: cache downloads | ||
|
||
set -e | ||
|
||
# YAML parsing function borrowed from ChartInflator | ||
function parseYaml { | ||
local file=$1 | ||
while read -r line | ||
do | ||
local k=${line%:*} | ||
local v=${line#*:} | ||
local t=${v#"${v%%[![:space:]]*}"} # trim leading space | ||
|
||
if [ "$k" == "url" ]; then url=$t | ||
elif [ "$k" == "overlay" ]; then overlay=$t | ||
fi | ||
done <"$file" | ||
} | ||
|
||
TMP_DIR=$(mktemp -d) | ||
|
||
parseYaml $1 | ||
go-getter $url $TMP_DIR/got 2> /dev/null | ||
kustomize build $TMP_DIR/got/$overlay | ||
|
||
/bin/rm -rf $TMP_DIR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// +build notravis | ||
|
||
// Copyright 2019 The Kubernetes Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// Disabled on travis, because don't want to install go-getter on travis. | ||
|
||
package main_test | ||
|
||
import ( | ||
"testing" | ||
|
||
kusttest_test "sigs.k8s.io/kustomize/v3/pkg/kusttest" | ||
plugins_test "sigs.k8s.io/kustomize/v3/pkg/plugins/test" | ||
) | ||
|
||
// This test requires having the go-getter binary on the PATH. | ||
// | ||
func TestGoGetter(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 | ||
`) | ||
|
||
th.AssertActualEqualsExpected(m, ` | ||
apiVersion: v1 | ||
data: | ||
altGreeting: Good Morning! | ||
enableRisky: "false" | ||
kind: ConfigMap | ||
metadata: | ||
name: the-map | ||
`) | ||
} |