Fix krm exec function working dir

This commit is contained in:
Ahmed AbouZaid
2022-10-09 15:22:42 +02:00
parent 1b1e6ccab0
commit d29febecb7
3 changed files with 29 additions and 3 deletions

View File

@@ -47,8 +47,18 @@ func (l *Loader) Config() *types.PluginConfig {
return l.pc
}
// SetWorkDir sets the working directory for this loader's plugins
func (l *Loader) SetWorkDir(wd string) {
// DeepCopyPluginConfig makes a full copy the actual values of PluginConfig.
func (l *Loader) DeepCopyPluginConfig() {
l.pc = &types.PluginConfig{
PluginRestrictions: l.pc.PluginRestrictions,
BpLoadingOptions: l.pc.BpLoadingOptions,
FnpLoadingOptions: l.pc.FnpLoadingOptions,
HelmConfig: l.pc.HelmConfig,
}
}
// SetPluginConfigWorkingDir sets the working directory for the loader's plugins.
func (l *Loader) SetPluginConfigWorkingDir(wd string) {
l.pc.FnpLoadingOptions.WorkingDir = wd
}

View File

@@ -78,3 +78,17 @@ func TestLoader(t *testing.T) {
}
}
}
func TestLoaderSetPluginConfigWorkingDir(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")
}
}

View File

@@ -45,7 +45,9 @@ func NewKustTarget(
rFactory *resmap.Factory,
pLdr *loader.Loader) *KustTarget {
pLdrCopy := *pLdr
pLdrCopy.SetWorkDir(ldr.Root())
pLdrCopy.DeepCopyPluginConfig()
pLdrCopy.SetPluginConfigWorkingDir(ldr.Root())
return &KustTarget{
ldr: ldr,
validator: validator,