mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
exec function working dir is the kustomization that referenced it (#4125)
* exec function working dir is the kustomization that referenced it * suggested changes * more code review * use a field instead of an annotation * more code review
This commit is contained in:
@@ -7,7 +7,9 @@ import (
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
@@ -19,6 +21,10 @@ type Filter struct {
|
||||
// Args are the arguments to the executable
|
||||
Args []string `yaml:"args,omitempty"`
|
||||
|
||||
// WorkingDir is the working directory that the executable
|
||||
// should run in
|
||||
WorkingDir string
|
||||
|
||||
runtimeutil.FunctionFilter
|
||||
}
|
||||
|
||||
@@ -32,5 +38,16 @@ func (c *Filter) Run(reader io.Reader, writer io.Writer) error {
|
||||
cmd.Stdin = reader
|
||||
cmd.Stdout = writer
|
||||
cmd.Stderr = os.Stderr
|
||||
if c.WorkingDir != "" {
|
||||
if !filepath.IsAbs(c.WorkingDir) {
|
||||
return errors.Errorf(
|
||||
"relative working directory %s not allowed", c.WorkingDir)
|
||||
}
|
||||
if c.WorkingDir == "/" {
|
||||
return errors.Errorf(
|
||||
"root working directory '/' not allowed")
|
||||
}
|
||||
cmd.Dir = c.WorkingDir
|
||||
}
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user