mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-01 18:30:15 +00:00
Merge pull request #2800 from Shell32-Natsu/ignore-tempdir-env
Ignore TMPDIR when run container
This commit is contained in:
@@ -162,6 +162,8 @@ func (c *Filter) setupExec() {
|
||||
c.Exec.Args = args
|
||||
}
|
||||
|
||||
var tmpDirEnvKey string = "TMPDIR"
|
||||
|
||||
// getArgs returns the command + args to run to spawn the container
|
||||
func (c *Filter) getCommand() (string, []string) {
|
||||
// run the container using docker. this is simpler than using the docker
|
||||
@@ -189,13 +191,15 @@ func (c *Filter) getCommand() (string, []string) {
|
||||
args = append(args, "--mount", storageMount.String())
|
||||
}
|
||||
|
||||
// TODO: put these env processes into a separate function and call it in the outside of
|
||||
// getCommand
|
||||
os.Setenv("LOG_TO_STDERR", "true")
|
||||
os.Setenv("STRUCTURED_RESULTS", "true")
|
||||
|
||||
// export the local environment vars to the container
|
||||
for _, pair := range os.Environ() {
|
||||
items := strings.Split(pair, "=")
|
||||
if items[0] == "" || items[1] == "" {
|
||||
if items[0] == "" || items[1] == "" || items[0] == tmpDirEnvKey {
|
||||
continue
|
||||
}
|
||||
args = append(args, "-e", items[0])
|
||||
|
||||
@@ -106,7 +106,7 @@ metadata:
|
||||
for _, e := range os.Environ() {
|
||||
// the process env
|
||||
parts := strings.Split(e, "=")
|
||||
if parts[0] == "" || parts[1] == "" {
|
||||
if parts[0] == "" || parts[1] == "" || parts[0] == tmpDirEnvKey {
|
||||
continue
|
||||
}
|
||||
tt.expectedArgs = append(tt.expectedArgs, "-e", parts[0])
|
||||
@@ -210,3 +210,15 @@ func TestFilter_ExitCode(t *testing.T) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestIgnoreEnv(t *testing.T) {
|
||||
os.Setenv(tmpDirEnvKey, "")
|
||||
|
||||
fltr := Filter{Image: "example.com:version"}
|
||||
_, args := fltr.getCommand()
|
||||
for _, arg := range args {
|
||||
if arg == tmpDirEnvKey {
|
||||
t.Fatalf("%s should not be exported to container", tmpDirEnvKey)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user