| 1 |
#!/bin/bash |
| 2 |
# Copyright 2019 The Kubernetes Authors. |
| 3 |
# SPDX-License-Identifier: Apache-2.0 |
| 4 |
|
| 5 |
# HashiCorp go-getter |
| 6 |
# |
| 7 |
# Reads a file like this |
| 8 |
# |
| 9 |
# apiVersion: someteam.example.com/v1 |
| 10 |
# kind: GoGetter |
| 11 |
# metadata: |
| 12 |
# name: example |
| 13 |
# url: github.com/kustless/kustomize-examples.git |
| 14 |
# # subPath: base # (optional) relative path in the package |
| 15 |
# # command: cat *.yaml # (optional) build command, default `kustomize build $subPath` |
| 16 |
# |
| 17 |
# download kustomize layes and build it to stdout |
| 18 |
# |
| 19 |
# Example execution: |
| 20 |
# ./plugin/someteam.example.com/v1/gogetter/GoGetter configFile.yaml |
| 21 |
# |
| 22 |
# TODO: cache downloads |
| 23 |
|
| 24 |
set -e |
| 25 |
|
| 26 |
# YAML parsing function borrowed from ChartInflator |
| 27 |
function parseYaml { |
| 28 |
local file=$1 |
| 29 |
while read -r line |
| 30 |
do |
| 31 |
local k=${line%%:*} |
| 32 |
local v=${line#*:} |
| 33 |
local t=${v#"${v%%[![:space:]]*}"} # trim leading space |
| 34 |
|
| 35 |
if [ "$k" == "url" ]; then url=$t |
| 36 |
elif [ "$k" == "subPath" ]; then subPath=$t |
| 37 |
elif [ "$k" == "command" ]; then command=$t |
| 38 |
fi |
| 39 |
done <"$file" |
| 40 |
} |
| 41 |
|
| 42 |
TMP_DIR=$(mktemp -d) |
| 43 |
|
| 44 |
parseYaml $1 |
| 45 |
|
| 46 |
if [ -z "$command" ]; then |
| 47 |
command="kustomize build" |
| 48 |
fi |
| 49 |
|
| 50 |
go-getter $url $TMP_DIR/got 2> /dev/null |
| 51 |
|
| 52 |
(cd $TMP_DIR/got/$subPath; $command) |
| 53 |
|
| 54 |
/bin/rm -rf $TMP_DIR |