mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 10:30:59 +00:00
proposal v2
This commit is contained in:
@@ -42,24 +42,22 @@ func NewLoader(
|
|||||||
return &Loader{pc: pc, rf: rf, fs: fs}
|
return &Loader{pc: pc, rf: rf, fs: fs}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config provides the global (not plugin specific) PluginConfig data.
|
// LoaderWithWorkingDir returns loader after setting its working directory.
|
||||||
func (l *Loader) Config() *types.PluginConfig {
|
// NOTE: This is not really a new loader since some of the Loader struct fields are pointers.
|
||||||
return l.pc
|
func (l *Loader) LoaderWithWorkingDir(wd string) *Loader {
|
||||||
}
|
lpc := &types.PluginConfig{
|
||||||
|
|
||||||
// DeepCopyPluginConfig makes a full copy the actual values of PluginConfig.
|
|
||||||
func (l *Loader) DeepCopyPluginConfig() {
|
|
||||||
l.pc = &types.PluginConfig{
|
|
||||||
PluginRestrictions: l.pc.PluginRestrictions,
|
PluginRestrictions: l.pc.PluginRestrictions,
|
||||||
BpLoadingOptions: l.pc.BpLoadingOptions,
|
BpLoadingOptions: l.pc.BpLoadingOptions,
|
||||||
FnpLoadingOptions: l.pc.FnpLoadingOptions,
|
FnpLoadingOptions: l.pc.FnpLoadingOptions,
|
||||||
HelmConfig: l.pc.HelmConfig,
|
HelmConfig: l.pc.HelmConfig,
|
||||||
}
|
}
|
||||||
|
lpc.FnpLoadingOptions.WorkingDir = wd
|
||||||
|
return &Loader{pc: lpc, rf: l.rf, fs: l.fs}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPluginConfigWorkingDir sets the working directory for the loader's plugins.
|
// Config provides the global (not plugin specific) PluginConfig data.
|
||||||
func (l *Loader) SetPluginConfigWorkingDir(wd string) {
|
func (l *Loader) Config() *types.PluginConfig {
|
||||||
l.pc.FnpLoadingOptions.WorkingDir = wd
|
return l.pc
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *Loader) LoadGenerators(
|
func (l *Loader) LoadGenerators(
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ package loader_test
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
. "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
. "sigs.k8s.io/kustomize/api/internal/plugins/loader"
|
||||||
"sigs.k8s.io/kustomize/api/loader"
|
"sigs.k8s.io/kustomize/api/loader"
|
||||||
"sigs.k8s.io/kustomize/api/provider"
|
"sigs.k8s.io/kustomize/api/provider"
|
||||||
@@ -79,16 +80,15 @@ func TestLoader(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoaderSetPluginConfigWorkingDir(t *testing.T) {
|
func TestLoaderWithWorkingDir(t *testing.T) {
|
||||||
p := provider.NewDefaultDepProvider()
|
p := provider.NewDefaultDepProvider()
|
||||||
rmF := resmap.NewFactory(p.GetResourceFactory())
|
rmF := resmap.NewFactory(p.GetResourceFactory())
|
||||||
fsys := filesys.MakeFsInMemory()
|
fsys := filesys.MakeFsInMemory()
|
||||||
c := types.EnabledPluginConfig(types.BploLoadFromFileSys)
|
c := types.EnabledPluginConfig(types.BploLoadFromFileSys)
|
||||||
pLdr := NewLoader(c, rmF, fsys)
|
pLdr := NewLoader(c, rmF, fsys)
|
||||||
pLdrCopy := *pLdr
|
npLdr := pLdr.LoaderWithWorkingDir("/tmp/dummy")
|
||||||
pLdrCopy.DeepCopyPluginConfig()
|
require.Equal(t,
|
||||||
pLdrCopy.SetPluginConfigWorkingDir("/tmp/dummy")
|
"/tmp/dummy",
|
||||||
if pLdrCopy.Config().FnpLoadingOptions.WorkingDir != "/tmp/dummy" {
|
npLdr.Config().FnpLoadingOptions.WorkingDir,
|
||||||
t.Fatal("plugin working dir is not set correctly")
|
"plugin working dir is not set correctly")
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,15 +44,11 @@ func NewKustTarget(
|
|||||||
validator ifc.Validator,
|
validator ifc.Validator,
|
||||||
rFactory *resmap.Factory,
|
rFactory *resmap.Factory,
|
||||||
pLdr *loader.Loader) *KustTarget {
|
pLdr *loader.Loader) *KustTarget {
|
||||||
pLdrCopy := *pLdr
|
|
||||||
pLdrCopy.DeepCopyPluginConfig()
|
|
||||||
pLdrCopy.SetPluginConfigWorkingDir(ldr.Root())
|
|
||||||
|
|
||||||
return &KustTarget{
|
return &KustTarget{
|
||||||
ldr: ldr,
|
ldr: ldr,
|
||||||
validator: validator,
|
validator: validator,
|
||||||
rFactory: rFactory,
|
rFactory: rFactory,
|
||||||
pLdr: &pLdrCopy,
|
pLdr: pLdr.LoaderWithWorkingDir(ldr.Root()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user