mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Make builtin the default pluginType
This commit is contained in:
@@ -26,12 +26,14 @@ import (
|
||||
|
||||
// Registry holds all the plugin factories.
|
||||
type Registry struct {
|
||||
factories map[string]Factory
|
||||
factories map[types.PluginType]Factory
|
||||
ldr ifc.Loader
|
||||
}
|
||||
|
||||
const (
|
||||
PluginsDir = "plugins"
|
||||
PluginsDir = "plugins"
|
||||
pluginTypeGo = types.PluginType("go")
|
||||
pluginTypeBuiltIn = types.PluginType("builtin")
|
||||
)
|
||||
|
||||
func DefaultPluginConfig() types.PluginConfig {
|
||||
@@ -48,9 +50,9 @@ func NewConfiguredRegistry(
|
||||
ldr ifc.Loader, pc *types.PluginConfig) Registry {
|
||||
return Registry{
|
||||
ldr: ldr,
|
||||
factories: map[string]Factory{
|
||||
"go": newGoFactory(pc),
|
||||
"builtin": newBuiltinFactory(ldr),
|
||||
factories: map[types.PluginType]Factory{
|
||||
pluginTypeGo: newGoFactory(pc),
|
||||
pluginTypeBuiltIn: newBuiltinFactory(ldr),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -60,11 +62,15 @@ func NewRegistry(ldr ifc.Loader) Registry {
|
||||
return NewConfiguredRegistry(ldr, &types.PluginConfig{})
|
||||
}
|
||||
|
||||
// Load returns a plugin by type and name,
|
||||
func (r *Registry) Load(pluginType, name string) (KVSource, error) {
|
||||
factory, exists := r.factories[pluginType]
|
||||
// Load returns a plugin by type and name.
|
||||
func (r *Registry) Load(
|
||||
pt types.PluginType, name string) (KVSource, error) {
|
||||
if pt.IsUndefined() {
|
||||
pt = pluginTypeBuiltIn
|
||||
}
|
||||
factory, exists := r.factories[pt]
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("%s is not a valid plugin type", pluginType)
|
||||
return nil, fmt.Errorf("%s is not a valid plugin type", pt)
|
||||
}
|
||||
return factory.load(name)
|
||||
}
|
||||
|
||||
@@ -20,6 +20,27 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
const result = `
|
||||
apiVersion: v1
|
||||
data:
|
||||
FRUIT: YXBwbGU=
|
||||
VEGETABLE: Y2Fycm90
|
||||
foo.env: Ck1PVU5UQUlOPWV2ZXJlc3QKT0NFQU49cGFjaWZpYwo=
|
||||
passphrase: ZGF0IHBocmFzZQ==
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: bob-t98kdk9767
|
||||
type: Opaque
|
||||
`
|
||||
|
||||
func writeDataFiles(th *KustTestHarness) {
|
||||
th.writeF("/app/foo.env", `
|
||||
MOUNTAIN=everest
|
||||
OCEAN=pacific
|
||||
`)
|
||||
th.writeF("/app/phrase.dat", "dat phrase")
|
||||
}
|
||||
|
||||
func TestBuiltinPlugins(t *testing.T) {
|
||||
th := NewKustTestHarness(t, "/app")
|
||||
th.writeK("/app", `
|
||||
@@ -37,25 +58,33 @@ secretGenerator:
|
||||
- foo.env
|
||||
- passphrase=phrase.dat
|
||||
`)
|
||||
th.writeF("/app/foo.env", `
|
||||
MOUNTAIN=everest
|
||||
OCEAN=pacific
|
||||
`)
|
||||
th.writeF("/app/phrase.dat", "dat phrase")
|
||||
writeDataFiles(th)
|
||||
m, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
th.assertActualEqualsExpected(m, `
|
||||
apiVersion: v1
|
||||
data:
|
||||
FRUIT: YXBwbGU=
|
||||
VEGETABLE: Y2Fycm90
|
||||
foo.env: Ck1PVU5UQUlOPWV2ZXJlc3QKT0NFQU49cGFjaWZpYwo=
|
||||
passphrase: ZGF0IHBocmFzZQ==
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: bob-t98kdk9767
|
||||
type: Opaque
|
||||
`)
|
||||
th.assertActualEqualsExpected(m, result)
|
||||
}
|
||||
|
||||
func TestBuiltinIsTheDefault(t *testing.T) {
|
||||
th := NewKustTestHarness(t, "/app")
|
||||
th.writeK("/app", `
|
||||
secretGenerator:
|
||||
- name: bob
|
||||
kvSources:
|
||||
- name: literals
|
||||
args:
|
||||
- FRUIT=apple
|
||||
- VEGETABLE=carrot
|
||||
- name: files
|
||||
args:
|
||||
- foo.env
|
||||
- passphrase=phrase.dat
|
||||
`)
|
||||
writeDataFiles(th)
|
||||
m, err := th.makeKustTarget().MakeCustomizedResMap()
|
||||
if err != nil {
|
||||
t.Fatalf("Err: %v", err)
|
||||
}
|
||||
th.assertActualEqualsExpected(m, result)
|
||||
}
|
||||
|
||||
@@ -271,9 +271,15 @@ type GeneratorOptions struct {
|
||||
DisableNameSuffixHash bool `json:"disableNameSuffixHash,omitempty" yaml:"disableNameSuffixHash,omitempty"`
|
||||
}
|
||||
|
||||
type PluginType string
|
||||
|
||||
func (p PluginType) IsUndefined() bool {
|
||||
return p == PluginType("")
|
||||
}
|
||||
|
||||
// KVSource represents a KV plugin backend.
|
||||
type KVSource struct {
|
||||
PluginType string `json:"pluginType,omitempty" yaml:"pluginType,omitempty"`
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
Args []string `json:"args,omitempty" yaml:"args,omitempty"`
|
||||
PluginType PluginType `json:"pluginType,omitempty" yaml:"pluginType,omitempty"`
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
Args []string `json:"args,omitempty" yaml:"args,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user