mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
One plugin per dir.
This commit is contained in:
38
plugin/builtin/configmapgenerator/ConfigMapGenerator.go
Normal file
38
plugin/builtin/configmapgenerator/ConfigMapGenerator.go
Normal 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)
|
||||
}
|
||||
54
plugin/builtin/configmapgenerator/ConfigMapGenerator_test.go
Normal file
54
plugin/builtin/configmapgenerator/ConfigMapGenerator_test.go
Normal 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
|
||||
`)
|
||||
}
|
||||
Reference in New Issue
Block a user