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:
jregan
2019-04-21 16:12:55 -07:00
committed by Jeffrey Regan
parent c9bf70fd4b
commit 76a3179868
13 changed files with 169 additions and 154 deletions

View File

@@ -27,9 +27,8 @@ import (
"syscall"
"github.com/ghodss/yaml"
"sigs.k8s.io/kustomize/k8sdeps/kv/plugin"
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/pgmconfig"
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap"
)
@@ -59,11 +58,23 @@ type ExecPlugin struct {
ldr ifc.Loader
}
func NewExecPlugin(root string, id resid.ResId) *ExecPlugin {
return &ExecPlugin{
name: filepath.Join(root, pluginPath(id)),
}
}
// isAvailable checks to see if the plugin is available
func (p *ExecPlugin) isAvailable() bool {
f, err := os.Stat(p.name)
if os.IsNotExist(err) {
return false
}
return f.Mode()&0111 != 0000
}
func (p *ExecPlugin) Config(
ldr ifc.Loader, rf *resmap.Factory, k ifc.Kunstructured) error {
dir := filepath.Join(pgmconfig.ConfigRoot(), plugin.PluginRoot)
id := k.GetGvk()
p.name = filepath.Join(dir, id.Group, id.Version, id.Kind)
p.rf = rf
p.ldr = ldr