mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 10:00:56 +00:00
Remove some duped code.
This commit is contained in:
@@ -13,7 +13,7 @@ import (
|
||||
|
||||
type plugin struct{}
|
||||
|
||||
var Transformer plugin
|
||||
var KustomizePlugin plugin
|
||||
|
||||
func (p *plugin) Config(k ifc.Kunstructured) error {
|
||||
return nil
|
||||
|
||||
59
plugins/someteam.example.com/v1/ServiceGenerator.go
Normal file
59
plugins/someteam.example.com/v1/ServiceGenerator.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// +build plugin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"text/template"
|
||||
|
||||
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
)
|
||||
|
||||
type plugin struct {
|
||||
ServiceName string
|
||||
Port string
|
||||
}
|
||||
|
||||
var KustomizePlugin plugin
|
||||
|
||||
var manifest = `
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: dev
|
||||
name: {{.ServiceName}}
|
||||
spec:
|
||||
ports:
|
||||
- port: {{.Port}}
|
||||
selector:
|
||||
app: dev
|
||||
`
|
||||
|
||||
func (p *plugin) Config(k ifc.Kunstructured) error {
|
||||
var err error
|
||||
p.ServiceName, err = k.GetFieldValue("service")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
p.Port, err = k.GetFieldValue("port")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *plugin) Generate() (resmap.ResMap, error) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
temp := template.Must(template.New("manifest").Parse(manifest))
|
||||
err := temp.Execute(&buf, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rf := resmap.NewFactory(resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl()))
|
||||
return rf.NewResMapFromBytes(buf.Bytes())
|
||||
}
|
||||
@@ -18,11 +18,11 @@ import (
|
||||
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
||||
)
|
||||
|
||||
type plugin struct{
|
||||
type plugin struct {
|
||||
prefix string
|
||||
}
|
||||
|
||||
var Transformer plugin
|
||||
var KustomizePlugin plugin
|
||||
|
||||
func (p *plugin) Config(k ifc.Kunstructured) error {
|
||||
var err error
|
||||
|
||||
@@ -1,24 +1,27 @@
|
||||
// +build plugin
|
||||
|
||||
package main
|
||||
|
||||
var database = map[string]string{
|
||||
"TREE": "oak",
|
||||
"ROCKET": "Saturn V",
|
||||
"FRUIT": "apple",
|
||||
"VEGETABLE": "carrot",
|
||||
"SIMPSON": "homer",
|
||||
"TREE": "oak",
|
||||
"ROCKET": "Saturn V",
|
||||
"FRUIT": "apple",
|
||||
"VEGETABLE": "carrot",
|
||||
"SIMPSON": "homer",
|
||||
}
|
||||
|
||||
type plugin struct{}
|
||||
|
||||
var KVSource plugin
|
||||
|
||||
func (p plugin) Get(
|
||||
root string, args []string) (map[string]string, error) {
|
||||
r := make(map[string]string)
|
||||
for _, k := range args {
|
||||
v, ok := database[k]
|
||||
if ok {
|
||||
r[k] = v
|
||||
}
|
||||
}
|
||||
return r, nil
|
||||
root string, args []string) (map[string]string, error) {
|
||||
r := make(map[string]string)
|
||||
for _, k := range args {
|
||||
v, ok := database[k]
|
||||
if ok {
|
||||
r[k] = v
|
||||
}
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user