mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-01 18:30:15 +00:00
Ease doing custom configuration of builtin plugins.
This commit is contained in:
@@ -16,6 +16,15 @@ import (
|
||||
"sigs.k8s.io/kustomize/v3/pkg/plugins"
|
||||
)
|
||||
|
||||
//go:generate stringer -type=pluginType
|
||||
type pluginType int
|
||||
|
||||
const (
|
||||
unknown pluginType = iota
|
||||
Transformer
|
||||
Generator
|
||||
)
|
||||
|
||||
func main() {
|
||||
root := inputFileRoot()
|
||||
file, err := os.Open(root + ".go")
|
||||
@@ -34,24 +43,41 @@ func main() {
|
||||
fmt.Sprintf(
|
||||
"// Code generated by pluginator on %s; DO NOT EDIT.",
|
||||
root))
|
||||
w.write("package builtin")
|
||||
w.write("package " + plugins.BuiltinPluginPackage)
|
||||
|
||||
pType := unknown
|
||||
|
||||
for scanner.Scan() {
|
||||
l := scanner.Text()
|
||||
if strings.HasPrefix(l, "//go:generate") {
|
||||
continue
|
||||
}
|
||||
if l == "var "+plugins.PluginSymbol+" plugin" {
|
||||
w.write("func New" + root + "Plugin() *" + root + "Plugin {")
|
||||
w.write(" return &" + root + "Plugin{}")
|
||||
w.write("}")
|
||||
if strings.HasPrefix(l, "//noinspection") {
|
||||
continue
|
||||
}
|
||||
if l == "var "+plugins.PluginSymbol+" plugin" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(l, " Transform(") {
|
||||
if pType != unknown {
|
||||
log.Fatal("unexpected Transform(")
|
||||
}
|
||||
pType = Transformer
|
||||
} else if strings.Contains(l, " Generate(") {
|
||||
if pType != unknown {
|
||||
log.Fatal("unexpected Generate(")
|
||||
}
|
||||
pType = Generator
|
||||
}
|
||||
w.write(l)
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
w.write("")
|
||||
w.write("func New" + root + "Plugin() resmap." + pType.String() + "Plugin {")
|
||||
w.write(" return &" + root + "Plugin{}")
|
||||
w.write("}")
|
||||
}
|
||||
|
||||
func inputFileRoot() string {
|
||||
@@ -93,7 +119,7 @@ func makeOutputFileName(root string) string {
|
||||
pgmconfig.DomainName,
|
||||
pgmconfig.ProgramName,
|
||||
pgmconfig.PluginRoot,
|
||||
"builtin",
|
||||
plugins.BuiltinPluginPackage,
|
||||
root+".go")
|
||||
}
|
||||
|
||||
|
||||
25
cmd/pluginator/plugintype_string.go
Normal file
25
cmd/pluginator/plugintype_string.go
Normal file
@@ -0,0 +1,25 @@
|
||||
// Code generated by "stringer -type=pluginType"; DO NOT EDIT.
|
||||
|
||||
package main
|
||||
|
||||
import "strconv"
|
||||
|
||||
func _() {
|
||||
// An "invalid array index" compiler error signifies that the constant values have changed.
|
||||
// Re-run the stringer command to generate them again.
|
||||
var x [1]struct{}
|
||||
_ = x[unknown-0]
|
||||
_ = x[Transformer-1]
|
||||
_ = x[Generator-2]
|
||||
}
|
||||
|
||||
const _pluginType_name = "unknownTransformerGenerator"
|
||||
|
||||
var _pluginType_index = [...]uint8{0, 7, 18, 27}
|
||||
|
||||
func (i pluginType) String() string {
|
||||
if i < 0 || i >= pluginType(len(_pluginType_index)-1) {
|
||||
return "pluginType(" + strconv.FormatInt(int64(i), 10) + ")"
|
||||
}
|
||||
return _pluginType_name[_pluginType_index[i]:_pluginType_index[i+1]]
|
||||
}
|
||||
Reference in New Issue
Block a user