explicitly specify envs to be exported in function

This commit is contained in:
Donny Xia
2020-08-24 13:35:18 -07:00
parent 30b58e90a3
commit 904a9dea08
6 changed files with 242 additions and 29 deletions

View File

@@ -5,8 +5,6 @@ package container
import (
"fmt"
"os"
"strings"
runtimeexec "sigs.k8s.io/kustomize/kyaml/fn/runtime/exec"
"sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil"
@@ -177,19 +175,7 @@ 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] == "" || items[0] == tmpDirEnvKey {
continue
}
args = append(args, "-e", items[0])
}
args = append(args, c.Envs.GetDockerFlags()...)
a := append(args, c.Image)
return "docker", a
}

View File

@@ -7,7 +7,6 @@ import (
"bytes"
"fmt"
"os"
"strings"
"testing"
"github.com/stretchr/testify/assert"
@@ -137,20 +136,13 @@ metadata:
}
tt.instance.Exec.FunctionConfig = cfg
os.Setenv("KYAML_TEST", "FOO")
tt.instance.setupExec()
tt.instance.Envs.AddKeyValue("KYAML_TEST", "FOO")
tt.expectedArgs = append(tt.expectedArgs, tt.instance.Envs.GetDockerFlags()...)
// configure expected env
for _, e := range os.Environ() {
// the process env
parts := strings.Split(e, "=")
if parts[0] == "" || parts[1] == "" || parts[0] == tmpDirEnvKey {
continue
}
tt.expectedArgs = append(tt.expectedArgs, "-e", parts[0])
}
tt.expectedArgs = append(tt.expectedArgs, tt.instance.Image)
tt.instance.setupExec()
if !assert.Equal(t, "docker", tt.instance.Exec.Path) {
t.FailNow()
}