mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-13 01:50:55 +00:00
Simplify plugin loader code.
* use one place to build plugin file names, * use one loader instance, * test for plugin enabled flag in just one place to avoid errors and reduce if statements, * don't return private objects, * factor goplugin loading to a method, * fix a related test that was commented out.
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||
@@ -20,9 +18,17 @@ func (p *plugin) Config(
|
||||
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(
|
||||
time.Now().Format("2006-01-02")+"-", "",
|
||||
getDate()+"-", "",
|
||||
config.MakeDefaultConfig().NamePrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/transformers"
|
||||
@@ -26,11 +27,11 @@ var KustomizePlugin plugin
|
||||
|
||||
func (p *plugin) Config(
|
||||
ldr ifc.Loader, rf *resmap.Factory, k ifc.Kunstructured) error {
|
||||
var err error
|
||||
p.prefix, err = k.GetFieldValue("prefix")
|
||||
if err != nil {
|
||||
return err
|
||||
name := k.GetName()
|
||||
if name == "" {
|
||||
return fmt.Errorf("name cannot be empty")
|
||||
}
|
||||
p.prefix = name + "-"
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user