mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
code review
This commit is contained in:
@@ -189,13 +189,15 @@ func (c *Filter) getCommand() (string, []string) {
|
|||||||
args = append(args, "--mount", storageMount.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("LOG_TO_STDERR", "true")
|
||||||
os.Setenv("STRUCTURED_RESULTS", "true")
|
os.Setenv("STRUCTURED_RESULTS", "true")
|
||||||
|
|
||||||
// export the local environment vars to the container
|
// export the local environment vars to the container
|
||||||
for _, pair := range os.Environ() {
|
for _, pair := range os.Environ() {
|
||||||
items := strings.Split(pair, "=")
|
items := strings.Split(pair, "=")
|
||||||
if items[0] == "" || items[1] == "" || shouldEnvIgnored(items[0]) {
|
if items[0] == "" || items[1] == "" || items[0] == "TMPDIR" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
args = append(args, "-e", items[0])
|
args = append(args, "-e", items[0])
|
||||||
@@ -203,16 +205,3 @@ func (c *Filter) getCommand() (string, []string) {
|
|||||||
a := append(args, c.Image)
|
a := append(args, c.Image)
|
||||||
return "docker", a
|
return "docker", a
|
||||||
}
|
}
|
||||||
|
|
||||||
var ignoreEnvKey []string = []string{"TMPDIR"}
|
|
||||||
|
|
||||||
// shouldEnvIgnored returns true if the environment variable key should be ignored
|
|
||||||
// by the container runtime.
|
|
||||||
func shouldEnvIgnored(envKey string) bool {
|
|
||||||
for _, k := range ignoreEnvKey {
|
|
||||||
if k == envKey {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ metadata:
|
|||||||
for _, e := range os.Environ() {
|
for _, e := range os.Environ() {
|
||||||
// the process env
|
// the process env
|
||||||
parts := strings.Split(e, "=")
|
parts := strings.Split(e, "=")
|
||||||
if parts[0] == "" || parts[1] == "" || shouldEnvIgnored(parts[0]) {
|
if parts[0] == "" || parts[1] == "" || parts[0] == "TMPDIR" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tt.expectedArgs = append(tt.expectedArgs, "-e", parts[0])
|
tt.expectedArgs = append(tt.expectedArgs, "-e", parts[0])
|
||||||
@@ -212,17 +212,13 @@ func TestFilter_ExitCode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIgnoreEnv(t *testing.T) {
|
func TestIgnoreEnv(t *testing.T) {
|
||||||
for _, key := range ignoreEnvKey {
|
os.Setenv("TMPDIR", "")
|
||||||
os.Setenv(key, "")
|
|
||||||
}
|
|
||||||
|
|
||||||
fltr := Filter{Image: "example.com:version"}
|
fltr := Filter{Image: "example.com:version"}
|
||||||
_, args := fltr.getCommand()
|
_, args := fltr.getCommand()
|
||||||
for _, arg := range args {
|
for _, arg := range args {
|
||||||
for _, key := range ignoreEnvKey {
|
if arg == "TMPDIR" {
|
||||||
if arg == key {
|
t.Fatalf("TMPDIR should not be exported to container")
|
||||||
t.Fatalf("%s should not be exported to container", key)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user