diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/api/handlers/libpod/pods.go | 30 | ||||
-rw-r--r-- | pkg/specgen/generate/container.go | 40 | ||||
-rw-r--r-- | pkg/specgen/specgen.go | 7 |
3 files changed, 58 insertions, 19 deletions
diff --git a/pkg/api/handlers/libpod/pods.go b/pkg/api/handlers/libpod/pods.go index 6e704fe65..8f8292567 100644 --- a/pkg/api/handlers/libpod/pods.go +++ b/pkg/api/handlers/libpod/pods.go @@ -135,8 +135,8 @@ func PodStop(w http.ResponseWriter, r *http.Request) { } } var errs []error //nolint - for _, err := range responses { - errs = append(errs, err) + for id, err := range responses { + errs = append(errs, errors.Wrapf(err, "error stopping container %s", id)) } report := entities.PodStopReport{ Errs: errs, @@ -164,12 +164,12 @@ func PodStart(w http.ResponseWriter, r *http.Request) { return } responses, err := pod.Start(r.Context()) - if err != nil { + if err != nil && errors.Cause(err) != define.ErrPodPartialFail { utils.Error(w, "Something went wrong", http.StatusInternalServerError, err) return } - for _, err := range responses { - errs = append(errs, err) + for id, err := range responses { + errs = append(errs, errors.Wrapf(err, "error starting container %s", id)) } report := entities.PodStartReport{ Errs: errs, @@ -220,12 +220,12 @@ func PodRestart(w http.ResponseWriter, r *http.Request) { return } responses, err := pod.Restart(r.Context()) - if err != nil { + if err != nil && errors.Cause(err) != define.ErrPodPartialFail { utils.Error(w, "Something went wrong", http.StatusInternalServerError, err) return } - for _, err := range responses { - errs = append(errs, err) + for id, err := range responses { + errs = append(errs, errors.Wrapf(err, "error restarting container %s", id)) } report := entities.PodRestartReport{ Errs: errs, @@ -271,12 +271,12 @@ func PodPause(w http.ResponseWriter, r *http.Request) { return } responses, err := pod.Pause() - if err != nil { + if err != nil && errors.Cause(err) != define.ErrPodPartialFail { utils.Error(w, "Something went wrong", http.StatusInternalServerError, err) return } - for _, v := range responses { - errs = append(errs, v) + for id, v := range responses { + errs = append(errs, errors.Wrapf(v, "error pausing container %s", id)) } report := entities.PodPauseReport{ Errs: errs, @@ -295,12 +295,12 @@ func PodUnpause(w http.ResponseWriter, r *http.Request) { return } responses, err := pod.Unpause() - if err != nil { + if err != nil && errors.Cause(err) != define.ErrPodPartialFail { utils.Error(w, "failed to pause pod", http.StatusInternalServerError, err) return } - for _, v := range responses { - errs = append(errs, v) + for id, v := range responses { + errs = append(errs, errors.Wrapf(v, "error unpausing container %s", id)) } report := entities.PodUnpauseReport{ Errs: errs, @@ -403,7 +403,7 @@ func PodKill(w http.ResponseWriter, r *http.Request) { } responses, err := pod.Kill(uint(sig)) - if err != nil { + if err != nil && errors.Cause(err) != define.ErrPodPartialFail { utils.Error(w, "failed to kill pod", http.StatusInternalServerError, err) return } diff --git a/pkg/specgen/generate/container.go b/pkg/specgen/generate/container.go index 53d160442..147ebd61b 100644 --- a/pkg/specgen/generate/container.go +++ b/pkg/specgen/generate/container.go @@ -2,6 +2,7 @@ package generate import ( "context" + "os" "github.com/containers/image/v5/manifest" "github.com/containers/podman/v2/libpod" @@ -62,14 +63,24 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat if err != nil { return nil, err } - // Get Default Environment - defaultEnvs, err := envLib.ParseSlice(rtc.Containers.Env) + // First transform the os env into a map. We need it for the labels later in + // any case. + osEnv, err := envLib.ParseSlice(os.Environ()) if err != nil { - return nil, errors.Wrap(err, "Env fields in containers.conf failed to parse") + return nil, errors.Wrap(err, "error parsing host environment variables") } + // Get Default Environment from containers.conf + defaultEnvs, err := envLib.ParseSlice(rtc.GetDefaultEnv()) + if err != nil { + return nil, errors.Wrap(err, "error parsing fields in containers.conf") + } + if defaultEnvs["containers"] == "" { + defaultEnvs["containers"] = "podman" + } var envs map[string]string + // Image Environment defaults if newImage != nil { // Image envs from the image if they don't exist // already, overriding the default environments @@ -82,9 +93,30 @@ func CompleteSpec(ctx context.Context, r *libpod.Runtime, s *specgen.SpecGenerat if err != nil { return nil, errors.Wrap(err, "Env fields from image failed to parse") } + defaultEnvs = envLib.Join(defaultEnvs, envs) + } + + // Caller Specified defaults + if s.EnvHost { + defaultEnvs = envLib.Join(defaultEnvs, osEnv) + } else if s.HTTPProxy { + for _, envSpec := range []string{ + "http_proxy", + "HTTP_PROXY", + "https_proxy", + "HTTPS_PROXY", + "ftp_proxy", + "FTP_PROXY", + "no_proxy", + "NO_PROXY", + } { + if v, ok := osEnv[envSpec]; ok { + defaultEnvs[envSpec] = v + } + } } - s.Env = envLib.Join(envLib.Join(defaultEnvs, envs), s.Env) + s.Env = envLib.Join(defaultEnvs, s.Env) // Labels and Annotations annotations := make(map[string]string) diff --git a/pkg/specgen/specgen.go b/pkg/specgen/specgen.go index a52225f87..cca05eddb 100644 --- a/pkg/specgen/specgen.go +++ b/pkg/specgen/specgen.go @@ -43,6 +43,13 @@ type ContainerBasicConfig struct { // image's configuration. // Optional. Command []string `json:"command,omitempty"` + // EnvHost indicates that the host environment should be added to container + // Optional. + EnvHost bool `json:"env_host,omitempty"` + // EnvHTTPProxy indicates that the http host proxy environment variables + // should be added to container + // Optional. + HTTPProxy bool `json:"httpproxy,omitempty"` // Env is a set of environment variables that will be set in the // container. // Optional. |