summaryrefslogtreecommitdiff
path: root/pkg/specgen/generate
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2020-05-06 13:20:44 +0200
committerDaniel J Walsh <dwalsh@redhat.com>2020-05-07 14:16:50 -0400
commit99bdafba999078bb5763c65cf7dfe7df520030f7 (patch)
tree916c768fca45b5e809f9e941b5425e760dcfe08c /pkg/specgen/generate
parent1d3cdf9a4642df073becb54d178d6b1959526a47 (diff)
downloadpodman-99bdafba999078bb5763c65cf7dfe7df520030f7.tar.gz
podman-99bdafba999078bb5763c65cf7dfe7df520030f7.tar.bz2
podman-99bdafba999078bb5763c65cf7dfe7df520030f7.zip
podman: split env variables in env and overrides
There are three different priorities for applying env variables: 1) environment/config file environment variables 2) image's config 3) user overrides (--env) The third kind are known to the client, while the default config and image's config is handled by the backend. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'pkg/specgen/generate')
-rw-r--r--pkg/specgen/generate/container.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go
index 92a2b4d35..e4bd2991a 100644
--- a/pkg/specgen/generate/container.go
+++ b/pkg/specgen/generate/container.go
@@ -9,6 +9,7 @@ import (
envLib "github.com/containers/libpod/pkg/env"
"github.com/containers/libpod/pkg/signal"
"github.com/containers/libpod/pkg/specgen"
+ "github.com/pkg/errors"
"golang.org/x/sys/unix"
)
@@ -48,24 +49,28 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat
s.StopSignal = &sig
}
+ rtc, err := r.GetConfig()
+ if err != nil {
+ return err
+ }
+ // Get Default Environment
+ defaultEnvs, err := envLib.ParseSlice(rtc.Containers.Env)
+ if err != nil {
+ return errors.Wrap(err, "Env fields in containers.conf failed to parse")
+ }
+
// Image envs from the image if they don't exist
- // already
- env, err := newImage.Env(ctx)
+ // already, overriding the default environments
+ imageEnvs, err := newImage.Env(ctx)
if err != nil {
return err
}
- if len(env) > 0 {
- envs, err := envLib.ParseSlice(env)
- if err != nil {
- return err
- }
- for k, v := range envs {
- if _, exists := s.Env[k]; !exists {
- s.Env[v] = k
- }
- }
+ envs, err := envLib.ParseSlice(imageEnvs)
+ if err != nil {
+ return errors.Wrap(err, "Env fields from image failed to parse")
}
+ s.Env = envLib.Join(envLib.Join(defaultEnvs, envs), s.Env)
labels, err := newImage.Labels(ctx)
if err != nil {