move check for working dir for exec functions

This commit is contained in:
Natasha Sarkar
2021-08-20 10:07:32 -07:00
parent 1e1b9b484a
commit e100be620e
5 changed files with 42 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ package container
import (
"fmt"
"os"
runtimeexec "sigs.k8s.io/kustomize/kyaml/fn/runtime/exec"
"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
@@ -139,19 +140,27 @@ func (c Filter) GetExit() error {
}
func (c *Filter) Filter(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
c.setupExec()
if err := c.setupExec(); err != nil {
return nil, err
}
return c.Exec.Filter(nodes)
}
func (c *Filter) setupExec() {
func (c *Filter) setupExec() error {
// don't init 2x
if c.Exec.Path != "" {
return
return nil
}
wd, err := os.Getwd()
if err != nil {
return err
}
c.Exec.WorkingDir = wd
path, args := c.getCommand()
c.Exec.Path = path
c.Exec.Args = args
return nil
}
// getArgs returns the command + args to run to spawn the container