mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Ignore TMPDIR when run container
This commit is contained in:
@@ -195,7 +195,7 @@ func (c *Filter) getCommand() (string, []string) {
|
||||
// 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] == "" || shouldEnvIgnored(items[0]) {
|
||||
continue
|
||||
}
|
||||
args = append(args, "-e", items[0])
|
||||
@@ -203,3 +203,15 @@ func (c *Filter) getCommand() (string, []string) {
|
||||
a := append(args, c.Image)
|
||||
return "docker", a
|
||||
}
|
||||
|
||||
// shouldEnvIgnored returns true if the environment variable key should be ignored
|
||||
// by the container runtime.
|
||||
func shouldEnvIgnored(envKey string) bool {
|
||||
ignoreEnvKey := []string{"TMPDIR"}
|
||||
for _, k := range ignoreEnvKey {
|
||||
if k == envKey {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -210,3 +210,20 @@ func TestFilter_ExitCode(t *testing.T) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
func TestIgnoreEnv(t *testing.T) {
|
||||
ignoredEnvKey := []string{"TMPDIR"}
|
||||
for _, key := range ignoredEnvKey {
|
||||
os.Setenv(key, "")
|
||||
}
|
||||
|
||||
fltr := Filter{Image: "example.com:version"}
|
||||
_, args := fltr.getCommand()
|
||||
for _, arg := range args {
|
||||
for _, key := range ignoredEnvKey {
|
||||
if arg == key {
|
||||
t.Fatalf("%s should not be exported to container", key)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user