container_create: correctly set image and kube envs
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
e4470612a2
commit
cc0f78dfc4
1 changed files with 36 additions and 20 deletions
|
@ -1006,30 +1006,46 @@ func (s *Server) createSandboxContainer(ctx context.Context, containerID string,
|
||||||
}
|
}
|
||||||
specgen.SetProcessArgs(processArgs)
|
specgen.SetProcessArgs(processArgs)
|
||||||
|
|
||||||
// Add environment variables from CRI and image config
|
envs := []string{}
|
||||||
envs := containerConfig.GetEnvs()
|
if containerConfig.GetEnvs() == nil && containerImageConfig != nil {
|
||||||
if envs != nil {
|
envs = containerImageConfig.Config.Env
|
||||||
for _, item := range envs {
|
} else {
|
||||||
key := item.Key
|
for _, item := range containerConfig.GetEnvs() {
|
||||||
value := item.Value
|
if item.GetKey() == "" {
|
||||||
if key == "" {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
specgen.AddProcessEnv(key, value)
|
envs = append(envs, item.GetKey()+"="+item.GetValue())
|
||||||
|
}
|
||||||
|
if containerImageConfig != nil {
|
||||||
|
for _, imageEnv := range containerImageConfig.Config.Env {
|
||||||
|
var found bool
|
||||||
|
parts := strings.SplitN(imageEnv, "=", 2)
|
||||||
|
if len(parts) != 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
imageEnvKey := parts[0]
|
||||||
|
if imageEnvKey == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, kubeEnv := range envs {
|
||||||
|
kubeEnvKey := strings.SplitN(kubeEnv, "=", 2)[0]
|
||||||
|
if kubeEnvKey == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if imageEnvKey == kubeEnvKey {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
envs = append(envs, imageEnv)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if containerImageConfig != nil {
|
for _, e := range envs {
|
||||||
for _, item := range containerImageConfig.Config.Env {
|
parts := strings.SplitN(e, "=", 2)
|
||||||
parts := strings.SplitN(item, "=", 2)
|
specgen.AddProcessEnv(parts[0], parts[1])
|
||||||
if len(parts) != 2 {
|
|
||||||
return nil, fmt.Errorf("invalid env from image: %s", item)
|
|
||||||
}
|
|
||||||
|
|
||||||
if parts[0] == "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
specgen.AddProcessEnv(parts[0], parts[1])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set working directory
|
// Set working directory
|
||||||
|
|
Loading…
Reference in a new issue