This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 3d47d89cbc498c32bce07436720ffb367b8b4e87 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 +++++++- docs/modules/traits/pages/mount.adoc | 13 +++++++++---- pkg/trait/environment.go | 20 +++++++++++++++++++- resources/traits.yaml | 25 ++++++++++++++++++------- 4 files changed, 53 insertions(+), 13 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/docs/modules/traits/pages/mount.adoc b/docs/modules/traits/pages/mount.adoc index d5e2c19..cd9d549 100644 --- a/docs/modules/traits/pages/mount.adoc +++ b/docs/modules/traits/pages/mount.adoc @@ -1,9 +1,8 @@ = Mount Trait // Start of autogenerated code - DO NOT EDIT! (description) -The Mount trait can be used to configure volumes mounted on the Integration Pod. +The Mount trait can be used to configure volumes mounted on the Integration Pods. -nolint: tagliatelle This trait is available in the following profiles: **Kubernetes, Knative, OpenShift**. @@ -30,11 +29,17 @@ The following configuration options are available: | mount.configs | []string -| A list of configuration pointing to configmap/secret. Syntax: [configmap\|secret]:name[key], where name represents the resource name and key optionally represents the resource key to be filtered +| A list of configuration pointing to configmap/secret. +The configuration are expected to be UTF-8 resources as they are processed by runtime Camel Context and tried to be parsed as property files. +They are also made available on the classpath in order to ease their usage directly from the Route. +Syntax: [configmap\|secret]:name[key], where name represents the resource name and key optionally represents the resource key to be filtered | mount.resources | []string -| A list of resources pointing to configmap/secret. Syntax: [configmap\|secret]:name[/key][@path], where name represents the resource name, key optionally represents the resource key to be filtered and path represents the destination path +| A list of resources (text or binary content) pointing to configmap/secret. +The resources are expected to be any resource type (text or binary content). +The destination path can be either a default location or any path specified by the user. +Syntax: [configmap\|secret]:name[/key][@path], where name represents the resource name, key optionally represents the resource key to be filtered and path represents the destination path | mount.volumes | []string diff --git a/pkg/trait/environment.go b/pkg/trait/environment.go index 2a21580..0412f17 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/camel" "github.com/apache/camel-k/pkg/util/defaults" "github.com/apache/camel-k/pkg/util/envvar" @@ -32,7 +34,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"` } @@ -82,6 +88,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 fd24ebe..c0d1365 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: @@ -810,7 +815,7 @@ traits: - Knative - OpenShift description: 'The Mount trait can be used to configure volumes mounted on the Integration - Pod. nolint: tagliatelle' + Pods. nolint: tagliatelle' properties: - name: enabled type: bool @@ -818,14 +823,20 @@ traits: property. - name: configs type: '[]string' - description: 'A list of configuration pointing to configmap/secret. Syntax: [configmap|secret]:name[key], + description: 'A list of configuration pointing to configmap/secret.The configuration + are expected to be UTF-8 resources as they are processed by runtime Camel Context + and tried to be parsed as property files.They are also made available on the + classpath in order to ease their usage directly from the Route.Syntax: [configmap|secret]:name[key], where name represents the resource name and key optionally represents the resource key to be filtered' - name: resources type: '[]string' - description: 'A list of resources pointing to configmap/secret. Syntax: [configmap|secret]:name[/key][@path], - where name represents the resource name, key optionally represents the resource - key to be filtered and path represents the destination path' + description: 'A list of resources (text or binary content) pointing to configmap/secret.The + resources are expected to be any resource type (text or binary content).The + destination path can be either a default location or any path specified by the + user.Syntax: [configmap|secret]:name[/key][@path], where name represents the + resource name, key optionally represents the resource key to be filtered and + path represents the destination path' - name: volumes type: '[]string' description: 'A list of Persistent Volume Claims to be mounted. Syntax: [pvcname:/container/path]'
