Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Shell32-Natsu committed Aug 5, 2020
1 parent 2f7241f commit 8cdc97a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
17 changes: 3 additions & 14 deletions kyaml/fn/runtime/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,30 +189,19 @@ 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] == "" || shouldEnvIgnored(items[0]) {
if items[0] == "" || items[1] == "" || items[0] == "TMPDIR" {
continue
}
args = append(args, "-e", items[0])
}
a := append(args, c.Image)
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
}
12 changes: 4 additions & 8 deletions kyaml/fn/runtime/container/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ metadata:
for _, e := range os.Environ() {
// the process env
parts := strings.Split(e, "=")
if parts[0] == "" || parts[1] == "" || shouldEnvIgnored(parts[0]) {
if parts[0] == "" || parts[1] == "" || parts[0] == "TMPDIR" {
continue
}
tt.expectedArgs = append(tt.expectedArgs, "-e", parts[0])
Expand Down Expand Up @@ -212,17 +212,13 @@ func TestFilter_ExitCode(t *testing.T) {
}

func TestIgnoreEnv(t *testing.T) {
for _, key := range ignoreEnvKey {
os.Setenv(key, "")
}
os.Setenv("TMPDIR", "")

fltr := Filter{Image: "example.com:version"}
_, args := fltr.getCommand()
for _, arg := range args {
for _, key := range ignoreEnvKey {
if arg == key {
t.Fatalf("%s should not be exported to container", key)
}
if arg == "TMPDIR" {
t.Fatalf("TMPDIR should not be exported to container")
}
}
}

0 comments on commit 8cdc97a

Please sign in to comment.