One plugin per dir.

This commit is contained in:
jregan
2019-05-19 12:00:07 -07:00
parent 31534fe47d
commit 5653ae69e4
42 changed files with 612 additions and 626 deletions

View File

@@ -0,0 +1,38 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
//go:generate go run sigs.k8s.io/kustomize/plugin/pluginator
package main
import (
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/types"
"sigs.k8s.io/yaml"
)
type plugin struct {
ldr ifc.Loader
rf *resmap.Factory
types.GeneratorOptions
types.ConfigMapArgs
}
var KustomizePlugin plugin
func (p *plugin) Config(
ldr ifc.Loader, rf *resmap.Factory, config []byte) (err error) {
p.GeneratorOptions = types.GeneratorOptions{}
p.ConfigMapArgs = types.ConfigMapArgs{}
err = yaml.Unmarshal(config, p)
p.ldr = ldr
p.rf = rf
return
}
func (p *plugin) Generate() (resmap.ResMap, error) {
argsList := make([]types.ConfigMapArgs, 1)
argsList[0] = p.ConfigMapArgs
return p.rf.NewResMapFromConfigMapArgs(
p.ldr, &p.GeneratorOptions, argsList)
}

View File

@@ -0,0 +1,54 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package main_test
import (
"testing"
"sigs.k8s.io/kustomize/pkg/kusttest"
"sigs.k8s.io/kustomize/plugin"
)
func TestConfigMapGenerator(t *testing.T) {
tc := plugin.NewEnvForTest(t).Set()
defer tc.Reset()
tc.BuildGoPlugin(
"builtin", "", "ConfigMapGenerator")
th := kusttest_test.NewKustTestPluginHarness(t, "/app")
th.WriteF("/app/devops.env", `
SERVICE_PORT=32
`)
th.WriteF("/app/uxteam.env", `
COLOR=red
`)
rm := th.LoadAndRunGenerator(`
apiVersion: builtin
kind: ConfigMapGenerator
metadata:
name: myMapGen
name: myMap
envs:
- devops.env
- uxteam.env
literals:
- FRUIT=apple
- VEGETABLE=carrot
`)
th.AssertActualEqualsExpected(rm, `
apiVersion: v1
data:
COLOR: red
FRUIT: apple
SERVICE_PORT: "32"
VEGETABLE: carrot
kind: ConfigMap
metadata:
name: myMap
`)
}