mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-01 18:30:15 +00:00
Add ConfigMapGenerator and test.
This commit is contained in:
32
plugin/builtin/ConfigMapGenerator.go
Normal file
32
plugin/builtin/ConfigMapGenerator.go
Normal file
@@ -0,0 +1,32 @@
|
||||
// +build plugin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"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.ConfigMapArgs
|
||||
}
|
||||
|
||||
var KustomizePlugin plugin
|
||||
|
||||
func (p *plugin) Config(
|
||||
ldr ifc.Loader, rf *resmap.Factory, k ifc.Kunstructured) (err error) {
|
||||
p.ldr = ldr
|
||||
p.rf = rf
|
||||
p.args.GeneratorArgs, err = resmap.GeneratorArgsFromKunstruct(k)
|
||||
return
|
||||
}
|
||||
|
||||
func (p *plugin) Generate() (resmap.ResMap, error) {
|
||||
argsList := make([]types.ConfigMapArgs, 1)
|
||||
argsList[0] = p.args
|
||||
return p.rf.NewResMapFromConfigMapArgs(p.ldr, &p.options, argsList)
|
||||
}
|
||||
53
plugin/builtin/ConfigMapGenerator_test.go
Normal file
53
plugin/builtin/ConfigMapGenerator_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package builtin
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/internal/plugintest"
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
|
||||
"sigs.k8s.io/kustomize/pkg/kusttest"
|
||||
"sigs.k8s.io/kustomize/pkg/loader"
|
||||
)
|
||||
|
||||
func TestConfigMapGenerator(t *testing.T) {
|
||||
tc := plugintest_test.NewPluginTestEnv(t).Set()
|
||||
defer tc.Reset()
|
||||
|
||||
tc.BuildGoPlugin(
|
||||
"builtin", "", "ConfigMapGenerator")
|
||||
|
||||
th := kusttest_test.NewKustTestHarnessFull(
|
||||
t, "/app", loader.RestrictionRootOnly, plugin.ActivePluginConfig())
|
||||
|
||||
th.WriteF("/app/devops.env", `
|
||||
SERVICE_PORT=32
|
||||
`)
|
||||
th.WriteF("/app/uxteam.env", `
|
||||
COLOR=red
|
||||
`)
|
||||
|
||||
rm := th.LoadAndRunGenerator(`
|
||||
apiVersion: builtin
|
||||
kind: ConfigMapGenerator
|
||||
metadata:
|
||||
name: myMap
|
||||
envFiles:
|
||||
- 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
|
||||
`)
|
||||
}
|
||||
Reference in New Issue
Block a user