From 82a0ff9d5ccb90ce74a498f763eec6559a7a3c33 Mon Sep 17 00:00:00 2001 From: Qi Wang Date: Thu, 25 Jun 2020 17:00:05 -0400 Subject: [PATCH] Add container_engine_env for engine to use Add container_env_var for setting envariables for engin to use. Signed-off-by: Qi Wang --- common/docs/containers.conf.5.md | 5 +++++ common/pkg/config/config.go | 3 +++ common/pkg/config/config_local_test.go | 10 ++++++++++ common/pkg/config/containers.conf | 6 ++++++ common/pkg/config/testdata/containers_default.conf | 6 ++++++ 5 files changed, 30 insertions(+) diff --git a/common/docs/containers.conf.5.md b/common/docs/containers.conf.5.md index 5ab198007b..6a1f520c69 100644 --- a/common/docs/containers.conf.5.md +++ b/common/docs/containers.conf.5.md @@ -271,6 +271,11 @@ they cannot be reused by other programs on the host. However, this can cause significant memory usage if a container has many ports forwarded to it. Disabling this can save memory. +**env**=[] +Environment variables to be used when running the container engine. For example "http_proxy=internal.proxy.company.com". +Note these environment variables will not be used within the container. Set the env section under [containers] table, +if you want to set environment variables for the container. + **events_logger**="journald" Default method to use when logging events. Valid values: `file`, `journald`, and `none`. diff --git a/common/pkg/config/config.go b/common/pkg/config/config.go index 385627e337..4477beb206 100644 --- a/common/pkg/config/config.go +++ b/common/pkg/config/config.go @@ -207,6 +207,9 @@ type EngineConfig struct { // memory. EnablePortReservation bool `toml:"enable_port_reservation,omitempty"` + // Environment variables to be used when running the container engine. For example "http_proxy=internal.proxy.company.com" + Env []string `toml:"env,omitempty"` + // EventsLogFilePath is where the events log is stored. EventsLogFilePath string `toml:"events_logfile_path,omitempty"` diff --git a/common/pkg/config/config_local_test.go b/common/pkg/config/config_local_test.go index b840acf37f..d5c90942cc 100644 --- a/common/pkg/config/config_local_test.go +++ b/common/pkg/config/config_local_test.go @@ -168,6 +168,16 @@ var _ = Describe("Config Local", func() { gomega.Expect(err).NotTo(gomega.BeNil()) }) + It("should return containers engine env", func() { + // Given + expectedEnv := []string{"http_proxy=internal.proxy.company.com", "foo=bar"} + // When + config, err := NewConfig("testdata/containers_default.conf") + // Then + gomega.Expect(err).To(gomega.BeNil()) + gomega.Expect(config.Engine.Env).To(gomega.BeEquivalentTo(expectedEnv)) + }) + It("Expect Remote to be False", func() { // Given // When diff --git a/common/pkg/config/containers.conf b/common/pkg/config/containers.conf index 3c00048d1e..f185e43163 100644 --- a/common/pkg/config/containers.conf +++ b/common/pkg/config/containers.conf @@ -279,6 +279,12 @@ # # enable_port_reservation = true +# Environment variables to be used when running the container engine. +# For example "http_proxy=internal.proxy.company.com". +# Note these environment variables will not be used within the container. +# Set the env section under [containers] table, if you want to set environment variables for the container. +# env = [] + # Selects which logging mechanism to use for container engine events. # Valid values are `journald`, `file` and `none`. # diff --git a/common/pkg/config/testdata/containers_default.conf b/common/pkg/config/testdata/containers_default.conf index e7ed99195e..8888556263 100644 --- a/common/pkg/config/testdata/containers_default.conf +++ b/common/pkg/config/testdata/containers_default.conf @@ -127,6 +127,12 @@ conmon_path = [ "/usr/local/sbin/conmon" ] +# Environment variables to be used when running the container engine. +# For example "http_proxy=internal.proxy.company.com". +# Note these environment variables will not be used within the container. +# Set the env section under [containers] table, if you want to set environment variables for the container. +env = ["http_proxy=internal.proxy.company.com", "foo=bar"] + # Container init binary #init_path = "/usr/libexec/podman/catatonit"