mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Make plugin dir match Go conventions.
This commit is contained in:
14
plugin/someteam.example.com/v1/ConfigMapGenerator
Executable file
14
plugin/someteam.example.com/v1/ConfigMapGenerator
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Skip the config file name argument.
|
||||
shift
|
||||
|
||||
echo "
|
||||
kind: ConfigMap
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: example-configmap-test
|
||||
data:
|
||||
username: $1
|
||||
password: $2
|
||||
"
|
||||
37
plugin/someteam.example.com/v1/DatePrefixer.go
Normal file
37
plugin/someteam.example.com/v1/DatePrefixer.go
Normal file
@@ -0,0 +1,37 @@
|
||||
// +build plugin
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
||||
)
|
||||
|
||||
type plugin struct{}
|
||||
|
||||
var KustomizePlugin plugin
|
||||
|
||||
func (p *plugin) Config(
|
||||
ldr ifc.Loader, rf *resmap.Factory, k ifc.Kunstructured) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns a constant, rather than
|
||||
// time.Now().Format("2006-01-02")
|
||||
// to make tests happy.
|
||||
// This is just an example.
|
||||
func getDate() string {
|
||||
return "2018-05-11"
|
||||
}
|
||||
|
||||
func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
tr, err := transformers.NewNamePrefixSuffixTransformer(
|
||||
getDate()+"-", "",
|
||||
config.MakeDefaultConfig().NamePrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tr.Transform(m)
|
||||
}
|
||||
13
plugin/someteam.example.com/v1/PrintWorkDir
Executable file
13
plugin/someteam.example.com/v1/PrintWorkDir
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
dir=`pwd`
|
||||
|
||||
echo "
|
||||
kind: WorkDir
|
||||
apiVersion: v1
|
||||
metadata:
|
||||
name: $dir
|
||||
spec:
|
||||
path: ${KUSTOMIZE_PLUGIN_CONFIG_ROOT}
|
||||
"
|
||||
11
plugin/someteam.example.com/v1/SedTransformer
Executable file
11
plugin/someteam.example.com/v1/SedTransformer
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Skip the config file name argument.
|
||||
shift
|
||||
|
||||
args=""
|
||||
for arg in $@; do
|
||||
args="$args -e $arg"
|
||||
done
|
||||
|
||||
cat - | sed $args
|
||||
60
plugin/someteam.example.com/v1/ServiceGenerator.go
Normal file
60
plugin/someteam.example.com/v1/ServiceGenerator.go
Normal file
@@ -0,0 +1,60 @@
|
||||
// +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(
|
||||
ldr ifc.Loader, rf *resmap.Factory, 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())
|
||||
}
|
||||
46
plugin/someteam.example.com/v1/StringPrefixer.go
Normal file
46
plugin/someteam.example.com/v1/StringPrefixer.go
Normal file
@@ -0,0 +1,46 @@
|
||||
// +build plugin
|
||||
|
||||
// Assuming GOPATH is something like
|
||||
// ~/gopath
|
||||
// and this source file is located at
|
||||
// $GOPATH/src/sigs.k8s.io/kustomize/plugins/StringPrefixer.go,
|
||||
// build it like this:
|
||||
// dir=$GOPATH/src/sigs.k8s.io/kustomize/plugins
|
||||
// go build -buildmode plugin -tags=plugin \
|
||||
// -o $dir/StringPrefixer.so $dir/StringPrefixer.go
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers/config"
|
||||
)
|
||||
|
||||
type plugin struct {
|
||||
prefix string
|
||||
}
|
||||
|
||||
var KustomizePlugin plugin
|
||||
|
||||
func (p *plugin) Config(
|
||||
ldr ifc.Loader, rf *resmap.Factory, k ifc.Kunstructured) error {
|
||||
name := k.GetName()
|
||||
if name == "" {
|
||||
return fmt.Errorf("name cannot be empty")
|
||||
}
|
||||
p.prefix = name + "-"
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *plugin) Transform(m resmap.ResMap) error {
|
||||
tr, err := transformers.NewNamePrefixSuffixTransformer(
|
||||
p.prefix, "",
|
||||
config.MakeDefaultConfig().NamePrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return tr.Transform(m)
|
||||
}
|
||||
27
plugin/someteam.example.com/v1/kvMaker.go
Normal file
27
plugin/someteam.example.com/v1/kvMaker.go
Normal file
@@ -0,0 +1,27 @@
|
||||
// +build plugin
|
||||
|
||||
package main
|
||||
|
||||
var database = map[string]string{
|
||||
"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
|
||||
}
|
||||
Reference in New Issue
Block a user