mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-10 08:20:59 +00:00
Make plugin dir match Go conventions.
This commit is contained in:
77
plugin/builtin/ChartInflatorExec
Executable file
77
plugin/builtin/ChartInflatorExec
Executable file
@@ -0,0 +1,77 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Helm chart inflator
|
||||
|
||||
# Reads a file like this
|
||||
#
|
||||
# apiVersion: kustomize.config.k8s.io/v1
|
||||
# kind: ChartInflatorExec
|
||||
# metadata:
|
||||
# name: notImportantHere
|
||||
# chart: chartName
|
||||
# values: /absolute/path/to/values/file
|
||||
# helmBin: /absolute/path/to/helmBin
|
||||
#
|
||||
# fetches the given chart from stable/$chartName,
|
||||
# and inflates it to stdout, using the given values file.
|
||||
#
|
||||
# Example execution:
|
||||
# ./plugins/kustomize.config.k8s.io/v1/ChartInflatorExec configFile.yaml
|
||||
|
||||
|
||||
|
||||
# Yaml parsing is a ridiculous thing to do in bash,
|
||||
# but let's try:
|
||||
function parseYaml {
|
||||
local file=$1
|
||||
while read -r line
|
||||
do
|
||||
local k=${line%:*}
|
||||
local v=${line#*:}
|
||||
|
||||
[ "$k" == "chart" ] && chartName=$v
|
||||
[ "$k" == "values" ] && valuesFile=$v
|
||||
[ "$k" == "helmBin" ] && helmBin=$v
|
||||
done <"$file"
|
||||
|
||||
# Trim leading space
|
||||
chartName="${chartName#"${chartName%%[![:space:]]*}"}"
|
||||
valuesFile="${valuesFile#"${valuesFile%%[![:space:]]*}"}"
|
||||
helmBin="${helmBin#"${helmBin%%[![:space:]]*}"}"
|
||||
}
|
||||
|
||||
TMP_DIR=$(mktemp -d)
|
||||
|
||||
# Where all the files generated by 'helm init' live.
|
||||
HELM_HOME=$TMP_DIR/dotHelm
|
||||
|
||||
# Where helm charts are unpacked.
|
||||
CHART_HOME=$TMP_DIR/charts
|
||||
|
||||
parseYaml $1
|
||||
|
||||
if [ -z "$helmBin" ]; then
|
||||
helmBin=/usr/local/bin/helm
|
||||
fi
|
||||
|
||||
if [ -z "$valuesFile" ]; then
|
||||
valuesFile=$CHART_HOME/$chartName/values.yaml
|
||||
fi
|
||||
|
||||
function doHelm {
|
||||
$helmBin --home $HELM_HOME $@
|
||||
}
|
||||
|
||||
# The init command is extremely chatty
|
||||
doHelm init --client-only >& /dev/null
|
||||
|
||||
doHelm fetch --untar \
|
||||
--untardir $CHART_HOME \
|
||||
stable/$chartName
|
||||
|
||||
doHelm template \
|
||||
--values $valuesFile \
|
||||
$CHART_HOME/$chartName
|
||||
|
||||
/bin/rm -rf $TMP_DIR
|
||||
62
plugin/builtin/SecretGenerator.go
Normal file
62
plugin/builtin/SecretGenerator.go
Normal file
@@ -0,0 +1,62 @@
|
||||
// +build plugin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/types"
|
||||
)
|
||||
|
||||
type plugin struct {
|
||||
ldr ifc.Loader
|
||||
rf *resmap.Factory
|
||||
options types.GeneratorOptions
|
||||
args types.SecretArgs
|
||||
}
|
||||
|
||||
var KustomizePlugin plugin
|
||||
|
||||
func (p *plugin) Config(
|
||||
ldr ifc.Loader, rf *resmap.Factory, k ifc.Kunstructured) error {
|
||||
p.ldr = ldr
|
||||
p.rf = rf
|
||||
|
||||
var err error
|
||||
// TODO: Should validate this.
|
||||
p.args.Behavior, err = k.GetFieldValue("behavior")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
envFiles, err := k.GetStringSlice("envFiles")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(envFiles) > 2 {
|
||||
// TODO: refactor to allow this
|
||||
return fmt.Errorf("cannot yet accept more than one envFile")
|
||||
}
|
||||
if len(envFiles) > 0 {
|
||||
p.args.EnvSource = envFiles[0]
|
||||
}
|
||||
|
||||
p.args.FileSources, err = k.GetStringSlice("valueFiles")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.args.LiteralSources, err = k.GetStringSlice("literals")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *plugin) Generate() (resmap.ResMap, error) {
|
||||
argsList := make([]types.SecretArgs, 1)
|
||||
argsList[0] = p.args
|
||||
return p.rf.NewResMapFromSecretArgs(p.ldr, &p.options, argsList)
|
||||
}
|
||||
Reference in New Issue
Block a user