Add secret generator.

This commit is contained in:
jregan
2019-04-06 18:27:14 -07:00
parent 1623f1e4c0
commit ffc16d51e0
10 changed files with 178 additions and 21 deletions

View File

@@ -18,18 +18,23 @@ package plugins
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/types"
"sigs.k8s.io/kustomize/pkg/resmap"
)
type generatorLoader struct {
pc *types.PluginConfig
pc *types.PluginConfig
ldr ifc.Loader
rf *resmap.Factory
}
func NewGeneratorLoader(pc *types.PluginConfig) generatorLoader {
return generatorLoader{pc: pc}
func NewGeneratorLoader(
pc *types.PluginConfig,
ldr ifc.Loader, rf *resmap.Factory) generatorLoader {
return generatorLoader{pc: pc, ldr: ldr, rf: rf}
}
func (l generatorLoader) Load(
@@ -43,7 +48,7 @@ func (l generatorLoader) Load(
var result []transformers.Generator
for id, res := range rm {
fileName := pluginFileName(l.pc, id)
c, err := loadAndConfigurePlugin(fileName, res)
c, err := loadAndConfigurePlugin(fileName, l.ldr, l.rf, res)
if err != nil {
return nil, err
}

View File

@@ -32,15 +32,19 @@ import (
)
type Configurable interface {
Config(k ifc.Kunstructured) error
Config(ldr ifc.Loader, rf *resmap.Factory, k ifc.Kunstructured) error
}
type transformerLoader struct {
pc *types.PluginConfig
pc *types.PluginConfig
ldr ifc.Loader
rf *resmap.Factory
}
func NewTransformerLoader(pc *types.PluginConfig) transformerLoader {
return transformerLoader{pc: pc}
func NewTransformerLoader(
pc *types.PluginConfig,
ldr ifc.Loader, rf *resmap.Factory) transformerLoader {
return transformerLoader{pc: pc, ldr: ldr, rf: rf}
}
func (l transformerLoader) Load(
@@ -54,7 +58,7 @@ func (l transformerLoader) Load(
var result []transformers.Transformer
for id, res := range rm {
fileName := pluginFileName(l.pc, id)
c, err := loadAndConfigurePlugin(fileName, res)
c, err := loadAndConfigurePlugin(fileName, l.ldr, l.rf, res)
if err != nil {
return nil, err
}
@@ -74,7 +78,8 @@ func pluginFileName(pc *types.PluginConfig, id resid.ResId) string {
}
func loadAndConfigurePlugin(
fileName string, res *resource.Resource) (Configurable, error) {
fileName string, ldr ifc.Loader,
rf *resmap.Factory, res *resource.Resource) (Configurable, error) {
goPlugin, err := plugin.Open(fileName)
if err != nil {
return nil, fmt.Errorf("plugin %s file not opened", fileName)
@@ -88,7 +93,7 @@ func loadAndConfigurePlugin(
if !ok {
return nil, fmt.Errorf("plugin %s not configurable", fileName)
}
err = c.Config(res)
err = c.Config(ldr, rf, res)
if err != nil {
return nil, errors.Wrapf(err, "plugin %s fails configuration", fileName)
}