proposal v2

This commit is contained in:
Ahmed AbouZaid
2022-10-15 16:45:50 +02:00
parent d29febecb7
commit ea21b37d67
3 changed files with 17 additions and 23 deletions

View File

@@ -42,24 +42,22 @@ func NewLoader(
return &Loader{pc: pc, rf: rf, fs: fs}
}
// Config provides the global (not plugin specific) PluginConfig data.
func (l *Loader) Config() *types.PluginConfig {
return l.pc
}
// DeepCopyPluginConfig makes a full copy the actual values of PluginConfig.
func (l *Loader) DeepCopyPluginConfig() {
l.pc = &types.PluginConfig{
// LoaderWithWorkingDir returns loader after setting its working directory.
// NOTE: This is not really a new loader since some of the Loader struct fields are pointers.
func (l *Loader) LoaderWithWorkingDir(wd string) *Loader {
lpc := &types.PluginConfig{
PluginRestrictions: l.pc.PluginRestrictions,
BpLoadingOptions: l.pc.BpLoadingOptions,
FnpLoadingOptions: l.pc.FnpLoadingOptions,
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.
func (l *Loader) SetPluginConfigWorkingDir(wd string) {
l.pc.FnpLoadingOptions.WorkingDir = wd
// Config provides the global (not plugin specific) PluginConfig data.
func (l *Loader) Config() *types.PluginConfig {
return l.pc
}
func (l *Loader) LoadGenerators(

View File

@@ -6,6 +6,7 @@ package loader_test
import (
"testing"
"github.com/stretchr/testify/require"
. "sigs.k8s.io/kustomize/api/internal/plugins/loader"
"sigs.k8s.io/kustomize/api/loader"
"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()
rmF := resmap.NewFactory(p.GetResourceFactory())
fsys := filesys.MakeFsInMemory()
c := types.EnabledPluginConfig(types.BploLoadFromFileSys)
pLdr := NewLoader(c, rmF, fsys)
pLdrCopy := *pLdr
pLdrCopy.DeepCopyPluginConfig()
pLdrCopy.SetPluginConfigWorkingDir("/tmp/dummy")
if pLdrCopy.Config().FnpLoadingOptions.WorkingDir != "/tmp/dummy" {
t.Fatal("plugin working dir is not set correctly")
}
npLdr := pLdr.LoaderWithWorkingDir("/tmp/dummy")
require.Equal(t,
"/tmp/dummy",
npLdr.Config().FnpLoadingOptions.WorkingDir,
"plugin working dir is not set correctly")
}