This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch release-1.7.x
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit 64cdd75e1704882343861ff7a1b5542e5d4239eb
Author: Antonin Stefanutti <[email protected]>
AuthorDate: Mon Jan 10 12:47:19 2022 +0100

    feat(trait): Propagate HTTP proxy env variables to integration Pods
---
 docs/modules/traits/pages/environment.adoc |  8 +++++++-
 pkg/trait/environment.go                   | 20 +++++++++++++++++++-
 resources/traits.yaml                      |  9 +++++++--
 3 files changed, 33 insertions(+), 4 deletions(-)

diff --git a/docs/modules/traits/pages/environment.adoc 
b/docs/modules/traits/pages/environment.adoc
index f3d9c0e..754f155 100755
--- a/docs/modules/traits/pages/environment.adoc
+++ b/docs/modules/traits/pages/environment.adoc
@@ -32,9 +32,15 @@ The following configuration options are available:
 | bool
 | Enables injection of `NAMESPACE` and `POD_NAME` environment variables 
(default `true`)
 
+| environment.http-proxy
+| bool
+| Propagates the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment 
variables (default `true`)
+
 | environment.vars
 | []string
-| A list of variables to be created on the Pod. Must have KEY=VALUE syntax 
(ie, MY_VAR="my value").
+| A list of environment variables to be added to the integration container.
+The syntax is KEY=VALUE, e.g., `MY_VAR="my value"`.
+These take precedence over the previously defined environment variables.
 
 |===
 
diff --git a/pkg/trait/environment.go b/pkg/trait/environment.go
index b4ebfa8..e158bb4 100644
--- a/pkg/trait/environment.go
+++ b/pkg/trait/environment.go
@@ -18,6 +18,8 @@ limitations under the License.
 package trait
 
 import (
+       "os"
+
        "github.com/apache/camel-k/pkg/util/defaults"
        "github.com/apache/camel-k/pkg/util/envvar"
        "github.com/apache/camel-k/pkg/util/property"
@@ -31,7 +33,11 @@ type environmentTrait struct {
        BaseTrait `property:",squash"`
        // Enables injection of `NAMESPACE` and `POD_NAME` environment 
variables (default `true`)
        ContainerMeta *bool `property:"container-meta" 
json:"containerMeta,omitempty"`
-       // A list of variables to be created on the Pod. Must have KEY=VALUE 
syntax (ie, MY_VAR="my value").
+       // Propagates the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` 
environment variables (default `true`)
+       HTTPProxy *bool `property:"http-proxy" json:"httpProxy,omitempty"`
+       // A list of environment variables to be added to the integration 
container.
+       // The syntax is KEY=VALUE, e.g., `MY_VAR="my value"`.
+       // These take precedence over the previously defined environment 
variables.
        Vars []string `property:"vars" json:"vars,omitempty"`
 }
 
@@ -81,6 +87,18 @@ func (t *environmentTrait) Apply(e *Environment) error {
                envvar.SetValFrom(&e.EnvVars, envVarPodName, "metadata.name")
        }
 
+       if IsNilOrTrue(t.HTTPProxy) {
+               if HTTPProxy, ok := os.LookupEnv("HTTP_PROXY"); ok {
+                       envvar.SetVal(&e.EnvVars, "HTTP_PROXY", HTTPProxy)
+               }
+               if HTTPSProxy, ok := os.LookupEnv("HTTPS_PROXY"); ok {
+                       envvar.SetVal(&e.EnvVars, "HTTPS_PROXY", HTTPSProxy)
+               }
+               if noProxy, ok := os.LookupEnv("NO_PROXY"); ok {
+                       envvar.SetVal(&e.EnvVars, "NO_PROXY", noProxy)
+               }
+       }
+
        if t.Vars != nil {
                for _, env := range t.Vars {
                        k, v := property.SplitPropertyFileEntry(env)
diff --git a/resources/traits.yaml b/resources/traits.yaml
index a19f164..a28715d 100755
--- a/resources/traits.yaml
+++ b/resources/traits.yaml
@@ -315,10 +315,15 @@ traits:
     type: bool
     description: Enables injection of `NAMESPACE` and `POD_NAME` environment 
variables
       (default `true`)
+  - name: http-proxy
+    type: bool
+    description: Propagates the `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` 
environment
+      variables (default `true`)
   - name: vars
     type: '[]string'
-    description: A list of variables to be created on the Pod. Must have 
KEY=VALUE
-      syntax (ie, MY_VAR="my value").
+    description: A list of environment variables to be added to the 
integration container.The
+      syntax is KEY=VALUE, e.g., `MY_VAR="my value"`.These take precedence 
over the
+      previously defined environment variables.
 - name: error-handler
   platform: true
   profiles:

Reply via email to