Remove redundant env field

This commit is contained in:
Donny Xia
2020-08-26 12:49:42 -07:00
parent 46194b3385
commit c202be0338
6 changed files with 40 additions and 46 deletions

View File

@@ -102,6 +102,18 @@ func (ce *ContainerEnv) AddKey(key string) {
}
}
// Raw returns a slice of string which represents the envs.
// Example: [foo=bar, baz]
func (ce *ContainerEnv) Raw() []string {
var ret []string
for k, v := range ce.EnvVars {
ret = append(ret, k+"="+v)
}
ret = append(ret, ce.VarsToExport...)
return ret
}
// NewContainerEnv returns a pointer to a new ContainerEnv
func NewContainerEnv() *ContainerEnv {
var ce ContainerEnv
@@ -162,11 +174,8 @@ type ContainerSpec struct {
// User is the username/uid that application runs as in continer
User ContainerUser `json:"user,omitempty" yaml:"user,omitempty"`
// EnvRaw is a slice of env string.
EnvRaw []string `json:"envs,omitempty" yaml:"envs,omitempty"`
// Env contains environment variables that will be exported to container
Env ContainerEnv `json:"-" yaml:"-"`
// Env is a slice of env string that will be exposed to container
Env []string `json:"envs,omitempty" yaml:"envs,omitempty"`
}
// ContainerNetwork
@@ -230,7 +239,6 @@ func GetFunctionSpec(n *yaml.RNode) *FunctionSpec {
if fn := getFunctionSpecFromAnnotation(n, meta); fn != nil {
fn.Container.Network.Name = NetworkNameEmpty
fn.StorageMounts = []StorageMount{}
fn.Container.Env = *NewContainerEnvFromStringSlice(fn.Container.EnvRaw)
return fn
}

View File

@@ -1514,6 +1514,6 @@ metadata:
return
}
fn := GetFunctionSpec(cfg)
assert.Equal(t, tc.expected, fn.Container.Env)
assert.Equal(t, tc.expected, *NewContainerEnvFromStringSlice(fn.Container.Env))
}
}