You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2022/01/12 13:53:46 UTC

[camel-k] branch main updated (590b23c -> 863887e)

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

astefanutti pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git.


    from 590b23c  Fix #1107: fix expected roles in tests
     new 57b9569  feat(maven): Support platform Maven settings
     new 8993eca  feat(maven): Honor proxy environment variables
     new 05a2737  chore(maven): Default to standard HTTP and HTTPS port numbers
     new 6690786  chore(maven): Set Maven proxy ID in global settings
     new 59a87cf  chore(maven): Convert NO_PROXY to http.nonProxyHosts JVM system property format
     new 630afe3  feat(maven): HTTP proxy e2e tests
     new e094e36  fix(proxy): HTTPS proxy can use HTTP scheme
     new c2131ca  chore(e2e): Set NO_PROXY with the Kubernetes service cluster IPs
     new 92259fb  chore(maven): Add default Maven repositories to global settings
     new ebcc70c  chore(maven): Separate user and platform Maven settings
     new 4cc932c  chore(api): Remove Maven repositories from the platform API
     new 9d35c05  chore: Fix lints
     new 083c4f8  chore(maven): Unify settings API
     new c125dc9  chore(e2e): Add extra RBAC permissions for the HTTP proxy tests
     new 3d47d89  feat(trait): Propagate HTTP proxy env variables to integration Pods
     new 52fd932  chore(e2e): Add environment trait e2e tests
     new da18313  feat(jvm): Translate HTTP proxy env variables into system properties
     new c747683  chore(jvm): Fail fast when no integration container is found
     new da858f3  chore(jvm): Rely on default JVM HTTP proxy port numbers
     new 98bed0f  fix(jvm): NO_PROXY translates to -Dhttp.nonProxyHosts
     new aa89ed2  fix(jvm): Quote HTTP proxy system property values
     new 254c8e7  fix(e2e): Add Maven repositories to NO_PROXY
     new f77b553  fix(e2e): Add container registry to NO_PROXY
     new d0c1651  feat: Propagate HTTP proxy environment to build Pods
     new 3920592  fix(e2e): assert downward API in environment trait tests
     new 360be86  chore(api): Remove HTTP proxy Secret
     new 39a1ea1  fix(e2e): Use different integrations in environment trait tests
     new a007707  chore(e2e): assert HTTP proxy logs
     new cc4449f  chore: Rebuild resources
     new 4e15b69  feat: Add HTTP proxy documentation
     new 863887e  chore(e2e): Move HTTPD resources creation in separate functions

The 31 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .github/workflows/openshift.yml                    |  28 ++
 config/crd/bases/camel.apache.org_builds.yaml      |  23 +-
 .../crd/bases/camel.apache.org_camelcatalogs.yaml  |   6 +-
 .../camel.apache.org_integrationplatforms.yaml     |  90 +----
 docs/modules/ROOT/nav.adoc                         |   1 +
 .../ROOT/pages/configuration/http-proxy.adoc       | 116 +++++++
 docs/modules/ROOT/pages/configuration/maven.adoc   |  44 ++-
 docs/modules/traits/pages/environment.adoc         |   8 +-
 docs/modules/traits/pages/mount.adoc               |  13 +-
 e2e/common/build/maven_http_proxy_test.go          | 367 +++++++++++++++++++++
 e2e/common/traits/environment_test.go              | 166 ++++++++++
 e2e/support/regexp.go                              | 119 +++++++
 helm/camel-k/crds/crd-build.yaml                   |  23 +-
 helm/camel-k/crds/crd-camel-catalog.yaml           |   6 +-
 helm/camel-k/crds/crd-integration-platform.yaml    |  90 +----
 pkg/apis/camel/v1/build_types.go                   |  25 +-
 pkg/apis/camel/v1/common_types.go                  |  30 --
 pkg/apis/camel/v1/integrationplatform_types.go     |   1 -
 pkg/apis/camel/v1/maven_types.go                   |  39 ++-
 pkg/apis/camel/v1/zz_generated.deepcopy.go         |  27 +-
 pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go   |   1 -
 pkg/builder/project.go                             |  13 +-
 pkg/builder/project_test.go                        |  32 +-
 pkg/builder/quarkus.go                             |   6 +-
 pkg/builder/types.go                               |   3 +-
 pkg/cmd/install.go                                 |  94 +++++-
 pkg/cmd/install_test.go                            |   7 -
 pkg/cmd/util_dependencies.go                       |  26 +-
 pkg/controller/build/build_pod.go                  |  51 +--
 .../integrationplatform/initialize_test.go         |  26 --
 pkg/platform/defaults.go                           |  78 +----
 pkg/resources/resources.go                         |  12 +-
 pkg/trait/builder.go                               |  11 +-
 pkg/trait/environment.go                           |  20 +-
 pkg/trait/jvm.go                                   |  59 +++-
 pkg/trait/openapi.go                               |  20 +-
 pkg/util/camel/catalog.go                          |  30 +-
 pkg/util/maven/maven_command.go                    |  23 +-
 pkg/util/maven/maven_proxies.go                    |  89 +++++
 pkg/util/maven/maven_repositories.go               |  94 ++++++
 pkg/util/maven/maven_settings.go                   | 102 +-----
 pkg/util/maven/maven_settings_test.go              |  42 +--
 pkg/util/maven/maven_types.go                      |  12 +
 resources/traits.yaml                              |  25 +-
 44 files changed, 1495 insertions(+), 603 deletions(-)
 create mode 100644 docs/modules/ROOT/pages/configuration/http-proxy.adoc
 create mode 100644 e2e/common/build/maven_http_proxy_test.go
 create mode 100644 e2e/common/traits/environment_test.go
 create mode 100644 e2e/support/regexp.go
 create mode 100644 pkg/util/maven/maven_proxies.go
 create mode 100644 pkg/util/maven/maven_repositories.go

[camel-k] 30/31: feat: Add HTTP proxy documentation

Posted by as...@apache.org.
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 4e15b691d47ed8c2aff86c4a08eb0b783f50d636
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Jan 12 11:33:37 2022 +0100

    feat: Add HTTP proxy documentation
---
 docs/modules/ROOT/nav.adoc                         |   1 +
 .../ROOT/pages/configuration/http-proxy.adoc       | 116 +++++++++++++++++++++
 docs/modules/ROOT/pages/configuration/maven.adoc   |  44 ++++++--
 3 files changed, 153 insertions(+), 8 deletions(-)

diff --git a/docs/modules/ROOT/nav.adoc b/docs/modules/ROOT/nav.adoc
index 890e733..068bf24 100644
--- a/docs/modules/ROOT/nav.adoc
+++ b/docs/modules/ROOT/nav.adoc
@@ -32,6 +32,7 @@
 ** xref:configuration/runtime-properties.adoc[Properties]
 ** xref:configuration/runtime-config.adoc[Runtime configuration]
 ** xref:configuration/runtime-resources.adoc[Runtime resources]
+** xref:configuration/http-proxy.adoc[HTTP Proxy]
 ** xref:configuration/maven.adoc[Maven]
 * Observability
 ** xref:observability/logging.adoc[Logging]
diff --git a/docs/modules/ROOT/pages/configuration/http-proxy.adoc b/docs/modules/ROOT/pages/configuration/http-proxy.adoc
new file mode 100644
index 0000000..1240c03
--- /dev/null
+++ b/docs/modules/ROOT/pages/configuration/http-proxy.adoc
@@ -0,0 +1,116 @@
+[[http-proxy]]
+= HTTP Proxy
+
+Production or corporate environments can deny direct access to the Internet, and mandates egress traffic to go through an HTTP or HTTPS proxy.
+
+The Camel K operator can be configured to route egress traffic to this proxy, by setting the usual `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` on the operator Deployment.
+
+This can be achieved with the Kamel CLI, at installation time, e.g.:
+
+[source,console]
+----
+$ kamel install --operator-env-vars=HTTP_PROXY=http://proxy
+----
+
+Alternatively, the operator Deployment can be amended with the `kubectl` CLI, e.g.:
+
+[source,console]
+----
+$ kubectl set env deployment camel-k-operator HTTP_PROXY=http://proxy
+----
+
+The `HTTP_PROXY` and `HTTPS_PROXY` environment variable values expect URLs following the `http://[<username>[:<pswd>]@]<host>[:<port>]` format, e.g.:
+
+[source]
+----
+HTTP_PROXY=http://proxy.corp.tld
+----
+
+NOTE: Maven currently does not support connecting to an HTTP proxy via TLS. For this reason, the scheme of the `HTTPS_PROXY` value is restricted to `http`.
+
+The `NO_PROXY` environment variable value expects a comma-separated list of destination domain names, domain suffixes, IP addresses or other network CIDRs, e.g.:
+
+[source]
+----
+NO_PROXY=.cluster.local,.svc,10.0.0.0/16,127.0.0.1,localhost
+----
+
+By default, all egress traffic, generated by all the workloads and processes managed by the Camel K operator, will be proxied.
+This encompasses:
+
+* Communicating with the Kubernetes API server
+* Downloading Maven artifacts from repositories
+* Pulling base images from container registries
+* Pushing images to the configured container registry
+
+For this reason, services that the operator requires access to should be reviewed, and it must be determined whether any of them must bypass the proxy.
+
+This particularly applies to internal services, hosted within the cluster, whose internal domain names or IP addresses should be added to the `NO_PROXY` environment variable.
+
+Typically, the `NO_PROXY` variable should be populated with the internal domain suffixes, as well as the cluster network CIDRs, e.g.:
+
+[source]
+----
+NO_PROXY=.cluster.local,.svc,10.0.0.0/16,127.0.0.1,172.17.0.0/18,172.21.0.0/16,localhost
+----
+
+NOTE: As the Camel K operator communicates with the Kubernetes API, the cluster IPs of the Kubernetes Service must at least be specified in `NO_PROXY`, anytime an HTTP proxy is configured.
+
+By default, the `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables are also propagated to the integrations.
+This behavior can be deactivated, by using the `http-proxy` parameter of the _environment_ trait, e.g.:
+
+[source,console]
+----
+$ kamel run -t environment.http-proxy=false
+----
+
+Alternatively, it can be disabled globally, by editing the IntegrationPlatform resources, e.g.:
+
+[source, yaml]
+----
+apiVersion: camel.apache.org/v1
+kind: IntegrationPlatform
+metadata:
+  name: camel-k
+spec:
+  traits:
+    environment:
+      configuration:
+        httpProxy: false # <1>
+----
+<1> Deactivates the propagation of HTTP proxy environment variables at the platform level
+
+[[openshift]]
+=== OpenShift
+
+On OpenShift 4, cluster-wide egress proxy can be configured by editing the `cluster` Proxy resource:
+
+[source,yaml]
+----
+apiVersion: config.openshift.io/v1
+kind: Proxy
+metadata:
+  name: cluster
+spec:
+  httpProxy: http://<username>:<pswd>@<ip>:<port>
+----
+
+Operator Lifecycle Manager (OLM), sources the status of this `cluster` Proxy, to automatically populate the `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables, on the operator Deployment resources it manages.
+
+These cluster-wide proxy settings can be overwritten, specifically for the Camel K operator if necessary, by editing the corresponding Subscription resource, e.g.:
+
+[source,yaml]
+----
+apiVersion: operators.coreos.com/v1alpha1
+kind: Subscription
+metadata:
+  name: camel-k
+  namespace: openshift-operators
+spec:
+  config:
+    env:
+    - name: HTTP_PROXY
+      value: ""
+    - name: NO_PROXY
+      value: ""
+----
diff --git a/docs/modules/ROOT/pages/configuration/maven.adoc b/docs/modules/ROOT/pages/configuration/maven.adoc
index d5ff11f..69a7196 100644
--- a/docs/modules/ROOT/pages/configuration/maven.adoc
+++ b/docs/modules/ROOT/pages/configuration/maven.adoc
@@ -1,5 +1,6 @@
 = Configure Maven
 
+[[maven-settings]]
 == Maven Settings
 
 The Maven settings, used by the Camel K operator, can be provided in a ConfigMap or a Secret.
@@ -114,6 +115,17 @@ WARNING: The `--maven-settings` and `--maven-repository` options are mutually ex
 
 You can find more information in the https://maven.apache.org/guides/introduction/introduction-to-repositories.html[Introduction to Repositories] from the Maven documentation.
 
+[[http-proxy]]
+== HTTP Proxy
+
+HTTP proxy can be configured on the Camel K operator Deployment, with the usual `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY` environment variables.
+
+The operator automatically configures Maven according to the values of these variables.
+
+See the xref:configuration/http-proxy.adoc[HTTP proxy] documentation for more details.
+
+The generated configuration can be overwritten in the <<maven-settings>> if necessary.
+
 [[ca-certificates]]
 == CA Certificates
 
@@ -131,6 +143,7 @@ A JKS formatted keystore is automatically created to store the CA certificate(s)
 The root CA certificates are also imported into the created keystore.
 
 The created Secret can then be referenced in the IntegrationPlatform resource, from the `spec.build.maven.caSecret` field, e.g.:
+
 [source,yaml]
 ----
 apiVersion: camel.apache.org/v1
@@ -191,12 +204,18 @@ Maven extensions are typically used to enable https://maven.apache.org/wagon/wag
 [[use-case]]
 == S3 Bucket as a Maven Repository
 
-In this section, we will show how to configure Camel K to fetch artifacts from a https://aws.amazon.com/s3/[S3] bucket that's setup as a Maven repository. We will assume that the bucket is already up and running and configured correctly. We will also assume you know how to setup Maven locally to fetch artifacts from it.
+In this section, we will show how to configure Camel K to fetch artifacts from a https://aws.amazon.com/s3/[S3] bucket that's set up as a Maven repository.
+We will assume that the bucket is already up and running and configured correctly. We will also assume you know how to set up Maven locally to fetch artifacts from it.
 
 === Custom Maven Settings
 
-The first thing that needs to be done is to create a Maven settings file configured to use the S3 bucket as a Maven repository. The Maven settings file will be used by the Camel K operator so make sure your S3 instance is accessible in your cluster. +
-The Maven settings will contain all the information needed for Maven to access the S3 bucket namely your credentials, S3 URL and bucket name. This information will typically be located in the `server` and `repository` section of your Maven settings. For example when using https://min.io/[MinIO] as a S3 provider and https://github.com/Yleisradio/aws-maven/pull/20[`fi.yle.tools:aws-maven:1.4.3`] as a Wagon Provider, your Maven settings will look something like this: 
+The first thing that needs to be done is to create a Maven settings file configured to use the S3 bucket as a Maven repository.
+The Maven settings file will be used by the Camel K operator so make sure your S3 instance is accessible in your cluster.
+
+The Maven settings will contain all the information needed for Maven to access the S3 bucket namely your credentials, S3 URL and bucket name.
+This information will typically be located in the `server` and `repository` section of your Maven settings.
+
+For example when using https://min.io/[MinIO] as a S3 provider and https://github.com/Yleisradio/aws-maven/pull/20[`fi.yle.tools:aws-maven:1.4.3`] as a Wagon Provider, your Maven settings will look something like this:
 
 [source,xml]
 ----
@@ -289,7 +308,10 @@ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.
   </profiles>
 </settings>
 ----
-Since these settings contains credentials, you will want to store it in a Kubernetes `secret`. As mentioned above, the `kubectl` CLI provides a convenient command to create a Secret from a file, e.g.:
+
+Since these settings contains credentials, you will want to store it in a Kubernetes Secret.
+As mentioned above, the `kubectl` CLI provides a convenient command to create a Secret from a file, e.g.:
+
 [source,console]
 ----
 $ kubectl create secret generic camel-k-s3-maven-settings --from-file=maven-settings=maven_settings.xml
@@ -297,8 +319,10 @@ $ kubectl create secret generic camel-k-s3-maven-settings --from-file=maven-sett
 
 === S3 TLS Certificates
 
-In most cases, you will need to add the certificate(s) served by your S3 instance to the list of certificate(s) trusted by the Camel K Operator when running Maven commands. Where/how to get the certificate(s) varies greatly depending on how your S3 instance is setup and will not be covered here. +
-Once retrieved, you should create a Kubernetes `secret` containing the certificate(s) similar to what is described in the section <<ca-certificates>>, e.g.:
+In most cases, you will need to add the certificate(s) served by your S3 instance to the list of certificate(s) trusted by the Camel K Operator when running Maven commands.
+Where/how to get the certificate(s) varies greatly depending on how your S3 instance is set up, and will not be covered here.
+Once retrieved, you should create a Kubernetes Secret containing the certificate(s) similar to what is described in the section <<ca-certificates>>, e.g.:
+
 [source,console]
 ----
 $ kubectl create secret generic s3-ca --from-file=s3-ca=ca.crt
@@ -306,13 +330,17 @@ $ kubectl create secret generic s3-ca --from-file=s3-ca=ca.crt
 
 === Maven settings, certificates and extensions
 
-We are now ready to configure the Camel K operator to use your S3 bucket as a Maven repository. This can be done while installing the Operator using the Kamel CLI, e.g:
+We are now ready to configure the Camel K operator to use your S3 bucket as a Maven repository.
+This can be done while installing the Operator using the Kamel CLI, e.g:
+
 [source,console]
 ----
 $ kamel install --maven-settings secret:camel-k-s3-maven-settings/maven-settings --maven-ca-secret s3-ca/s3-ca --maven-extension fi.yle.tools:aws-maven:1.4.3
 ----
 
-Maven dependencies hosted in your S3 bucket can now be used just like any other dependency when running an integration. For example when using the Kamel CLI using the `--dependency` option:
+Maven dependencies hosted in your S3 bucket can now be used just like any other dependency when running an integration.
+For example when using the Kamel CLI using the `--dependency` option:
+
 [source,console]
 ----
 $ kamel run S3.java --dependency=mvn:artfiactId:groupId:version

[camel-k] 06/31: feat(maven): HTTP proxy e2e tests

Posted by as...@apache.org.
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 630afe3e3bb807f7829b93fda59e1521abfe87be
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Jan 7 10:53:53 2022 +0100

    feat(maven): HTTP proxy e2e tests
---
 e2e/common/build/maven_http_proxy_test.go | 326 ++++++++++++++++++++++++++++++
 1 file changed, 326 insertions(+)

diff --git a/e2e/common/build/maven_http_proxy_test.go b/e2e/common/build/maven_http_proxy_test.go
new file mode 100644
index 0000000..ace8aa8
--- /dev/null
+++ b/e2e/common/build/maven_http_proxy_test.go
@@ -0,0 +1,326 @@
+//go:build integration
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package build
+
+import (
+	"crypto/rand"
+	"crypto/rsa"
+	"crypto/x509"
+	"crypto/x509/pkix"
+	"encoding/pem"
+	"fmt"
+	"math/big"
+	rand2 "math/rand"
+	"testing"
+	"time"
+
+	. "github.com/onsi/gomega"
+	. "github.com/onsi/gomega/gstruct"
+
+	appsv1 "k8s.io/api/apps/v1"
+	corev1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/util/intstr"
+
+	. "github.com/apache/camel-k/e2e/support"
+	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+)
+
+func TestMavenProxy(t *testing.T) {
+	WithNewTestNamespace(t, func(ns string) {
+		hostname := fmt.Sprintf("%s.%s.svc", "proxy", ns)
+		tlsMountPath := "/etc/tls/private"
+
+		// Generate the TLS certificate
+		serialNumber := big.NewInt(rand2.Int63())
+		cert := &x509.Certificate{
+			SerialNumber: serialNumber,
+			Subject: pkix.Name{
+				Organization: []string{"Camel K test"},
+			},
+			DNSNames:              []string{hostname},
+			NotBefore:             time.Now(),
+			NotAfter:              time.Now().AddDate(1, 0, 0),
+			ExtKeyUsage:           []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
+			KeyUsage:              x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
+			BasicConstraintsValid: true,
+		}
+
+		// generate the certificate private key
+		certPrivateKey, err := rsa.GenerateKey(rand.Reader, 2048)
+		Expect(err).To(BeNil())
+
+		privateKeyBytes := x509.MarshalPKCS1PrivateKey(certPrivateKey)
+		// encode for storing into a Secret
+		privateKeyPem := pem.EncodeToMemory(
+			&pem.Block{
+				Type:  "RSA PRIVATE KEY",
+				Bytes: privateKeyBytes,
+			},
+		)
+		certBytes, err := x509.CreateCertificate(rand.Reader, cert, cert, &certPrivateKey.PublicKey, certPrivateKey)
+		Expect(err).To(BeNil())
+
+		// encode for storing into a Secret
+		certPem := pem.EncodeToMemory(&pem.Block{
+			Type:  "CERTIFICATE",
+			Bytes: certBytes,
+		})
+
+		secret := &corev1.Secret{
+			TypeMeta: metav1.TypeMeta{
+				Kind:       "Secret",
+				APIVersion: corev1.SchemeGroupVersion.String(),
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: ns,
+				Name:      "tls-secret",
+			},
+			Type: corev1.SecretTypeTLS,
+			Data: map[string][]byte{
+				corev1.TLSCertKey:       certPem,
+				corev1.TLSPrivateKeyKey: privateKeyPem,
+			},
+		}
+		Expect(TestClient().Create(TestContext, secret)).To(Succeed())
+
+		// HTTPD configuration
+		config := &corev1.ConfigMap{
+			TypeMeta: metav1.TypeMeta{
+				Kind:       "ConfigMap",
+				APIVersion: corev1.SchemeGroupVersion.String(),
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: ns,
+				Name:      "httpd-config",
+			},
+			Data: map[string]string{
+				"httpd.conf": fmt.Sprintf(`
+ServerRoot "/etc/httpd
+
+PidFile /var/run/httpd/httpd.pid"
+
+LoadModule mpm_event_module /usr/local/apache2/modules/mod_mpm_event.so
+LoadModule authn_core_module /usr/local/apache2/modules/mod_authn_core.so
+LoadModule authz_core_module /usr/local/apache2/modules/mod_authz_core.so
+LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
+LoadModule proxy_http_module /usr/local/apache2/modules/mod_proxy_http.so
+LoadModule proxy_connect_module /usr/local/apache2/modules/mod_proxy_connect.so
+LoadModule headers_module /usr/local/apache2/modules/mod_headers.so
+LoadModule setenvif_module /usr/local/apache2/modules/mod_setenvif.so
+LoadModule version_module /usr/local/apache2/modules/mod_version.so
+LoadModule log_config_module /usr/local/apache2/modules/mod_log_config.so
+LoadModule env_module /usr/local/apache2/modules/mod_env.so
+LoadModule unixd_module /usr/local/apache2/modules/mod_unixd.so
+LoadModule status_module /usr/local/apache2/modules/mod_status.so
+LoadModule autoindex_module /usr/local/apache2/modules/mod_autoindex.so
+LoadModule ssl_module /usr/local/apache2/modules/mod_ssl.so
+
+Mutex posixsem
+
+LogFormat "%%h %%l %%u %%t \"%%r\" %%>s %%b" common
+CustomLog /dev/stdout common
+ErrorLog /dev/stderr
+
+LogLevel warn
+
+Listen 8080
+Listen 8443
+
+ServerName %s
+
+ProxyRequests On
+ProxyVia Off
+
+<VirtualHost *:8443>
+  SSLEngine on
+
+  SSLCertificateFile "%s/%s"
+  SSLCertificateKeyFile "%s/%s"
+
+  AllowEncodedSlashes NoDecode
+</VirtualHost>
+`,
+					hostname, tlsMountPath, corev1.TLSCertKey, tlsMountPath, corev1.TLSPrivateKeyKey,
+				),
+			},
+		}
+		Expect(TestClient().Create(TestContext, config)).To(Succeed())
+
+		// Deploy HTTPD
+		// $ curl --proxy-cacert ca.crt --proxy https://proxy.http-proxy.svc:443 https://www.google.com
+		// https://github.com/curl/curl/pull/1127
+		deployment := &appsv1.Deployment{
+			TypeMeta: metav1.TypeMeta{
+				Kind:       "Deployment",
+				APIVersion: appsv1.SchemeGroupVersion.String(),
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: ns,
+				Name:      "proxy",
+			},
+			Spec: appsv1.DeploymentSpec{
+				Selector: &metav1.LabelSelector{
+					MatchLabels: map[string]string{
+						"app": "proxy",
+					},
+				},
+				Template: corev1.PodTemplateSpec{
+					ObjectMeta: metav1.ObjectMeta{
+						Labels: map[string]string{
+							"app": "proxy",
+						},
+					},
+					Spec: corev1.PodSpec{
+						Containers: []corev1.Container{
+							{
+								Name:    "httpd",
+								Image:   "httpd:2.4.46",
+								Command: []string{"httpd", "-f", "/etc/httpd/httpd.conf", "-DFOREGROUND"},
+								Ports: []corev1.ContainerPort{
+									{
+										Name:          "http",
+										ContainerPort: 8080,
+									},
+									{
+										Name:          "https",
+										ContainerPort: 8443,
+									},
+								},
+								VolumeMounts: []corev1.VolumeMount{
+									{
+										Name:      "tls",
+										MountPath: tlsMountPath,
+										ReadOnly:  true,
+									},
+									{
+										Name:      "httpd-conf",
+										MountPath: "/etc/httpd",
+										ReadOnly:  true,
+									},
+									{
+										Name:      "httpd-run",
+										MountPath: "/var/run/httpd",
+									},
+								},
+							},
+						},
+						Volumes: []corev1.Volume{
+							{
+								Name: "tls",
+								VolumeSource: corev1.VolumeSource{
+									Secret: &corev1.SecretVolumeSource{
+										SecretName: secret.Name,
+									},
+								},
+							},
+							{
+								Name: "httpd-conf",
+								VolumeSource: corev1.VolumeSource{
+									ConfigMap: &corev1.ConfigMapVolumeSource{
+										LocalObjectReference: corev1.LocalObjectReference{
+											Name: config.Name,
+										},
+									},
+								},
+							},
+							{
+								Name: "httpd-run",
+								VolumeSource: corev1.VolumeSource{
+									EmptyDir: &corev1.EmptyDirVolumeSource{},
+								},
+							},
+						},
+					},
+				},
+			},
+		}
+		Expect(TestClient().Create(TestContext, deployment)).To(Succeed())
+
+		service := &corev1.Service{
+			TypeMeta: metav1.TypeMeta{
+				Kind:       "Service",
+				APIVersion: corev1.SchemeGroupVersion.String(),
+			},
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: ns,
+				Name:      deployment.Name,
+			},
+			Spec: corev1.ServiceSpec{
+				Selector: deployment.Spec.Template.Labels,
+				Ports: []corev1.ServicePort{
+					{
+						Name:       "http",
+						Port:       80,
+						TargetPort: intstr.FromString("http"),
+					},
+					{
+						Name:       "https",
+						Port:       443,
+						TargetPort: intstr.FromString("https"),
+					},
+				},
+			},
+		}
+		Expect(TestClient().Create(TestContext, service)).To(Succeed())
+
+		// Wait for the Deployment to become ready
+		Eventually(Deployment(ns, deployment.Name), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras,
+			Fields{
+				"Status": MatchFields(IgnoreExtras,
+					Fields{
+						"ReadyReplicas": Equal(int32(1)),
+					}),
+			}),
+		))
+
+		// Install Camel K with the HTTP proxy
+		Expect(Kamel("install", "-n", ns,
+			"--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://%s", hostname),
+			// FIXME: TLS handshake issue
+			// "--operator-env-vars", fmt.Sprintf("HTTPS_PROXY=https://%s", hostname),
+			// "--maven-ca-secret", secret.Name+"/"+corev1.TLSCertKey,
+			// FIXME: use the cluster network CIDR
+			"--operator-env-vars", "NO_PROXY=.cluster.local,.svc,10.0.0.0/16,127.0.0.1,172.17.0.0/18,172.21.0.0/16",
+		).Execute()).To(Succeed())
+
+		Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))
+
+		// Run the Integration
+		name := "java"
+		Expect(Kamel("run", "-n", ns, "files/Java.java", "--name", name).Execute()).To(Succeed())
+
+		Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
+		Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+		Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+
+		// TODO: assert the proxy logs
+
+		// Clean up
+		Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+		Expect(TestClient().Delete(TestContext, deployment)).To(Succeed())
+		Expect(TestClient().Delete(TestContext, service)).To(Succeed())
+		Expect(TestClient().Delete(TestContext, secret)).To(Succeed())
+		Expect(TestClient().Delete(TestContext, config)).To(Succeed())
+	})
+}

[camel-k] 10/31: chore(maven): Separate user and platform Maven settings

Posted by as...@apache.org.
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 ebcc70c2c453b367b1c4a0b5787eba9211b54ecc
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Jan 7 17:49:54 2022 +0100

    chore(maven): Separate user and platform Maven settings
---
 pkg/cmd/install.go                                 | 78 ++++++++++++++++++++--
 .../integrationplatform/initialize_test.go         | 26 --------
 pkg/platform/defaults.go                           | 74 --------------------
 pkg/trait/builder.go                               |  5 +-
 4 files changed, 77 insertions(+), 106 deletions(-)

diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index 1921a2c..0f1225c 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -18,27 +18,33 @@ limitations under the License.
 package cmd
 
 import (
+	"context"
 	"fmt"
 	"os"
 	"regexp"
 	"strings"
 	"time"
 
-	"go.uber.org/multierr"
-
 	"github.com/pkg/errors"
 	"github.com/spf13/cobra"
 	"github.com/spf13/viper"
 
+	"go.uber.org/multierr"
+
 	corev1 "k8s.io/api/core/v1"
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/types"
+
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/client"
 	"github.com/apache/camel-k/pkg/install"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/maven"
 	"github.com/apache/camel-k/pkg/util/olm"
+	"github.com/apache/camel-k/pkg/util/patch"
 	"github.com/apache/camel-k/pkg/util/registry"
 	"github.com/apache/camel-k/pkg/util/watch"
 )
@@ -383,8 +389,37 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 		}
 
 		if len(o.MavenRepositories) > 0 {
-			for _, r := range o.MavenRepositories {
-				platform.AddConfiguration("repository", r)
+			var repositories []v1.Repository
+			var mirrors []maven.Mirror
+
+			for i, r := range o.MavenRepositories {
+				if strings.Contains(r, "@mirrorOf=") {
+					mirror := maven.NewMirror(r)
+					if mirror.ID == "" {
+						mirror.ID = fmt.Sprintf("mirror-%03d", i)
+					}
+					mirrors = append(mirrors, mirror)
+				} else {
+					repository := maven.NewRepository(r)
+					if repository.ID == "" {
+						repository.ID = fmt.Sprintf("repository-%03d", i)
+					}
+					repositories = append(repositories, repository)
+				}
+			}
+
+			settings := maven.NewDefaultSettings(repositories, mirrors)
+
+			err := createDefaultMavenSettingsConfigMap(o.Context, c, namespace, platform.Name, settings)
+			if err != nil {
+				return err
+			}
+
+			platform.Spec.Build.Maven.Settings.ConfigMapKeyRef = &corev1.ConfigMapKeySelector{
+				LocalObjectReference: corev1.LocalObjectReference{
+					Name: platform.Name + "-maven-settings",
+				},
+				Key: "settings.xml",
 			}
 		}
 
@@ -675,3 +710,38 @@ func decodeSecretKeySelector(secretKey string) (*corev1.SecretKeySelector, error
 		Key: match[2],
 	}, nil
 }
+
+func createDefaultMavenSettingsConfigMap(ctx context.Context, client client.Client, namespace, name string, settings maven.Settings) error {
+	cm, err := maven.SettingsConfigMap(namespace, name, settings)
+	if err != nil {
+		return err
+	}
+
+	err = client.Create(ctx, cm)
+	if err != nil && !k8serrors.IsAlreadyExists(err) {
+		return err
+	} else if k8serrors.IsAlreadyExists(err) {
+		existing := &corev1.ConfigMap{
+			ObjectMeta: metav1.ObjectMeta{
+				Namespace: cm.Namespace,
+				Name:      cm.Name,
+			},
+		}
+		err = client.Get(ctx, ctrl.ObjectKeyFromObject(existing), existing)
+		if err != nil {
+			return err
+		}
+
+		p, err := patch.PositiveMergePatch(existing, cm)
+		if err != nil {
+			return err
+		} else if len(p) != 0 {
+			err = client.Patch(ctx, cm, ctrl.RawPatch(types.MergePatchType, p))
+			if err != nil {
+				return errors.Wrap(err, "error during patch resource")
+			}
+		}
+	}
+
+	return nil
+}
diff --git a/pkg/controller/integrationplatform/initialize_test.go b/pkg/controller/integrationplatform/initialize_test.go
index 4c7aa12..a718b12 100644
--- a/pkg/controller/integrationplatform/initialize_test.go
+++ b/pkg/controller/integrationplatform/initialize_test.go
@@ -115,29 +115,3 @@ func TestTimeouts_Truncated(t *testing.T) {
 
 	assert.Equal(t, 5*time.Minute, answer.Status.Build.GetTimeout().Duration)
 }
-
-func TestDefaultMavenSettingsApplied(t *testing.T) {
-	ip := v1.IntegrationPlatform{}
-	ip.Namespace = "ns"
-	ip.Name = "test-platform"
-	ip.Spec.Cluster = v1.IntegrationPlatformClusterOpenShift
-	ip.Spec.Profile = v1.TraitProfileOpenShift
-
-	c, err := test.NewFakeClient(&ip)
-	assert.Nil(t, err)
-
-	assert.Nil(t, platform.ConfigureDefaults(context.TODO(), c, &ip, false))
-
-	h := NewInitializeAction()
-	h.InjectLogger(log.Log)
-	h.InjectClient(c)
-
-	answer, err := h.Handle(context.TODO(), &ip)
-	assert.Nil(t, err)
-	assert.NotNil(t, answer)
-
-	assert.NotNil(t, answer.Status.Build.Maven.Settings.ConfigMapKeyRef)
-	assert.Nil(t, answer.Spec.Build.Maven.Settings.ConfigMapKeyRef)
-	assert.Equal(t, "test-platform-maven-settings", answer.Status.Build.Maven.Settings.ConfigMapKeyRef.Name)
-	assert.Equal(t, "settings.xml", answer.Status.Build.Maven.Settings.ConfigMapKeyRef.Key)
-}
diff --git a/pkg/platform/defaults.go b/pkg/platform/defaults.go
index 45bc09a..8355b32 100644
--- a/pkg/platform/defaults.go
+++ b/pkg/platform/defaults.go
@@ -19,7 +19,6 @@ package platform
 
 import (
 	"context"
-	"fmt"
 	"runtime"
 	"strings"
 	"time"
@@ -40,9 +39,7 @@ import (
 	"github.com/apache/camel-k/pkg/kamelet/repository"
 	"github.com/apache/camel-k/pkg/util/defaults"
 	"github.com/apache/camel-k/pkg/util/log"
-	"github.com/apache/camel-k/pkg/util/maven"
 	"github.com/apache/camel-k/pkg/util/openshift"
-	"github.com/apache/camel-k/pkg/util/patch"
 )
 
 // BuilderServiceAccount --.
@@ -186,42 +183,6 @@ func setPlatformDefaults(ctx context.Context, c client.Client, p *v1.Integration
 		}
 	}
 
-	if p.Status.Build.Maven.Settings.ConfigMapKeyRef == nil && p.Status.Build.Maven.Settings.SecretKeyRef == nil {
-		var repositories []v1.Repository
-		var mirrors []maven.Mirror
-		for i, c := range p.Status.Configuration {
-			if c.Type == "repository" {
-				if strings.Contains(c.Value, "@mirrorOf=") {
-					mirror := maven.NewMirror(c.Value)
-					if mirror.ID == "" {
-						mirror.ID = fmt.Sprintf("mirror-%03d", i)
-					}
-					mirrors = append(mirrors, mirror)
-				} else {
-					repo := maven.NewRepository(c.Value)
-					if repo.ID == "" {
-						repo.ID = fmt.Sprintf("repository-%03d", i)
-					}
-					repositories = append(repositories, repo)
-				}
-			}
-		}
-
-		settings := maven.NewDefaultSettings(repositories, mirrors)
-
-		err := createDefaultMavenSettingsConfigMap(ctx, c, p, settings)
-		if err != nil {
-			return err
-		}
-
-		p.Status.Build.Maven.Settings.ConfigMapKeyRef = &corev1.ConfigMapKeySelector{
-			LocalObjectReference: corev1.LocalObjectReference{
-				Name: p.Name + "-maven-settings",
-			},
-			Key: "settings.xml",
-		}
-	}
-
 	if p.Status.Build.PublishStrategy == v1.IntegrationPlatformBuildPublishStrategyKaniko && p.Status.Build.KanikoBuildCache == nil {
 		// Default to disabling Kaniko cache warmer
 		// Using the cache warmer pod seems unreliable with the current Kaniko version
@@ -262,41 +223,6 @@ func setStatusAdditionalInfo(platform *v1.IntegrationPlatform) {
 	platform.Status.Info["gitCommit"] = defaults.GitCommit
 }
 
-func createDefaultMavenSettingsConfigMap(ctx context.Context, client client.Client, p *v1.IntegrationPlatform, settings maven.Settings) error {
-	cm, err := maven.SettingsConfigMap(p.Namespace, p.Name, settings)
-	if err != nil {
-		return err
-	}
-
-	err = client.Create(ctx, cm)
-	if err != nil && !k8serrors.IsAlreadyExists(err) {
-		return err
-	} else if k8serrors.IsAlreadyExists(err) {
-		existing := &corev1.ConfigMap{
-			ObjectMeta: metav1.ObjectMeta{
-				Namespace: cm.Namespace,
-				Name:      cm.Name,
-			},
-		}
-		err = client.Get(ctx, ctrl.ObjectKeyFromObject(existing), existing)
-		if err != nil {
-			return err
-		}
-
-		p, err := patch.PositiveMergePatch(existing, cm)
-		if err != nil {
-			return err
-		} else if len(p) != 0 {
-			err = client.Patch(ctx, cm, ctrl.RawPatch(types.MergePatchType, p))
-			if err != nil {
-				return errors.Wrap(err, "error during patch resource")
-			}
-		}
-	}
-
-	return nil
-}
-
 func createServiceCaBundleConfigMap(ctx context.Context, client client.Client, p *v1.IntegrationPlatform) (*corev1.ConfigMap, error) {
 	cm := &corev1.ConfigMap{
 		ObjectMeta: metav1.ObjectMeta{
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index e14f282..22f970d 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -135,8 +135,9 @@ func (t *builderTrait) Apply(e *Environment) error {
 }
 
 func (t *builderTrait) builderTask(e *Environment) (*v1.BuilderTask, error) {
-	maven := e.Platform.Status.Build.Maven
-
+	maven := v1.MavenBuildSpec{
+		MavenSpec: e.Platform.Status.Build.Maven,
+	}
 	// Add Maven repositories defined in the IntegrationKit
 	for _, repo := range e.IntegrationKit.Spec.Repositories {
 		maven.Repositories = append(maven.Repositories, mvn.NewRepository(repo))

[camel-k] 17/31: feat(jvm): Translate HTTP proxy env variables into system properties

Posted by as...@apache.org.
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 da18313671286ee2c39a9d4fef7cf26aba9e708e
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 10 12:51:34 2022 +0100

    feat(jvm): Translate HTTP proxy env variables into system properties
---
 pkg/trait/jvm.go | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 994a532..306a068 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -19,6 +19,7 @@ package trait
 
 import (
 	"fmt"
+	"net/url"
 	"path"
 	"sort"
 	"strings"
@@ -38,6 +39,7 @@ import (
 	"github.com/apache/camel-k/pkg/builder"
 	"github.com/apache/camel-k/pkg/util"
 	"github.com/apache/camel-k/pkg/util/camel"
+	"github.com/apache/camel-k/pkg/util/envvar"
 )
 
 // The JVM trait is used to configure the JVM that runs the integration.
@@ -169,6 +171,59 @@ func (t *jvmTrait) Apply(e *Environment) error {
 		args = append(args, t.Options...)
 	}
 
+	// Translate HTTP proxy environment variables, that are set by the environment trait,
+	// into corresponding JVM system properties.
+	if HTTPProxy := envvar.Get(container.Env, "HTTP_PROXY"); HTTPProxy != nil {
+		u, err := url.Parse(HTTPProxy.Value)
+		if err != nil {
+			return err
+		}
+		if !util.StringSliceContainsAnyOf(t.Options, "http.proxyHost") {
+			args = append(args, "-Dhttp.proxyHost="+u.Hostname())
+		}
+		if !util.StringSliceContainsAnyOf(t.Options, "http.proxyPort") {
+			args = append(args, "-Dhttp.proxyPort="+u.Port())
+		}
+		if user := u.User; !util.StringSliceContainsAnyOf(t.Options, "http.proxyUser") && user != nil {
+			args = append(args, "-Dhttp.proxyUser="+user.Username())
+			if password, ok := user.Password(); !util.StringSliceContainsAnyOf(t.Options, "http.proxyUser") && ok {
+				args = append(args, "-Dhttp.proxyPassword="+password)
+			}
+		}
+	}
+
+	if HTTPSProxy := envvar.Get(container.Env, "HTTPS_PROXY"); HTTPSProxy != nil {
+		u, err := url.Parse(HTTPSProxy.Value)
+		if err != nil {
+			return err
+		}
+		if !util.StringSliceContainsAnyOf(t.Options, "https.proxyHost") {
+			args = append(args, "-Dhttps.proxyHost="+u.Hostname())
+		}
+		if !util.StringSliceContainsAnyOf(t.Options, "https.proxyPort") {
+			args = append(args, "-Dhttps.proxyPort="+u.Port())
+		}
+		if user := u.User; !util.StringSliceContainsAnyOf(t.Options, "https.proxyUser") && user != nil {
+			args = append(args, "-Dhttps.proxyUser="+user.Username())
+			if password, ok := user.Password(); !util.StringSliceContainsAnyOf(t.Options, "https.proxyUser") && ok {
+				args = append(args, "-Dhttps.proxyPassword="+password)
+			}
+		}
+	}
+
+	if noProxy := envvar.Get(container.Env, "NO_PROXY"); noProxy != nil {
+		if !util.StringSliceContainsAnyOf(t.Options, "http.nonProxyHosts") {
+			// Convert to the format expected by the JVM http.nonProxyHosts system property
+			hosts := strings.Split(strings.ReplaceAll(noProxy.Value, " ", ""), ",")
+			for i, host := range hosts {
+				if strings.HasPrefix(host, ".") {
+					hosts[i] = strings.Replace(host, ".", "*.", 1)
+				}
+			}
+			args = append(args, "-Dhttps.nonProxyHosts="+strings.Join(hosts, "|"))
+		}
+	}
+
 	// Tune JVM maximum heap size based on the container memory limit, if any.
 	// This is configured off-container, thus is limited to explicit user configuration.
 	// We may want to inject a wrapper script into the container image, so that it can
@@ -191,8 +246,8 @@ func (t *jvmTrait) Apply(e *Environment) error {
 	items := classpath.List()
 	// Keep class path sorted so that it's consistent over reconciliation cycles
 	sort.Strings(items)
-
 	args = append(args, "-cp", strings.Join(items, ":"))
+
 	args = append(args, e.CamelCatalog.Runtime.ApplicationClass)
 
 	if IsNilOrTrue(t.PrintCommand) {

[camel-k] 25/31: fix(e2e): assert downward API in environment trait tests

Posted by as...@apache.org.
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 39205920ad8a9d493e2e455c2f286c15f7bff345
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 11 13:24:48 2022 +0100

    fix(e2e): assert downward API in environment trait tests
---
 e2e/common/traits/environment_test.go | 39 ++++++++++++++++++++++++++++++++---
 1 file changed, 36 insertions(+), 3 deletions(-)

diff --git a/e2e/common/traits/environment_test.go b/e2e/common/traits/environment_test.go
index d17bc5a..efd1ad2 100644
--- a/e2e/common/traits/environment_test.go
+++ b/e2e/common/traits/environment_test.go
@@ -76,7 +76,18 @@ func TestEnvironmentTrait(t *testing.T) {
 
 			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
 				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
-				ContainElement(corev1.EnvVar{Name: "NAMESPACE", Value: ns}),
+				ContainElement(corev1.EnvVar{Name: "NAMESPACE", ValueFrom: &corev1.EnvVarSource{
+					FieldRef: &corev1.ObjectFieldSelector{
+						APIVersion: "v1",
+						FieldPath:  "metadata.namespace",
+					},
+				}}),
+				ContainElement(corev1.EnvVar{Name: "POD_NAME", ValueFrom: &corev1.EnvVarSource{
+					FieldRef: &corev1.ObjectFieldSelector{
+						APIVersion: "v1",
+						FieldPath:  "metadata.name",
+					},
+				}}),
 				ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: httpProxy}),
 				ContainElement(corev1.EnvVar{Name: "NO_PROXY", Value: strings.Join(noProxy, ",")}),
 			)))
@@ -92,7 +103,18 @@ func TestEnvironmentTrait(t *testing.T) {
 
 			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
 				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
-				ContainElement(corev1.EnvVar{Name: "NAMESPACE", Value: ns}),
+				ContainElement(corev1.EnvVar{Name: "NAMESPACE", ValueFrom: &corev1.EnvVarSource{
+					FieldRef: &corev1.ObjectFieldSelector{
+						APIVersion: "v1",
+						FieldPath:  "metadata.namespace",
+					},
+				}}),
+				ContainElement(corev1.EnvVar{Name: "POD_NAME", ValueFrom: &corev1.EnvVarSource{
+					FieldRef: &corev1.ObjectFieldSelector{
+						APIVersion: "v1",
+						FieldPath:  "metadata.name",
+					},
+				}}),
 				ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: "http://custom.proxy"}),
 				ContainElement(corev1.EnvVar{Name: "NO_PROXY", Value: strings.Join(noProxy, ",")}),
 			)))
@@ -108,7 +130,18 @@ func TestEnvironmentTrait(t *testing.T) {
 
 			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
 				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
-				ContainElement(corev1.EnvVar{Name: "NAMESPACE", Value: ns}),
+				ContainElement(corev1.EnvVar{Name: "NAMESPACE", ValueFrom: &corev1.EnvVarSource{
+					FieldRef: &corev1.ObjectFieldSelector{
+						APIVersion: "v1",
+						FieldPath:  "metadata.namespace",
+					},
+				}}),
+				ContainElement(corev1.EnvVar{Name: "POD_NAME", ValueFrom: &corev1.EnvVarSource{
+					FieldRef: &corev1.ObjectFieldSelector{
+						APIVersion: "v1",
+						FieldPath:  "metadata.name",
+					},
+				}}),
 				Not(ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: httpProxy})),
 				Not(ContainElement(corev1.EnvVar{Name: "NO_PROXY", Value: strings.Join(noProxy, ",")})),
 			)))

[camel-k] 04/31: chore(maven): Set Maven proxy ID in global settings

Posted by as...@apache.org.
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 66907864f809ee71af73fb99ae74ac3a14b70b85
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Jan 7 09:51:40 2022 +0100

    chore(maven): Set Maven proxy ID in global settings
---
 pkg/util/maven/maven_proxies.go | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/pkg/util/maven/maven_proxies.go b/pkg/util/maven/maven_proxies.go
index abb8a91..94091a8 100644
--- a/pkg/util/maven/maven_proxies.go
+++ b/pkg/util/maven/maven_proxies.go
@@ -58,11 +58,15 @@ func parseProxyFromEnvVar(proxyEnvVar string) (Proxy, error) {
 		Host:     u.Hostname(),
 		Port:     u.Port(),
 	}
-	if proxy.Port == "" {
-		switch proxy.Protocol {
-		case "http":
+	switch proxy.Protocol {
+	case "http":
+		proxy.ID = "http-proxy"
+		if proxy.Port == "" {
 			proxy.Port = "80"
-		case "https":
+		}
+	case "https":
+		proxy.ID = "https-proxy"
+		if proxy.Port == "" {
 			proxy.Port = "443"
 		}
 	}

[camel-k] 23/31: fix(e2e): Add container registry to NO_PROXY

Posted by as...@apache.org.
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 f77b55362b894143b7326c2ca955fba0b1298bec
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 11 09:27:13 2022 +0100

    fix(e2e): Add container registry to NO_PROXY
---
 e2e/common/traits/environment_test.go |  26 ++++++--
 e2e/support/regexp.go                 | 119 ++++++++++++++++++++++++++++++++++
 2 files changed, 138 insertions(+), 7 deletions(-)

diff --git a/e2e/common/traits/environment_test.go b/e2e/common/traits/environment_test.go
index 57c0201..d17bc5a 100644
--- a/e2e/common/traits/environment_test.go
+++ b/e2e/common/traits/environment_test.go
@@ -24,6 +24,7 @@ package traits
 
 import (
 	"fmt"
+	"os"
 	"strings"
 	"testing"
 
@@ -38,21 +39,32 @@ import (
 
 func TestEnvironmentTrait(t *testing.T) {
 	WithNewTestNamespace(t, func(ns string) {
-		// Retrieve the Kubernetes Service ClusterIPs to populate the NO_PROXY environment variable
-		svc := Service("default", "kubernetes")()
-		Expect(svc).NotTo(BeNil())
-
+		// HTTP proxy configuration
+		httpProxy := "http://proxy"
 		noProxy := []string{
 			".cluster.local",
 			".svc",
 			"localhost",
 			".apache.org",
 		}
+
+		// Retrieve the Kubernetes Service ClusterIPs to populate the NO_PROXY environment variable
+		svc := Service("default", "kubernetes")()
+		Expect(svc).NotTo(BeNil())
+
 		noProxy = append(noProxy, svc.Spec.ClusterIPs...)
 
+		// Retrieve the internal container registry to populate the NO_PROXY environment variable
+		if registry, ok := os.LookupEnv("KAMEL_INSTALL_REGISTRY"); ok {
+			domain := RegistryRegexp.FindString(registry)
+			Expect(domain).NotTo(BeNil())
+			domain = strings.Split(domain, ":")[0]
+			noProxy = append(noProxy, domain)
+		}
+
 		// Install Camel K with the HTTP proxy environment variable
 		Expect(Kamel("install", "-n", ns,
-			"--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://proxy"),
+			"--operator-env-vars", fmt.Sprintf("HTTP_PROXY=%s", httpProxy),
 			"--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","),
 		).Execute()).To(Succeed())
 
@@ -65,7 +77,7 @@ func TestEnvironmentTrait(t *testing.T) {
 			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
 				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
 				ContainElement(corev1.EnvVar{Name: "NAMESPACE", Value: ns}),
-				ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: "http://proxy"}),
+				ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: httpProxy}),
 				ContainElement(corev1.EnvVar{Name: "NO_PROXY", Value: strings.Join(noProxy, ",")}),
 			)))
 		})
@@ -97,7 +109,7 @@ func TestEnvironmentTrait(t *testing.T) {
 			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
 				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
 				ContainElement(corev1.EnvVar{Name: "NAMESPACE", Value: ns}),
-				Not(ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: "http://proxy"})),
+				Not(ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: httpProxy})),
 				Not(ContainElement(corev1.EnvVar{Name: "NO_PROXY", Value: strings.Join(noProxy, ",")})),
 			)))
 		})
diff --git a/e2e/support/regexp.go b/e2e/support/regexp.go
new file mode 100644
index 0000000..ba44168
--- /dev/null
+++ b/e2e/support/regexp.go
@@ -0,0 +1,119 @@
+//go:build integration
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package support
+
+import "regexp"
+
+var (
+	// alphaNumericRegexp defines the alpha numeric atom, typically a
+	// component of names. This only allows lower case characters and digits.
+	alphaNumericRegexp = match(`[a-z0-9]+`)
+
+	// separatorRegexp defines the separators allowed to be embedded in name
+	// components. This allow one period, one or two underscore and multiple
+	// dashes.
+	separatorRegexp = match(`(?:[._]|__|[-]*)`)
+
+	// nameComponentRegexp restricts registry path component names to start
+	// with at least one letter or number, with following parts able to be
+	// separated by one period, one or two underscore and multiple dashes.
+	nameComponentRegexp = expression(
+		alphaNumericRegexp,
+		optional(repeated(separatorRegexp, alphaNumericRegexp)))
+
+	// domainComponentRegexp restricts the registry domain component of a
+	// repository name to start with a component as defined by DomainRegexp
+	// and followed by an optional port.
+	domainComponentRegexp = match(`(?:[a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])`)
+
+	// DomainRegexp defines the structure of potential domain components
+	// that may be part of image names. This is purposely a subset of what is
+	// allowed by DNS to ensure backwards compatibility with Docker image
+	// names.
+	DomainRegexp = expression(
+		domainComponentRegexp,
+		optional(repeated(literal(`.`), domainComponentRegexp)),
+		optional(literal(`:`), match(`[0-9]+`)))
+
+	RegistryRegexp = anchored(
+		capture(DomainRegexp),
+		optional(
+			literal(`/`),
+			nameComponentRegexp,
+			optional(repeated(literal(`/`), nameComponentRegexp)),
+		),
+	)
+)
+
+// match compiles the string to a regular expression.
+var match = regexp.MustCompile
+
+// literal compiles s into a literal regular expression, escaping any regexp
+// reserved characters.
+func literal(s string) *regexp.Regexp {
+	re := match(regexp.QuoteMeta(s))
+
+	if _, complete := re.LiteralPrefix(); !complete {
+		panic("must be a literal")
+	}
+
+	return re
+}
+
+// expression defines a full expression, where each regular expression must
+// follow the previous.
+func expression(res ...*regexp.Regexp) *regexp.Regexp {
+	var s string
+	for _, re := range res {
+		s += re.String()
+	}
+
+	return match(s)
+}
+
+// optional wraps the expression in a non-capturing group and makes the
+// production optional.
+func optional(res ...*regexp.Regexp) *regexp.Regexp {
+	return match(group(expression(res...)).String() + `?`)
+}
+
+// repeated wraps the regexp in a non-capturing group to get one or more
+// matches.
+func repeated(res ...*regexp.Regexp) *regexp.Regexp {
+	return match(group(expression(res...)).String() + `+`)
+}
+
+// group wraps the regexp in a non-capturing group.
+func group(res ...*regexp.Regexp) *regexp.Regexp {
+	return match(`(?:` + expression(res...).String() + `)`)
+}
+
+// capture wraps the expression in a capturing group.
+func capture(res ...*regexp.Regexp) *regexp.Regexp {
+	return match(`(` + expression(res...).String() + `)`)
+}
+
+// anchored anchors the regular expression by adding start and end delimiters.
+func anchored(res ...*regexp.Regexp) *regexp.Regexp {
+	return match(`^` + expression(res...).String() + `$`)
+}

[camel-k] 09/31: chore(maven): Add default Maven repositories to global settings

Posted by as...@apache.org.
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 92259fbb97cd97248425b044e039f64d94bd72bc
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Jan 7 17:10:54 2022 +0100

    chore(maven): Add default Maven repositories to global settings
---
 pkg/builder/project.go               |  2 +-
 pkg/trait/openapi.go                 |  2 +-
 pkg/util/camel/catalog.go            |  2 +-
 pkg/util/maven/maven_repositories.go | 53 ++++++++++++++++++++++++++++++++++++
 pkg/util/maven/maven_settings.go     | 34 +++++++++++------------
 5 files changed, 73 insertions(+), 20 deletions(-)

diff --git a/pkg/builder/project.go b/pkg/builder/project.go
index 06de5ed..35a897a 100644
--- a/pkg/builder/project.go
+++ b/pkg/builder/project.go
@@ -94,7 +94,7 @@ func generateProjectSettings(ctx *builderContext) error {
 		ctx.Maven.UserSettings = []byte(val)
 	}
 
-	settings, err := maven.NewSettings(maven.ProxyFromEnvironment)
+	settings, err := maven.NewSettings(maven.DefaultRepositories, maven.ProxyFromEnvironment)
 	if err != nil {
 		return err
 	}
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index bc262b7..5cc3d4f 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -262,7 +262,7 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Dat
 		mc.UserSettings = []byte(settings)
 	}
 
-	if settings, err := maven.NewSettings(maven.ProxyFromEnvironment); err != nil {
+	if settings, err := maven.NewSettings(maven.DefaultRepositories, maven.ProxyFromEnvironment); err != nil {
 		return err
 	} else {
 		data, err := settings.MarshalBytes()
diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go
index ad05456..5fff813 100644
--- a/pkg/util/camel/catalog.go
+++ b/pkg/util/camel/catalog.go
@@ -84,7 +84,7 @@ func GenerateCatalog(
 	if err != nil {
 		return nil, err
 	}
-	settings, err := maven.NewSettings(maven.ProxyFromEnvironment)
+	settings, err := maven.NewSettings(maven.DefaultRepositories, maven.ProxyFromEnvironment)
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/util/maven/maven_repositories.go b/pkg/util/maven/maven_repositories.go
new file mode 100644
index 0000000..2576cbb
--- /dev/null
+++ b/pkg/util/maven/maven_repositories.go
@@ -0,0 +1,53 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package maven
+
+import (
+	"strings"
+
+	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+)
+
+var DefaultRepositories = &defaultRepositories{}
+
+type defaultRepositories struct{}
+
+func (o defaultRepositories) apply(settings *Settings) error {
+	for _, repository := range defaultMavenRepositories() {
+		upsertRepository(repository, &settings.Profiles[0].Repositories)
+		upsertRepository(repository, &settings.Profiles[0].PluginRepositories)
+	}
+	return nil
+}
+
+func defaultMavenRepositories() (repositories []v1.Repository) {
+	for _, repository := range strings.Split(DefaultMavenRepositories, ",") {
+		repositories = append(repositories, NewRepository(repository))
+	}
+	return
+}
+
+func upsertRepository(repository v1.Repository, repositories *[]v1.Repository) {
+	for i, r := range *repositories {
+		if r.ID == repository.ID {
+			(*repositories)[i] = repository
+			return
+		}
+	}
+	*repositories = append(*repositories, repository)
+}
diff --git a/pkg/util/maven/maven_settings.go b/pkg/util/maven/maven_settings.go
index 8d61c49..e1e03f3 100644
--- a/pkg/util/maven/maven_settings.go
+++ b/pkg/util/maven/maven_settings.go
@@ -19,7 +19,6 @@ package maven
 
 import (
 	"encoding/xml"
-	"strings"
 
 	corev1 "k8s.io/api/core/v1"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -46,6 +45,14 @@ func NewSettings(options ...SettingsOption) (Settings, error) {
 		XMLNs:             "http://maven.apache.org/SETTINGS/1.0.0",
 		XMLNsXsi:          "http://www.w3.org/2001/XMLSchema-instance",
 		XsiSchemaLocation: "http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd",
+		Profiles: []Profile{
+			{
+				ID: "camel-k",
+				Activation: Activation{
+					ActiveByDefault: true,
+				},
+			},
+		},
 	}
 
 	for _, option := range options {
@@ -92,6 +99,15 @@ func NewDefaultSettings(repositories []v1.Repository, mirrors []Mirror) Settings
 	return settings
 }
 
+func containsRepo(repositories []v1.Repository, id string) bool {
+	for _, r := range repositories {
+		if r.ID == id {
+			return true
+		}
+	}
+	return false
+}
+
 func SettingsConfigMap(namespace string, name string, settings Settings) (*corev1.ConfigMap, error) {
 	data, err := util.EncodeXML(settings)
 	if err != nil {
@@ -117,19 +133,3 @@ func SettingsConfigMap(namespace string, name string, settings Settings) (*corev
 
 	return cm, nil
 }
-
-func defaultMavenRepositories() (repos []v1.Repository) {
-	for _, repoDesc := range strings.Split(DefaultMavenRepositories, ",") {
-		repos = append(repos, NewRepository(repoDesc))
-	}
-	return
-}
-
-func containsRepo(repositories []v1.Repository, id string) bool {
-	for _, r := range repositories {
-		if r.ID == id {
-			return true
-		}
-	}
-	return false
-}

[camel-k] 01/31: feat(maven): Support platform Maven settings

Posted by as...@apache.org.
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 57b9569f4b7687fa890ff33039d1cbb997bafa2f
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Jan 6 17:43:32 2022 +0100

    feat(maven): Support platform Maven settings
---
 pkg/builder/project.go          | 10 +++++++++-
 pkg/builder/project_test.go     |  4 ++--
 pkg/builder/quarkus.go          |  6 ++++--
 pkg/builder/types.go            |  3 ++-
 pkg/cmd/util_dependencies.go    |  5 ++---
 pkg/trait/openapi.go            | 15 ++++++++++-----
 pkg/util/camel/catalog.go       | 27 +++++++++++++++++----------
 pkg/util/maven/maven_command.go | 23 +++++++++++++++++------
 8 files changed, 63 insertions(+), 30 deletions(-)

diff --git a/pkg/builder/project.go b/pkg/builder/project.go
index 609769d..e9cd843 100644
--- a/pkg/builder/project.go
+++ b/pkg/builder/project.go
@@ -23,6 +23,7 @@ import (
 	"github.com/apache/camel-k/pkg/util/camel"
 	"github.com/apache/camel-k/pkg/util/jvm"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
+	"github.com/apache/camel-k/pkg/util/maven"
 )
 
 func init() {
@@ -90,9 +91,16 @@ func generateProjectSettings(ctx *builderContext) error {
 		return err
 	}
 	if val != "" {
-		ctx.Maven.SettingsData = []byte(val)
+		ctx.Maven.UserSettings = []byte(val)
 	}
 
+	settings := maven.NewSettings()
+	data, err := settings.MarshalBytes()
+	if err != nil {
+		return err
+	}
+	ctx.Maven.GlobalSettings = data
+
 	return nil
 }
 
diff --git a/pkg/builder/project_test.go b/pkg/builder/project_test.go
index 9855cac..9a1c7fa 100644
--- a/pkg/builder/project_test.go
+++ b/pkg/builder/project_test.go
@@ -74,7 +74,7 @@ func TestMavenSettingsFromConfigMap(t *testing.T) {
 	err = Project.GenerateProjectSettings.execute(&ctx)
 	assert.Nil(t, err)
 
-	assert.Equal(t, []byte("setting-data"), ctx.Maven.SettingsData)
+	assert.Equal(t, []byte("setting-data"), ctx.Maven.UserSettings)
 }
 
 func TestMavenSettingsFromSecret(t *testing.T) {
@@ -121,5 +121,5 @@ func TestMavenSettingsFromSecret(t *testing.T) {
 	err = Project.GenerateProjectSettings.execute(&ctx)
 	assert.Nil(t, err)
 
-	assert.Equal(t, []byte("setting-data"), ctx.Maven.SettingsData)
+	assert.Equal(t, []byte("setting-data"), ctx.Maven.UserSettings)
 }
diff --git a/pkg/builder/quarkus.go b/pkg/builder/quarkus.go
index aa52763..7189c1a 100644
--- a/pkg/builder/quarkus.go
+++ b/pkg/builder/quarkus.go
@@ -151,7 +151,8 @@ func GenerateQuarkusProjectCommon(camelQuarkusVersion string, runtimeVersion str
 
 func buildQuarkusRunner(ctx *builderContext) error {
 	mc := maven.NewContext(path.Join(ctx.Path, "maven"))
-	mc.SettingsContent = ctx.Maven.SettingsData
+	mc.GlobalSettings = ctx.Maven.GlobalSettings
+	mc.UserSettings = ctx.Maven.UserSettings
 	mc.LocalRepository = ctx.Build.Maven.LocalRepository
 
 	if ctx.Maven.TrustStoreName != "" {
@@ -196,7 +197,8 @@ func BuildQuarkusRunnerCommon(ctx context.Context, mc maven.Context, project mav
 
 func computeQuarkusDependencies(ctx *builderContext) error {
 	mc := maven.NewContext(path.Join(ctx.Path, "maven"))
-	mc.SettingsContent = ctx.Maven.SettingsData
+	mc.GlobalSettings = ctx.Maven.GlobalSettings
+	mc.UserSettings = ctx.Maven.UserSettings
 	mc.LocalRepository = ctx.Build.Maven.LocalRepository
 
 	// Process artifacts list and add it to existing artifacts
diff --git a/pkg/builder/types.go b/pkg/builder/types.go
index 8897e11..bb2a2f2 100644
--- a/pkg/builder/types.go
+++ b/pkg/builder/types.go
@@ -85,7 +85,8 @@ type builderContext struct {
 	Resources         []resource
 	Maven             struct {
 		Project        maven.Project
-		SettingsData   []byte
+		UserSettings   []byte
+		GlobalSettings []byte
 		TrustStoreName string
 		TrustStorePass string
 	}
diff --git a/pkg/cmd/util_dependencies.go b/pkg/cmd/util_dependencies.go
index 8a5e3ea..96b83f8 100644
--- a/pkg/cmd/util_dependencies.go
+++ b/pkg/cmd/util_dependencies.go
@@ -140,7 +140,7 @@ func getTransitiveDependencies(ctx context.Context, catalog *camel.RuntimeCatalo
 		if err != nil {
 			return nil, err
 		}
-		mc.SettingsContent = settingsData
+		mc.UserSettings = settingsData
 	}
 
 	// Make maven command less verbose
@@ -210,7 +210,6 @@ func getLocalBuildRoutes(integrationDirectory string) ([]string, error) {
 
 func generateCatalog(ctx context.Context) (*camel.RuntimeCatalog, error) {
 	// A Camel catalog is required for this operation
-	settings := ""
 	mvn := v1.MavenSpec{
 		LocalRepository: "",
 	}
@@ -220,7 +219,7 @@ func generateCatalog(ctx context.Context) (*camel.RuntimeCatalog, error) {
 	}
 	var providerDependencies []maven.Dependency
 	var caCert []byte
-	catalog, err := camel.GenerateCatalogCommon(ctx, settings, caCert, mvn, runtime, providerDependencies)
+	catalog, err := camel.GenerateCatalogCommon(ctx, nil, nil, caCert, mvn, runtime, providerDependencies)
 	if err != nil {
 		return nil, err
 	}
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index a4545be..1961355 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -175,7 +175,7 @@ func (t *openAPITrait) generateFromDataSpecs(e *Environment, tmpDir string, spec
 			}
 		}
 
-		// Add an additional source that references the config map
+		// Add a source that references the config map
 		generatedSources = append(generatedSources, v1.SourceSpec{
 			DataSpec: v1.DataSpec{
 				Name:        generatedSourceName,
@@ -256,13 +256,18 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Dat
 	mc.AddArgument("-Dopenapi.spec=" + in)
 	mc.AddArgument("-Ddsl.out=" + out)
 
-	settings, err := kubernetes.ResolveValueSource(e.Ctx, e.Client, e.Platform.Namespace, &e.Platform.Status.Build.Maven.Settings)
-	if err != nil {
+	if settings, err := kubernetes.ResolveValueSource(e.Ctx, e.Client, e.Platform.Namespace, &e.Platform.Status.Build.Maven.Settings); err != nil {
 		return err
+	} else if settings != "" {
+		mc.UserSettings = []byte(settings)
 	}
-	if settings != "" {
-		mc.SettingsContent = []byte(settings)
+
+	settings := maven.NewSettings()
+	data, err := settings.MarshalBytes()
+	if err != nil {
+		return err
 	}
+	mc.GlobalSettings = data
 
 	if e.Platform.Status.Build.Maven.CASecret != nil {
 		certData, err := kubernetes.GetSecretRefData(e.Ctx, e.Client, e.Platform.Namespace, e.Platform.Status.Build.Maven.CASecret)
diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go
index b645955..88df86d 100644
--- a/pkg/util/camel/catalog.go
+++ b/pkg/util/camel/catalog.go
@@ -21,14 +21,13 @@ import (
 	"context"
 	"path"
 
-	"github.com/apache/camel-k/pkg/util"
-
 	yaml2 "gopkg.in/yaml.v2"
 
-	k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/resources"
+	"github.com/apache/camel-k/pkg/util"
 	"github.com/apache/camel-k/pkg/util/defaults"
 	"github.com/apache/camel-k/pkg/util/jvm"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
@@ -75,13 +74,18 @@ func catalogForRuntimeProvider(provider v1.RuntimeProvider) (*RuntimeCatalog, er
 
 func GenerateCatalog(
 	ctx context.Context,
-	client k8sclient.Reader,
+	client ctrl.Reader,
 	namespace string,
 	mvn v1.MavenSpec,
 	runtime v1.RuntimeSpec,
 	providerDependencies []maven.Dependency) (*RuntimeCatalog, error) {
 
-	settings, err := kubernetes.ResolveValueSource(ctx, client, namespace, &mvn.Settings)
+	userSettings, err := kubernetes.ResolveValueSource(ctx, client, namespace, &mvn.Settings)
+	if err != nil {
+		return nil, err
+	}
+	settings := maven.NewSettings()
+	globalSettings, err := settings.MarshalBytes()
 	if err != nil {
 		return nil, err
 	}
@@ -94,12 +98,13 @@ func GenerateCatalog(
 		}
 	}
 
-	return GenerateCatalogCommon(ctx, settings, caCert, mvn, runtime, providerDependencies)
+	return GenerateCatalogCommon(ctx, globalSettings, []byte(userSettings), caCert, mvn, runtime, providerDependencies)
 }
 
 func GenerateCatalogCommon(
 	ctx context.Context,
-	settings string,
+	globalSettings []byte,
+	userSettings []byte,
 	caCert []byte,
 	mvn v1.MavenSpec,
 	runtime v1.RuntimeSpec,
@@ -116,9 +121,11 @@ func GenerateCatalogCommon(
 		mc.AddSystemProperty("catalog.file", "catalog.yaml")
 		mc.AddSystemProperty("catalog.runtime", string(runtime.Provider))
 
-		mc.SettingsContent = nil
-		if settings != "" {
-			mc.SettingsContent = []byte(settings)
+		if globalSettings != nil {
+			mc.GlobalSettings = globalSettings
+		}
+		if userSettings != nil {
+			mc.UserSettings = userSettings
 		}
 
 		if caCert != nil {
diff --git a/pkg/util/maven/maven_command.go b/pkg/util/maven/maven_command.go
index e42d9cd..96c819b 100644
--- a/pkg/util/maven/maven_command.go
+++ b/pkg/util/maven/maven_command.go
@@ -62,12 +62,16 @@ func (c *Command) Do(ctx context.Context) error {
 	}
 
 	settingsPath := path.Join(c.context.Path, "settings.xml")
-	settingsExists, err := util.FileExists(settingsPath)
-	if err != nil {
+	if settingsExists, err := util.FileExists(settingsPath); err != nil {
 		return err
+	} else if settingsExists {
+		args = append(args, "--global-settings", settingsPath)
 	}
 
-	if settingsExists {
+	settingsPath = path.Join(c.context.Path, "user-settings.xml")
+	if settingsExists, err := util.FileExists(settingsPath); err != nil {
+		return err
+	} else if settingsExists {
 		args = append(args, "--settings", settingsPath)
 	}
 
@@ -162,7 +166,8 @@ func NewContext(buildDir string) Context {
 type Context struct {
 	Path                string
 	ExtraMavenOpts      []string
-	SettingsContent     []byte
+	GlobalSettings      []byte
+	UserSettings        []byte
 	AdditionalArguments []string
 	AdditionalEntries   map[string]interface{}
 	LocalRepository     string
@@ -197,8 +202,14 @@ func generateProjectStructure(context Context, project Project) error {
 		return err
 	}
 
-	if context.SettingsContent != nil {
-		if err := util.WriteFileWithContent(path.Join(context.Path, "settings.xml"), context.SettingsContent); err != nil {
+	if context.GlobalSettings != nil {
+		if err := util.WriteFileWithContent(path.Join(context.Path, "settings.xml"), context.GlobalSettings); err != nil {
+			return err
+		}
+	}
+
+	if context.UserSettings != nil {
+		if err := util.WriteFileWithContent(path.Join(context.Path, "user-settings.xml"), context.UserSettings); err != nil {
 			return err
 		}
 	}

[camel-k] 11/31: chore(api): Remove Maven repositories from the platform API

Posted by as...@apache.org.
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 4cc932c3e787bf3c1ffcf00c3db622d16e535cd7
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Jan 7 18:12:06 2022 +0100

    chore(api): Remove Maven repositories from the platform API
---
 config/crd/bases/camel.apache.org_builds.yaml      | 19 +++--
 .../crd/bases/camel.apache.org_camelcatalogs.yaml  |  6 +-
 .../camel.apache.org_integrationplatforms.yaml     | 86 +---------------------
 helm/camel-k/crds/crd-build.yaml                   | 19 +++--
 helm/camel-k/crds/crd-camel-catalog.yaml           |  6 +-
 helm/camel-k/crds/crd-integration-platform.yaml    | 86 +---------------------
 pkg/apis/camel/v1/build_types.go                   |  9 ++-
 pkg/apis/camel/v1/common_types.go                  | 30 --------
 pkg/apis/camel/v1/maven_types.go                   | 39 +++++++++-
 pkg/apis/camel/v1/zz_generated.deepcopy.go         | 27 +++++--
 pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go   |  1 -
 pkg/builder/project_test.go                        | 28 ++++---
 12 files changed, 118 insertions(+), 238 deletions(-)

diff --git a/config/crd/bases/camel.apache.org_builds.yaml b/config/crd/bases/camel.apache.org_builds.yaml
index 88b548c..efac42c 100644
--- a/config/crd/bases/camel.apache.org_builds.yaml
+++ b/config/crd/bases/camel.apache.org_builds.yaml
@@ -134,7 +134,7 @@ spec:
                             type: string
                           type: array
                         maven:
-                          description: MavenSpec --
+                          description: MavenBuildSpec --
                           properties:
                             caSecret:
                               description: The Secret name and key, containing the
@@ -164,9 +164,9 @@ spec:
                               - key
                               type: object
                             extension:
-                              description: Maven build extensions https://maven.apache.org/guides/mini/guide-using-extensions.html
+                              description: The Maven build extensions. See https://maven.apache.org/guides/mini/guide-using-extensions.html.
                               items:
-                                description: MavenArtifact --
+                                description: MavenArtifact defines a Maven artifact
                                 properties:
                                   artifactId:
                                     type: string
@@ -188,15 +188,17 @@ spec:
                               description: The Maven properties.
                               type: object
                             repositories:
+                              description: The Maven repositories.
                               items:
-                                description: Repository --
+                                description: Repository defines a Maven repository
                                 properties:
                                   id:
                                     type: string
                                   name:
                                     type: string
                                   releases:
-                                    description: RepositoryPolicy --
+                                    description: RepositoryPolicy defines the policy
+                                      associated to a Maven repository
                                     properties:
                                       checksumPolicy:
                                         type: string
@@ -208,7 +210,8 @@ spec:
                                     - enabled
                                     type: object
                                   snapshots:
-                                    description: RepositoryPolicy --
+                                    description: RepositoryPolicy defines the policy
+                                      associated to a Maven repository
                                     properties:
                                       checksumPolicy:
                                         type: string
@@ -316,7 +319,7 @@ spec:
                                 properties:
                                   dependencies:
                                     items:
-                                      description: MavenArtifact --
+                                      description: MavenArtifact defines a Maven artifact
                                       properties:
                                         artifactId:
                                           type: string
@@ -339,7 +342,7 @@ spec:
                               type: object
                             dependencies:
                               items:
-                                description: MavenArtifact --
+                                description: MavenArtifact defines a Maven artifact
                                 properties:
                                   artifactId:
                                     type: string
diff --git a/config/crd/bases/camel.apache.org_camelcatalogs.yaml b/config/crd/bases/camel.apache.org_camelcatalogs.yaml
index 4d33593..536db40 100644
--- a/config/crd/bases/camel.apache.org_camelcatalogs.yaml
+++ b/config/crd/bases/camel.apache.org_camelcatalogs.yaml
@@ -227,7 +227,7 @@ spec:
                       type: string
                     dependencies:
                       items:
-                        description: MavenArtifact --
+                        description: MavenArtifact defines a Maven artifact
                         properties:
                           artifactId:
                             type: string
@@ -264,7 +264,7 @@ spec:
                       properties:
                         dependencies:
                           items:
-                            description: MavenArtifact --
+                            description: MavenArtifact defines a Maven artifact
                             properties:
                               artifactId:
                                 type: string
@@ -287,7 +287,7 @@ spec:
                     type: object
                   dependencies:
                     items:
-                      description: MavenArtifact --
+                      description: MavenArtifact defines a Maven artifact
                       properties:
                         artifactId:
                           type: string
diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 4307527..1a0edd6 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -108,9 +108,9 @@ spec:
                         - key
                         type: object
                       extension:
-                        description: Maven build extensions https://maven.apache.org/guides/mini/guide-using-extensions.html
+                        description: The Maven build extensions. See https://maven.apache.org/guides/mini/guide-using-extensions.html.
                         items:
-                          description: MavenArtifact --
+                          description: MavenArtifact defines a Maven artifact
                           properties:
                             artifactId:
                               type: string
@@ -131,45 +131,6 @@ spec:
                           type: string
                         description: The Maven properties.
                         type: object
-                      repositories:
-                        items:
-                          description: Repository --
-                          properties:
-                            id:
-                              type: string
-                            name:
-                              type: string
-                            releases:
-                              description: RepositoryPolicy --
-                              properties:
-                                checksumPolicy:
-                                  type: string
-                                enabled:
-                                  type: boolean
-                                updatePolicy:
-                                  type: string
-                              required:
-                              - enabled
-                              type: object
-                            snapshots:
-                              description: RepositoryPolicy --
-                              properties:
-                                checksumPolicy:
-                                  type: string
-                                enabled:
-                                  type: boolean
-                                updatePolicy:
-                                  type: string
-                              required:
-                              - enabled
-                              type: object
-                            url:
-                              type: string
-                          required:
-                          - id
-                          - url
-                          type: object
-                        type: array
                       settings:
                         description: A reference to the ConfigMap or Secret key that
                           contains the Maven settings.
@@ -349,9 +310,9 @@ spec:
                         - key
                         type: object
                       extension:
-                        description: Maven build extensions https://maven.apache.org/guides/mini/guide-using-extensions.html
+                        description: The Maven build extensions. See https://maven.apache.org/guides/mini/guide-using-extensions.html.
                         items:
-                          description: MavenArtifact --
+                          description: MavenArtifact defines a Maven artifact
                           properties:
                             artifactId:
                               type: string
@@ -372,45 +333,6 @@ spec:
                           type: string
                         description: The Maven properties.
                         type: object
-                      repositories:
-                        items:
-                          description: Repository --
-                          properties:
-                            id:
-                              type: string
-                            name:
-                              type: string
-                            releases:
-                              description: RepositoryPolicy --
-                              properties:
-                                checksumPolicy:
-                                  type: string
-                                enabled:
-                                  type: boolean
-                                updatePolicy:
-                                  type: string
-                              required:
-                              - enabled
-                              type: object
-                            snapshots:
-                              description: RepositoryPolicy --
-                              properties:
-                                checksumPolicy:
-                                  type: string
-                                enabled:
-                                  type: boolean
-                                updatePolicy:
-                                  type: string
-                              required:
-                              - enabled
-                              type: object
-                            url:
-                              type: string
-                          required:
-                          - id
-                          - url
-                          type: object
-                        type: array
                       settings:
                         description: A reference to the ConfigMap or Secret key that
                           contains the Maven settings.
diff --git a/helm/camel-k/crds/crd-build.yaml b/helm/camel-k/crds/crd-build.yaml
index 88b548c..efac42c 100644
--- a/helm/camel-k/crds/crd-build.yaml
+++ b/helm/camel-k/crds/crd-build.yaml
@@ -134,7 +134,7 @@ spec:
                             type: string
                           type: array
                         maven:
-                          description: MavenSpec --
+                          description: MavenBuildSpec --
                           properties:
                             caSecret:
                               description: The Secret name and key, containing the
@@ -164,9 +164,9 @@ spec:
                               - key
                               type: object
                             extension:
-                              description: Maven build extensions https://maven.apache.org/guides/mini/guide-using-extensions.html
+                              description: The Maven build extensions. See https://maven.apache.org/guides/mini/guide-using-extensions.html.
                               items:
-                                description: MavenArtifact --
+                                description: MavenArtifact defines a Maven artifact
                                 properties:
                                   artifactId:
                                     type: string
@@ -188,15 +188,17 @@ spec:
                               description: The Maven properties.
                               type: object
                             repositories:
+                              description: The Maven repositories.
                               items:
-                                description: Repository --
+                                description: Repository defines a Maven repository
                                 properties:
                                   id:
                                     type: string
                                   name:
                                     type: string
                                   releases:
-                                    description: RepositoryPolicy --
+                                    description: RepositoryPolicy defines the policy
+                                      associated to a Maven repository
                                     properties:
                                       checksumPolicy:
                                         type: string
@@ -208,7 +210,8 @@ spec:
                                     - enabled
                                     type: object
                                   snapshots:
-                                    description: RepositoryPolicy --
+                                    description: RepositoryPolicy defines the policy
+                                      associated to a Maven repository
                                     properties:
                                       checksumPolicy:
                                         type: string
@@ -316,7 +319,7 @@ spec:
                                 properties:
                                   dependencies:
                                     items:
-                                      description: MavenArtifact --
+                                      description: MavenArtifact defines a Maven artifact
                                       properties:
                                         artifactId:
                                           type: string
@@ -339,7 +342,7 @@ spec:
                               type: object
                             dependencies:
                               items:
-                                description: MavenArtifact --
+                                description: MavenArtifact defines a Maven artifact
                                 properties:
                                   artifactId:
                                     type: string
diff --git a/helm/camel-k/crds/crd-camel-catalog.yaml b/helm/camel-k/crds/crd-camel-catalog.yaml
index 4d33593..536db40 100644
--- a/helm/camel-k/crds/crd-camel-catalog.yaml
+++ b/helm/camel-k/crds/crd-camel-catalog.yaml
@@ -227,7 +227,7 @@ spec:
                       type: string
                     dependencies:
                       items:
-                        description: MavenArtifact --
+                        description: MavenArtifact defines a Maven artifact
                         properties:
                           artifactId:
                             type: string
@@ -264,7 +264,7 @@ spec:
                       properties:
                         dependencies:
                           items:
-                            description: MavenArtifact --
+                            description: MavenArtifact defines a Maven artifact
                             properties:
                               artifactId:
                                 type: string
@@ -287,7 +287,7 @@ spec:
                     type: object
                   dependencies:
                     items:
-                      description: MavenArtifact --
+                      description: MavenArtifact defines a Maven artifact
                       properties:
                         artifactId:
                           type: string
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml
index 4307527..1a0edd6 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -108,9 +108,9 @@ spec:
                         - key
                         type: object
                       extension:
-                        description: Maven build extensions https://maven.apache.org/guides/mini/guide-using-extensions.html
+                        description: The Maven build extensions. See https://maven.apache.org/guides/mini/guide-using-extensions.html.
                         items:
-                          description: MavenArtifact --
+                          description: MavenArtifact defines a Maven artifact
                           properties:
                             artifactId:
                               type: string
@@ -131,45 +131,6 @@ spec:
                           type: string
                         description: The Maven properties.
                         type: object
-                      repositories:
-                        items:
-                          description: Repository --
-                          properties:
-                            id:
-                              type: string
-                            name:
-                              type: string
-                            releases:
-                              description: RepositoryPolicy --
-                              properties:
-                                checksumPolicy:
-                                  type: string
-                                enabled:
-                                  type: boolean
-                                updatePolicy:
-                                  type: string
-                              required:
-                              - enabled
-                              type: object
-                            snapshots:
-                              description: RepositoryPolicy --
-                              properties:
-                                checksumPolicy:
-                                  type: string
-                                enabled:
-                                  type: boolean
-                                updatePolicy:
-                                  type: string
-                              required:
-                              - enabled
-                              type: object
-                            url:
-                              type: string
-                          required:
-                          - id
-                          - url
-                          type: object
-                        type: array
                       settings:
                         description: A reference to the ConfigMap or Secret key that
                           contains the Maven settings.
@@ -349,9 +310,9 @@ spec:
                         - key
                         type: object
                       extension:
-                        description: Maven build extensions https://maven.apache.org/guides/mini/guide-using-extensions.html
+                        description: The Maven build extensions. See https://maven.apache.org/guides/mini/guide-using-extensions.html.
                         items:
-                          description: MavenArtifact --
+                          description: MavenArtifact defines a Maven artifact
                           properties:
                             artifactId:
                               type: string
@@ -372,45 +333,6 @@ spec:
                           type: string
                         description: The Maven properties.
                         type: object
-                      repositories:
-                        items:
-                          description: Repository --
-                          properties:
-                            id:
-                              type: string
-                            name:
-                              type: string
-                            releases:
-                              description: RepositoryPolicy --
-                              properties:
-                                checksumPolicy:
-                                  type: string
-                                enabled:
-                                  type: boolean
-                                updatePolicy:
-                                  type: string
-                              required:
-                              - enabled
-                              type: object
-                            snapshots:
-                              description: RepositoryPolicy --
-                              properties:
-                                checksumPolicy:
-                                  type: string
-                                enabled:
-                                  type: boolean
-                                updatePolicy:
-                                  type: string
-                              required:
-                              - enabled
-                              type: object
-                            url:
-                              type: string
-                          required:
-                          - id
-                          - url
-                          type: object
-                        type: array
                       settings:
                         description: A reference to the ConfigMap or Secret key that
                           contains the Maven settings.
diff --git a/pkg/apis/camel/v1/build_types.go b/pkg/apis/camel/v1/build_types.go
index 7345702..3f40acc 100644
--- a/pkg/apis/camel/v1/build_types.go
+++ b/pkg/apis/camel/v1/build_types.go
@@ -62,10 +62,17 @@ type BuilderTask struct {
 	Resources    []ResourceSpec `json:"resources,omitempty"`
 	Dependencies []string       `json:"dependencies,omitempty"`
 	Steps        []string       `json:"steps,omitempty"`
-	Maven        MavenSpec      `json:"maven,omitempty"`
+	Maven        MavenBuildSpec `json:"maven,omitempty"`
 	BuildDir     string         `json:"buildDir,omitempty"`
 }
 
+// MavenBuildSpec --
+type MavenBuildSpec struct {
+	MavenSpec `json:",inline"`
+	// The Maven repositories.
+	Repositories []Repository `json:"repositories,omitempty"`
+}
+
 // PublishTask --
 type PublishTask struct {
 	ContextDir string       `json:"contextDir,omitempty"`
diff --git a/pkg/apis/camel/v1/common_types.go b/pkg/apis/camel/v1/common_types.go
index 45e9f91..5826a06 100644
--- a/pkg/apis/camel/v1/common_types.go
+++ b/pkg/apis/camel/v1/common_types.go
@@ -104,29 +104,6 @@ type Configurable interface {
 	Configurations() []ConfigurationSpec
 }
 
-// MavenSpec --
-type MavenSpec struct {
-	// The path of the local Maven repository.
-	LocalRepository string `json:"localRepository,omitempty"`
-	// The Maven properties.
-	Properties map[string]string `json:"properties,omitempty"`
-	// A reference to the ConfigMap or Secret key that contains
-	// the Maven settings.
-	Settings ValueSource `json:"settings,omitempty"`
-	// The Secret name and key, containing the CA certificate(s) used to connect
-	// to remote Maven repositories.
-	// It can contain X.509 certificates, and PKCS#7 formatted certificate chains.
-	// A JKS formatted keystore is automatically created to store the CA certificate(s),
-	// and configured to be used as a trusted certificate(s) by the Maven commands.
-	// Note that the root CA certificates are also imported into the created keystore.
-	CASecret *corev1.SecretKeySelector `json:"caSecret,omitempty"`
-	// Deprecated: use IntegrationPlatform.Spec.Build.Timeout instead
-	Timeout      *metav1.Duration `json:"timeout,omitempty"`
-	Repositories []Repository     `json:"repositories,omitempty"`
-	// Maven build extensions https://maven.apache.org/guides/mini/guide-using-extensions.html
-	Extension []MavenArtifact `json:"extension,omitempty"`
-}
-
 // RegistrySpec provides the configuration for the container registry
 type RegistrySpec struct {
 	Insecure     bool   `json:"insecure,omitempty"`
@@ -144,13 +121,6 @@ type ValueSource struct {
 	SecretKeyRef *corev1.SecretKeySelector `json:"secretKeyRef,omitempty"`
 }
 
-// MavenArtifact --
-type MavenArtifact struct {
-	GroupID    string `json:"groupId" yaml:"groupId" xml:"groupId"`
-	ArtifactID string `json:"artifactId" yaml:"artifactId" xml:"artifactId"`
-	Version    string `json:"version,omitempty" yaml:"version,omitempty" xml:"version,omitempty"`
-}
-
 // RuntimeSpec --
 type RuntimeSpec struct {
 	Version          string                `json:"version" yaml:"version"`
diff --git a/pkg/apis/camel/v1/maven_types.go b/pkg/apis/camel/v1/maven_types.go
index 426f113..569336c 100644
--- a/pkg/apis/camel/v1/maven_types.go
+++ b/pkg/apis/camel/v1/maven_types.go
@@ -17,7 +17,35 @@ limitations under the License.
 
 package v1
 
-// Repository --
+import (
+	corev1 "k8s.io/api/core/v1"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+)
+
+// MavenSpec --
+type MavenSpec struct {
+	// The path of the local Maven repository.
+	LocalRepository string `json:"localRepository,omitempty"`
+	// The Maven properties.
+	Properties map[string]string `json:"properties,omitempty"`
+	// A reference to the ConfigMap or Secret key that contains
+	// the Maven settings.
+	Settings ValueSource `json:"settings,omitempty"`
+	// The Secret name and key, containing the CA certificate(s) used to connect
+	// to remote Maven repositories.
+	// It can contain X.509 certificates, and PKCS#7 formatted certificate chains.
+	// A JKS formatted keystore is automatically created to store the CA certificate(s),
+	// and configured to be used as a trusted certificate(s) by the Maven commands.
+	// Note that the root CA certificates are also imported into the created keystore.
+	CASecret *corev1.SecretKeySelector `json:"caSecret,omitempty"`
+	// Deprecated: use IntegrationPlatform.Spec.Build.Timeout instead
+	Timeout *metav1.Duration `json:"timeout,omitempty"`
+	// The Maven build extensions.
+	// See https://maven.apache.org/guides/mini/guide-using-extensions.html.
+	Extension []MavenArtifact `json:"extension,omitempty"`
+}
+
+// Repository defines a Maven repository
 type Repository struct {
 	ID        string           `xml:"id" json:"id"`
 	Name      string           `xml:"name,omitempty" json:"name,omitempty"`
@@ -26,9 +54,16 @@ type Repository struct {
 	Releases  RepositoryPolicy `xml:"releases,omitempty" json:"releases,omitempty"`
 }
 
-// RepositoryPolicy --
+// RepositoryPolicy defines the policy associated to a Maven repository
 type RepositoryPolicy struct {
 	Enabled        bool   `xml:"enabled" json:"enabled"`
 	UpdatePolicy   string `xml:"updatePolicy,omitempty" json:"updatePolicy,omitempty"`
 	ChecksumPolicy string `xml:"checksumPolicy,omitempty" json:"checksumPolicy,omitempty"`
 }
+
+// MavenArtifact defines a Maven artifact
+type MavenArtifact struct {
+	GroupID    string `json:"groupId" yaml:"groupId" xml:"groupId"`
+	ArtifactID string `json:"artifactId" yaml:"artifactId" xml:"artifactId"`
+	Version    string `json:"version,omitempty" yaml:"version,omitempty" xml:"version,omitempty"`
+}
diff --git a/pkg/apis/camel/v1/zz_generated.deepcopy.go b/pkg/apis/camel/v1/zz_generated.deepcopy.go
index f23a7da..b9f63d7 100644
--- a/pkg/apis/camel/v1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1/zz_generated.deepcopy.go
@@ -1,4 +1,3 @@
-//go:build !ignore_autogenerated
 // +build !ignore_autogenerated
 
 // Code generated by controller-gen. DO NOT EDIT.
@@ -1240,6 +1239,27 @@ func (in *MavenArtifact) DeepCopy() *MavenArtifact {
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
+func (in *MavenBuildSpec) DeepCopyInto(out *MavenBuildSpec) {
+	*out = *in
+	in.MavenSpec.DeepCopyInto(&out.MavenSpec)
+	if in.Repositories != nil {
+		in, out := &in.Repositories, &out.Repositories
+		*out = make([]Repository, len(*in))
+		copy(*out, *in)
+	}
+}
+
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MavenBuildSpec.
+func (in *MavenBuildSpec) DeepCopy() *MavenBuildSpec {
+	if in == nil {
+		return nil
+	}
+	out := new(MavenBuildSpec)
+	in.DeepCopyInto(out)
+	return out
+}
+
+// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
 func (in *MavenSpec) DeepCopyInto(out *MavenSpec) {
 	*out = *in
 	if in.Properties != nil {
@@ -1260,11 +1280,6 @@ func (in *MavenSpec) DeepCopyInto(out *MavenSpec) {
 		*out = new(metav1.Duration)
 		**out = **in
 	}
-	if in.Repositories != nil {
-		in, out := &in.Repositories, &out.Repositories
-		*out = make([]Repository, len(*in))
-		copy(*out, *in)
-	}
 	if in.Extension != nil {
 		in, out := &in.Extension, &out.Extension
 		*out = make([]MavenArtifact, len(*in))
diff --git a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
index be6e2c5..a5c99f3 100644
--- a/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1alpha1/zz_generated.deepcopy.go
@@ -1,4 +1,3 @@
-//go:build !ignore_autogenerated
 // +build !ignore_autogenerated
 
 // Code generated by controller-gen. DO NOT EDIT.
diff --git a/pkg/builder/project_test.go b/pkg/builder/project_test.go
index 9a1c7fa..5d8fdcf 100644
--- a/pkg/builder/project_test.go
+++ b/pkg/builder/project_test.go
@@ -58,13 +58,15 @@ func TestMavenSettingsFromConfigMap(t *testing.T) {
 		Namespace: "ns",
 		Build: v1.BuilderTask{
 			Runtime: catalog.Runtime,
-			Maven: v1.MavenSpec{
-				Settings: v1.ValueSource{
-					ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
-						LocalObjectReference: corev1.LocalObjectReference{
-							Name: "maven-settings",
+			Maven: v1.MavenBuildSpec{
+				MavenSpec: v1.MavenSpec{
+					Settings: v1.ValueSource{
+						ConfigMapKeyRef: &corev1.ConfigMapKeySelector{
+							LocalObjectReference: corev1.LocalObjectReference{
+								Name: "maven-settings",
+							},
+							Key: "settings.xml",
 						},
-						Key: "settings.xml",
 					},
 				},
 			},
@@ -105,13 +107,15 @@ func TestMavenSettingsFromSecret(t *testing.T) {
 		Namespace: "ns",
 		Build: v1.BuilderTask{
 			Runtime: catalog.Runtime,
-			Maven: v1.MavenSpec{
-				Settings: v1.ValueSource{
-					SecretKeyRef: &corev1.SecretKeySelector{
-						LocalObjectReference: corev1.LocalObjectReference{
-							Name: "maven-settings",
+			Maven: v1.MavenBuildSpec{
+				MavenSpec: v1.MavenSpec{
+					Settings: v1.ValueSource{
+						SecretKeyRef: &corev1.SecretKeySelector{
+							LocalObjectReference: corev1.LocalObjectReference{
+								Name: "maven-settings",
+							},
+							Key: "settings.xml",
 						},
-						Key: "settings.xml",
 					},
 				},
 			},

[camel-k] 19/31: chore(jvm): Rely on default JVM HTTP proxy port numbers

Posted by as...@apache.org.
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 da858f3ea9dfef9727beb58445abc4cab95c9536
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 10 14:48:42 2022 +0100

    chore(jvm): Rely on default JVM HTTP proxy port numbers
---
 pkg/trait/jvm.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 200670b..57d442a 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -181,7 +181,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
 		if !util.StringSliceContainsAnyOf(t.Options, "http.proxyHost") {
 			args = append(args, "-Dhttp.proxyHost="+u.Hostname())
 		}
-		if !util.StringSliceContainsAnyOf(t.Options, "http.proxyPort") {
+		if port := u.Port(); !util.StringSliceContainsAnyOf(t.Options, "http.proxyPort") && port != "" {
 			args = append(args, "-Dhttp.proxyPort="+u.Port())
 		}
 		if user := u.User; !util.StringSliceContainsAnyOf(t.Options, "http.proxyUser") && user != nil {
@@ -200,7 +200,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
 		if !util.StringSliceContainsAnyOf(t.Options, "https.proxyHost") {
 			args = append(args, "-Dhttps.proxyHost="+u.Hostname())
 		}
-		if !util.StringSliceContainsAnyOf(t.Options, "https.proxyPort") {
+		if port := u.Port(); !util.StringSliceContainsAnyOf(t.Options, "https.proxyPort") && port != "" {
 			args = append(args, "-Dhttps.proxyPort="+u.Port())
 		}
 		if user := u.User; !util.StringSliceContainsAnyOf(t.Options, "https.proxyUser") && user != nil {

[camel-k] 08/31: chore(e2e): Set NO_PROXY with the Kubernetes service cluster IPs

Posted by as...@apache.org.
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 c2131ca00858848fb01264f4c08ab67cc2243385
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Jan 7 12:48:08 2022 +0100

    chore(e2e): Set NO_PROXY with the Kubernetes service cluster IPs
---
 e2e/common/build/maven_http_proxy_test.go | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/e2e/common/build/maven_http_proxy_test.go b/e2e/common/build/maven_http_proxy_test.go
index ace8aa8..ef7a6f3 100644
--- a/e2e/common/build/maven_http_proxy_test.go
+++ b/e2e/common/build/maven_http_proxy_test.go
@@ -31,6 +31,7 @@ import (
 	"fmt"
 	"math/big"
 	rand2 "math/rand"
+	"strings"
 	"testing"
 	"time"
 
@@ -294,14 +295,24 @@ ProxyVia Off
 			}),
 		))
 
+		svc := Service("default", "kubernetes")()
+		Expect(svc).NotTo(BeNil())
+
+		// It may be needed to populate the values from the cluster, machine and service network CIDRs
+		noProxy := []string{
+			".cluster.local",
+			".svc",
+			"localhost",
+		}
+		noProxy = append(noProxy, svc.Spec.ClusterIPs...)
+
 		// Install Camel K with the HTTP proxy
 		Expect(Kamel("install", "-n", ns,
 			"--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://%s", hostname),
 			// FIXME: TLS handshake issue
 			// "--operator-env-vars", fmt.Sprintf("HTTPS_PROXY=https://%s", hostname),
 			// "--maven-ca-secret", secret.Name+"/"+corev1.TLSCertKey,
-			// FIXME: use the cluster network CIDR
-			"--operator-env-vars", "NO_PROXY=.cluster.local,.svc,10.0.0.0/16,127.0.0.1,172.17.0.0/18,172.21.0.0/16",
+			"--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","),
 		).Execute()).To(Succeed())
 
 		Eventually(PlatformPhase(ns), TestTimeoutMedium).Should(Equal(v1.IntegrationPlatformPhaseReady))

[camel-k] 26/31: chore(api): Remove HTTP proxy Secret

Posted by as...@apache.org.
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 360be86cd8c4a3b43a908cf286ae454f1ab39c46
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 11 13:32:45 2022 +0100

    chore(api): Remove HTTP proxy Secret
---
 config/crd/bases/camel.apache.org_builds.yaml      |  4 ---
 .../camel.apache.org_integrationplatforms.yaml     |  4 ---
 helm/camel-k/crds/crd-build.yaml                   |  4 ---
 helm/camel-k/crds/crd-integration-platform.yaml    |  4 ---
 pkg/apis/camel/v1/build_types.go                   | 16 +++++-------
 pkg/apis/camel/v1/integrationplatform_types.go     |  1 -
 pkg/cmd/install.go                                 |  7 -----
 pkg/cmd/install_test.go                            |  7 -----
 pkg/controller/build/build_pod.go                  | 30 ----------------------
 pkg/trait/builder.go                               |  6 ++---
 10 files changed, 9 insertions(+), 74 deletions(-)

diff --git a/config/crd/bases/camel.apache.org_builds.yaml b/config/crd/bases/camel.apache.org_builds.yaml
index efac42c..d678755 100644
--- a/config/crd/bases/camel.apache.org_builds.yaml
+++ b/config/crd/bases/camel.apache.org_builds.yaml
@@ -98,8 +98,6 @@ spec:
                           type: string
                         contextDir:
                           type: string
-                        httpProxySecret:
-                          type: string
                         image:
                           type: string
                         name:
@@ -437,8 +435,6 @@ spec:
                           type: object
                         contextDir:
                           type: string
-                        httpProxySecret:
-                          type: string
                         image:
                           type: string
                         name:
diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 1a0edd6..699fcd8 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -76,8 +76,6 @@ spec:
                     - routine
                     - pod
                     type: string
-                  httpProxySecret:
-                    type: string
                   kanikoBuildCache:
                     type: boolean
                   maven:
@@ -278,8 +276,6 @@ spec:
                     - routine
                     - pod
                     type: string
-                  httpProxySecret:
-                    type: string
                   kanikoBuildCache:
                     type: boolean
                   maven:
diff --git a/helm/camel-k/crds/crd-build.yaml b/helm/camel-k/crds/crd-build.yaml
index efac42c..d678755 100644
--- a/helm/camel-k/crds/crd-build.yaml
+++ b/helm/camel-k/crds/crd-build.yaml
@@ -98,8 +98,6 @@ spec:
                           type: string
                         contextDir:
                           type: string
-                        httpProxySecret:
-                          type: string
                         image:
                           type: string
                         name:
@@ -437,8 +435,6 @@ spec:
                           type: object
                         contextDir:
                           type: string
-                        httpProxySecret:
-                          type: string
                         image:
                           type: string
                         name:
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml
index 1a0edd6..699fcd8 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -76,8 +76,6 @@ spec:
                     - routine
                     - pod
                     type: string
-                  httpProxySecret:
-                    type: string
                   kanikoBuildCache:
                     type: boolean
                   maven:
@@ -278,8 +276,6 @@ spec:
                     - routine
                     - pod
                     type: string
-                  httpProxySecret:
-                    type: string
                   kanikoBuildCache:
                     type: boolean
                   maven:
diff --git a/pkg/apis/camel/v1/build_types.go b/pkg/apis/camel/v1/build_types.go
index 3f40acc..8b8d35a 100644
--- a/pkg/apis/camel/v1/build_types.go
+++ b/pkg/apis/camel/v1/build_types.go
@@ -83,19 +83,17 @@ type PublishTask struct {
 
 // BuildahTask --
 type BuildahTask struct {
-	BaseTask        `json:",inline"`
-	PublishTask     `json:",inline"`
-	Verbose         *bool  `json:"verbose,omitempty"`
-	HttpProxySecret string `json:"httpProxySecret,omitempty"`
+	BaseTask    `json:",inline"`
+	PublishTask `json:",inline"`
+	Verbose     *bool `json:"verbose,omitempty"`
 }
 
 // KanikoTask --
 type KanikoTask struct {
-	BaseTask        `json:",inline"`
-	PublishTask     `json:",inline"`
-	Verbose         *bool           `json:"verbose,omitempty"`
-	HttpProxySecret string          `json:"httpProxySecret,omitempty"`
-	Cache           KanikoTaskCache `json:"cache,omitempty"`
+	BaseTask    `json:",inline"`
+	PublishTask `json:",inline"`
+	Verbose     *bool           `json:"verbose,omitempty"`
+	Cache       KanikoTaskCache `json:"cache,omitempty"`
 }
 
 // KanikoTaskCache --
diff --git a/pkg/apis/camel/v1/integrationplatform_types.go b/pkg/apis/camel/v1/integrationplatform_types.go
index 807cfd2..87c66ac 100644
--- a/pkg/apis/camel/v1/integrationplatform_types.go
+++ b/pkg/apis/camel/v1/integrationplatform_types.go
@@ -116,7 +116,6 @@ type IntegrationPlatformBuildSpec struct {
 	Timeout               *metav1.Duration                        `json:"timeout,omitempty"`
 	PersistentVolumeClaim string                                  `json:"persistentVolumeClaim,omitempty"`
 	Maven                 MavenSpec                               `json:"maven,omitempty"`
-	HTTPProxySecret       string                                  `json:"httpProxySecret,omitempty"`
 	KanikoBuildCache      *bool                                   `json:"kanikoBuildCache,omitempty"`
 }
 
diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index 6807324..99fe01f 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -104,8 +104,6 @@ func newCmdInstall(rootCmdOptions *RootCmdOptions) (*cobra.Command, *installCmdO
 	cmd.Flags().String("build-timeout", "", "Set how long the build process can last")
 	cmd.Flags().String("trait-profile", "", "The profile to use for traits")
 	cmd.Flags().Bool("kaniko-build-cache", false, "To enable or disable the Kaniko cache")
-	cmd.Flags().String("http-proxy-secret", "", "Configure the source of the secret holding HTTP proxy server details "+
-		"(HTTP_PROXY|HTTPS_PROXY|NO_PROXY)")
 
 	// OLM
 	cmd.Flags().Bool("olm", true, "Try to install everything via OLM (Operator Lifecycle Manager) if available")
@@ -189,7 +187,6 @@ type installCmdOptions struct {
 	TraitProfile            string   `mapstructure:"trait-profile"`
 	Tolerations             []string `mapstructure:"tolerations"`
 	NodeSelectors           []string `mapstructure:"node-selectors"`
-	HTTPProxySecret         string   `mapstructure:"http-proxy-secret"`
 	ResourcesRequirements   []string `mapstructure:"operator-resources"`
 	EnvVars                 []string `mapstructure:"operator-env-vars"`
 
@@ -422,10 +419,6 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 			platform.Spec.Build.Maven.CASecret = secret
 		}
 
-		if o.HTTPProxySecret != "" {
-			platform.Spec.Build.HTTPProxySecret = o.HTTPProxySecret
-		}
-
 		if o.ClusterType != "" {
 			for _, c := range v1.AllIntegrationPlatformClusters {
 				if strings.EqualFold(string(c), o.ClusterType) {
diff --git a/pkg/cmd/install_test.go b/pkg/cmd/install_test.go
index 8c4e587..58fe06e 100644
--- a/pkg/cmd/install_test.go
+++ b/pkg/cmd/install_test.go
@@ -156,13 +156,6 @@ func TestInstallHealthFlag(t *testing.T) {
 	assert.Equal(t, int32(7777), installCmdOptions.HealthPort)
 }
 
-func TestInstallHttpProxySecretFlag(t *testing.T) {
-	installCmdOptions, rootCmd, _ := initializeInstallCmdOptions(t)
-	_, err := test.ExecuteCommand(rootCmd, cmdInstall, "--http-proxy-secret", "someString")
-	assert.Nil(t, err)
-	assert.Equal(t, "someString", installCmdOptions.HTTPProxySecret)
-}
-
 func TestInstallKanikoBuildCacheFlag(t *testing.T) {
 	installCmdOptions, rootCmd, _ := initializeInstallCmdOptions(t)
 	_, err := test.ExecuteCommand(rootCmd, cmdInstall, "--kaniko-build-cache")
diff --git a/pkg/controller/build/build_pod.go b/pkg/controller/build/build_pod.go
index d5e813f..00cab13 100644
--- a/pkg/controller/build/build_pod.go
+++ b/pkg/controller/build/build_pod.go
@@ -303,7 +303,6 @@ func addBuildahTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, ta
 	}
 
 	env = append(env, proxyFromEnvironment()...)
-	env = append(env, proxySecretEnvVars(task.HttpProxySecret)...)
 
 	args := []string{
 		strings.Join(bud, " "),
@@ -368,7 +367,6 @@ func addKanikoTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, tas
 	}
 
 	env = append(env, proxyFromEnvironment()...)
-	env = append(env, proxySecretEnvVars(task.HttpProxySecret)...)
 
 	if cache {
 		// Co-locate with the Kaniko warmer pod for sharing the host path volume as the current
@@ -548,34 +546,6 @@ func addRegistrySecret(name string, secret registrySecret, volumes *[]corev1.Vol
 	}
 }
 
-func proxySecretEnvVars(secret string) []corev1.EnvVar {
-	if secret == "" {
-		return []corev1.EnvVar{}
-	}
-
-	return []corev1.EnvVar{
-		proxySecretEnvVar("HTTP_PROXY", secret),
-		proxySecretEnvVar("HTTPS_PROXY", secret),
-		proxySecretEnvVar("NO_PROXY", secret),
-	}
-}
-
-func proxySecretEnvVar(name string, secret string) corev1.EnvVar {
-	optional := true
-	return corev1.EnvVar{
-		Name: name,
-		ValueFrom: &corev1.EnvVarSource{
-			SecretKeyRef: &corev1.SecretKeySelector{
-				LocalObjectReference: corev1.LocalObjectReference{
-					Name: secret,
-				},
-				Key:      name,
-				Optional: &optional,
-			},
-		},
-	}
-}
-
 func proxyFromEnvironment() []corev1.EnvVar {
 	var envVars []corev1.EnvVar
 
diff --git a/pkg/trait/builder.go b/pkg/trait/builder.go
index 22f970d..34cc890 100644
--- a/pkg/trait/builder.go
+++ b/pkg/trait/builder.go
@@ -109,8 +109,7 @@ func (t *builderTrait) Apply(e *Environment) error {
 				Image:    getImageName(e),
 				Registry: e.Platform.Status.Build.Registry,
 			},
-			HttpProxySecret: e.Platform.Status.Build.HTTPProxySecret,
-			Verbose:         t.Verbose,
+			Verbose: t.Verbose,
 		}})
 
 	case v1.IntegrationPlatformBuildPublishStrategyKaniko:
@@ -126,8 +125,7 @@ func (t *builderTrait) Apply(e *Environment) error {
 				Enabled:               e.Platform.Status.Build.KanikoBuildCache,
 				PersistentVolumeClaim: e.Platform.Status.Build.PersistentVolumeClaim,
 			},
-			HttpProxySecret: e.Platform.Status.Build.HTTPProxySecret,
-			Verbose:         t.Verbose,
+			Verbose: t.Verbose,
 		}})
 	}
 

[camel-k] 15/31: feat(trait): Propagate HTTP proxy env variables to integration Pods

Posted by as...@apache.org.
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 <an...@stefanutti.fr>
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]'

[camel-k] 29/31: chore: Rebuild resources

Posted by as...@apache.org.
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 cc4449f9d1c4c95a855531b704f1adcee588ee3b
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Jan 12 09:44:07 2022 +0100

    chore: Rebuild resources
---
 pkg/resources/resources.go | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/pkg/resources/resources.go b/pkg/resources/resources.go
index bcc7095..12c54ae 100644
--- a/pkg/resources/resources.go
+++ b/pkg/resources/resources.go
@@ -117,9 +117,9 @@ var assets = func() http.FileSystem {
 		"/crd/bases/camel.apache.org_builds.yaml": &vfsgenÛ°CompressedFileInfo{
 			name:             "camel.apache.org_builds.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 26787,
+			uncompressedSize: 26973,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3d\x5d\x73\xdb\x3a\x76\xef\xfa\x15\x67\xe2\x87\x24\x33\x16\x75\xef\xdd\xdd\xf6\xd6\x7d\xe8\x68\x95\x64\xaa\x26\xb1\x3d\x96\x73\xb7\xfb\x78\x44\x1e\x51\x58\x91\x00\x0b\x80\x96\xb5\x9d\xfe\xf7\x0e\x3e\x28\x51\x16\x3f\x40\x47\x9e\x4d\x7b\x8d\x97\x44\x24\x70\x70\xbe\x70\xbe\x00\xc2\x17\x30\x3e\x5f\x1b\x5d\xc0\x17\x16\x13\x57\x94\x80\x16\xa0\xd7\x04\xd3\x02\xe3\x35\xc1\x42\xac\xf4\x16\x25\xc1\x27\x51\xf2\x04\x35\x13\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3d\x5d\x73\xe3\x38\x72\xef\xfa\x15\x5d\xe3\x87\x99\xa9\xb2\xa8\xdd\xbd\xbb\x64\xa3\x3c\xa4\x74\xf2\x4c\x45\x99\x19\xdb\x65\x79\xf7\x72\x8f\x10\xd9\xa2\x70\x22\x01\x06\x00\x2d\xeb\x52\xf9\xef\x29\x7c\x90\x22\x25\x7e\x80\xb2\x7c\x3b\x57\x6b\xbc\xcc\x88\x04\x1a\xfd\x85\xee\x46\x03\x6c\x5f\xc1\xf8\x72\x6d\x74\x05\x5f\x69\x88\x4c\x62\x04\x8a\x83\xda\x20\xcc\x32\x12\x6e\x10\x96\x7c\xad\x76\x44\x20\x7c\xe6\x39\x8b\x88\x [...]
 		},
 		"/crd/bases/camel.apache.org_camelcatalogs.yaml": &vfsgenÛ°CompressedFileInfo{
 			name:             "camel.apache.org_camelcatalogs.yaml",
@@ -138,9 +138,9 @@ var assets = func() http.FileSystem {
 		"/crd/bases/camel.apache.org_integrationplatforms.yaml": &vfsgenÛ°CompressedFileInfo{
 			name:             "camel.apache.org_integrationplatforms.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 26080,
+			uncompressedSize: 22714,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3c\x4b\x93\xe3\xb6\xd1\x77\xfd\x8a\xae\xd5\x61\xed\xaa\x11\x65\x7f\x8f\x4a\xa2\x1c\x52\xb2\x76\xb7\xa2\xec\xee\xcc\xd4\x4a\x6b\xc7\x47\x88\x6c\x49\xb0\x48\x80\x01\xc0\xd1\xca\xa9\xfc\xf7\x54\x37\x48\x89\x1a\xf1\xa5\x99\x71\x25\xb6\x89\xcb\x8c\x44\xa0\xd1\xef\x07\xd0\xe2\x10\x46\x2f\x37\x06\x43\xf8\x20\x43\x54\x16\x23\x70\x1a\xdc\x16\x61\x9a\x8a\x70\x8b\xb0\xd0\x6b\xb7\x17\x06\xe1\x9d\xce\x54\x24\x9c\xd4\x0a\xbe\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3c\x4b\x8f\xe3\xb8\xd1\x77\xff\x8a\xc2\xf8\x30\xbb\x40\x5b\xde\xfd\xbe\x04\x49\x9c\x43\xe0\xf5\xcc\x20\x4e\xcf\x74\x37\xda\x9e\xdd\xec\x91\x96\xca\x36\xd7\x12\xa9\x90\x54\x7b\xbc\x41\xfe\x7b\x50\x45\xc9\x96\xdb\x7a\xf5\x63\x91\x64\x20\x5e\xba\x2d\x91\xc5\x7a\x57\xb1\x58\xd0\x10\x46\xaf\x37\x06\x43\xf8\x28\x43\x54\x16\x23\x70\x1a\xdc\x16\x61\x9a\x8a\x70\x8b\xb0\xd0\x6b\xb7\x17\x06\xe1\x83\xce\x54\x24\x9c\xd4\x0a\x [...]
 		},
 		"/crd/bases/camel.apache.org_integrations.yaml": &vfsgenÛ°CompressedFileInfo{
 			name:             "camel.apache.org_integrations.yaml",
@@ -555,9 +555,9 @@ var assets = func() http.FileSystem {
 		"/traits.yaml": &vfsgenÛ°CompressedFileInfo{
 			name:             "traits.yaml",
 			modTime:          time.Time{},
-			uncompressedSize: 50652,
+			uncompressedSize: 51377,
 
-			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\xbd\x7d\x73\x1c\xb9\x91\x27\xfc\xff\x7c\x0a\x04\xfd\x44\x88\x64\x74\x37\x35\xe3\xb5\x3d\x0f\xef\xb4\x3e\x8e\x24\xdb\x9c\xd1\x0b\x4f\x92\xc7\xe7\xd0\x29\xdc\xe8\xaa\xec\x6e\xa8\xab\x81\x32\x80\x22\xd5\x3e\xdf\x77\xbf\x40\x66\xe2\xa5\xaa\x9b\x64\x53\x12\x67\xcd\x8d\x5d\x47\xec\x88\x64\x01\x48\x24\x12\x89\x44\xe6\x2f\x13\xde\x4a\xe5\xdd\xe9\x37\x63\xa1\xe5\x1a\x4e\x85\x9c\xcf\x95\x56\x7e\xf3\x8d\x10\x6d\x23\xfd\xdc\x [...]
+			compressedContent: []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x7d\xfd\x73\x5b\xb9\x91\xe0\xef\xf3\x57\xa0\xb4\x57\x65\xc9\x45\x52\x9e\xc9\x26\x99\xd3\xdd\x6c\x4e\x63\x7b\x12\xcd\xf8\x43\x67\x6b\x26\x9b\xf2\xb9\x42\xf0\xbd\x26\x09\xeb\x11\x78\x01\xf0\x24\x33\x97\xfb\xdf\xaf\xd0\xdd\xf8\x78\x8f\xa4\x44\xd9\xd6\x6c\xb4\xb5\x9b\xaa\x1d\x4b\x7a\x00\x1a\x8d\x46\x7f\x77\xc3\x5b\xa9\xbc\x3b\xf9\x6a\x2c\xb4\x5c\xc1\x89\x90\xf3\xb9\xd2\xca\xaf\xbf\x12\xa2\x6d\xa4\x9f\x1b\xbb\x3a\x11\x [...]
 		},
 	}
 	fs["/"].(*vfsgenÛ°DirInfo).entries = []os.FileInfo{

[camel-k] 21/31: fix(jvm): Quote HTTP proxy system property values

Posted by as...@apache.org.
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 aa89ed2d423f855aad2aaabf5bde583801063b34
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 10 14:57:11 2022 +0100

    fix(jvm): Quote HTTP proxy system property values
---
 pkg/trait/jvm.go | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 3c5fa6c..e1bc3e4 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -179,15 +179,15 @@ func (t *jvmTrait) Apply(e *Environment) error {
 			return err
 		}
 		if !util.StringSliceContainsAnyOf(t.Options, "http.proxyHost") {
-			args = append(args, "-Dhttp.proxyHost="+u.Hostname())
+			args = append(args, fmt.Sprintf("-Dhttp.proxyHost=%q", u.Hostname()))
 		}
 		if port := u.Port(); !util.StringSliceContainsAnyOf(t.Options, "http.proxyPort") && port != "" {
-			args = append(args, "-Dhttp.proxyPort="+u.Port())
+			args = append(args, fmt.Sprintf("-Dhttp.proxyPort=%q", u.Port()))
 		}
 		if user := u.User; !util.StringSliceContainsAnyOf(t.Options, "http.proxyUser") && user != nil {
-			args = append(args, "-Dhttp.proxyUser="+user.Username())
+			args = append(args, fmt.Sprintf("-Dhttp.proxyUser=%q", user.Username()))
 			if password, ok := user.Password(); !util.StringSliceContainsAnyOf(t.Options, "http.proxyUser") && ok {
-				args = append(args, "-Dhttp.proxyPassword="+password)
+				args = append(args, fmt.Sprintf("-Dhttp.proxyPassword=%q", password))
 			}
 		}
 	}
@@ -198,15 +198,15 @@ func (t *jvmTrait) Apply(e *Environment) error {
 			return err
 		}
 		if !util.StringSliceContainsAnyOf(t.Options, "https.proxyHost") {
-			args = append(args, "-Dhttps.proxyHost="+u.Hostname())
+			args = append(args, fmt.Sprintf("-Dhttps.proxyHost=%q", u.Hostname()))
 		}
 		if port := u.Port(); !util.StringSliceContainsAnyOf(t.Options, "https.proxyPort") && port != "" {
-			args = append(args, "-Dhttps.proxyPort="+u.Port())
+			args = append(args, fmt.Sprintf("-Dhttps.proxyPort=%q", u.Port()))
 		}
 		if user := u.User; !util.StringSliceContainsAnyOf(t.Options, "https.proxyUser") && user != nil {
-			args = append(args, "-Dhttps.proxyUser="+user.Username())
+			args = append(args, fmt.Sprintf("-Dhttps.proxyUser=%q", user.Username()))
 			if password, ok := user.Password(); !util.StringSliceContainsAnyOf(t.Options, "https.proxyUser") && ok {
-				args = append(args, "-Dhttps.proxyPassword="+password)
+				args = append(args, fmt.Sprintf("-Dhttps.proxyPassword=%q", password))
 			}
 		}
 	}
@@ -220,7 +220,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
 					hosts[i] = strings.Replace(host, ".", "*.", 1)
 				}
 			}
-			args = append(args, "-Dhttp.nonProxyHosts="+strings.Join(hosts, "|"))
+			args = append(args, fmt.Sprintf("-Dhttp.nonProxyHosts=%q", strings.Join(hosts, "|")))
 		}
 	}
 

[camel-k] 02/31: feat(maven): Honor proxy environment variables

Posted by as...@apache.org.
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 8993eca031437c65ef66567ca080cb780dd38852
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Jan 6 17:57:59 2022 +0100

    feat(maven): Honor proxy environment variables
---
 pkg/builder/project.go                |  5 ++-
 pkg/trait/openapi.go                  | 15 ++++---
 pkg/util/camel/catalog.go             |  5 ++-
 pkg/util/maven/maven_proxies.go       | 75 +++++++++++++++++++++++++++++++++++
 pkg/util/maven/maven_settings.go      | 35 +++++++++-------
 pkg/util/maven/maven_settings_test.go |  7 +++-
 pkg/util/maven/maven_types.go         | 12 ++++++
 7 files changed, 131 insertions(+), 23 deletions(-)

diff --git a/pkg/builder/project.go b/pkg/builder/project.go
index e9cd843..06de5ed 100644
--- a/pkg/builder/project.go
+++ b/pkg/builder/project.go
@@ -94,7 +94,10 @@ func generateProjectSettings(ctx *builderContext) error {
 		ctx.Maven.UserSettings = []byte(val)
 	}
 
-	settings := maven.NewSettings()
+	settings, err := maven.NewSettings(maven.ProxyFromEnvironment)
+	if err != nil {
+		return err
+	}
 	data, err := settings.MarshalBytes()
 	if err != nil {
 		return err
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index 1961355..bc262b7 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -34,7 +34,7 @@ import (
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/runtime/schema"
 
-	"sigs.k8s.io/controller-runtime/pkg/client"
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/util"
@@ -191,7 +191,7 @@ func (t *openAPITrait) generateFromDataSpecs(e *Environment, tmpDir string, spec
 
 func (t *openAPITrait) generateOpenAPIConfigMap(e *Environment, resource v1.DataSpec, tmpDir, generatedContentName string) error {
 	cm := corev1.ConfigMap{}
-	key := client.ObjectKey{
+	key := ctrl.ObjectKey{
 		Namespace: e.Integration.Namespace,
 		Name:      generatedContentName,
 	}
@@ -262,12 +262,15 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Dat
 		mc.UserSettings = []byte(settings)
 	}
 
-	settings := maven.NewSettings()
-	data, err := settings.MarshalBytes()
-	if err != nil {
+	if settings, err := maven.NewSettings(maven.ProxyFromEnvironment); err != nil {
 		return err
+	} else {
+		data, err := settings.MarshalBytes()
+		if err != nil {
+			return err
+		}
+		mc.GlobalSettings = data
 	}
-	mc.GlobalSettings = data
 
 	if e.Platform.Status.Build.Maven.CASecret != nil {
 		certData, err := kubernetes.GetSecretRefData(e.Ctx, e.Client, e.Platform.Namespace, e.Platform.Status.Build.Maven.CASecret)
diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go
index 88df86d..ad05456 100644
--- a/pkg/util/camel/catalog.go
+++ b/pkg/util/camel/catalog.go
@@ -84,7 +84,10 @@ func GenerateCatalog(
 	if err != nil {
 		return nil, err
 	}
-	settings := maven.NewSettings()
+	settings, err := maven.NewSettings(maven.ProxyFromEnvironment)
+	if err != nil {
+		return nil, err
+	}
 	globalSettings, err := settings.MarshalBytes()
 	if err != nil {
 		return nil, err
diff --git a/pkg/util/maven/maven_proxies.go b/pkg/util/maven/maven_proxies.go
new file mode 100644
index 0000000..4418ea5
--- /dev/null
+++ b/pkg/util/maven/maven_proxies.go
@@ -0,0 +1,75 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package maven
+
+import (
+	"net/url"
+	"os"
+	"strings"
+)
+
+var ProxyFromEnvironment = proxyFromEnvironment{}
+
+type proxyFromEnvironment struct{}
+
+func (_ proxyFromEnvironment) apply(settings *Settings) error {
+	if httpProxy := os.Getenv("HTTP_PROXY"); httpProxy != "" {
+		proxy, err := parseProxyFromEnvVar(httpProxy)
+		if err != nil {
+			return err
+		}
+		settings.Proxies = append(settings.Proxies, proxy)
+	}
+
+	if httpsProxy := os.Getenv("HTTPS_PROXY"); httpsProxy != "" {
+		proxy, err := parseProxyFromEnvVar(httpsProxy)
+		if err != nil {
+			return err
+		}
+		settings.Proxies = append(settings.Proxies, proxy)
+	}
+
+	return nil
+}
+
+func parseProxyFromEnvVar(proxyEnvVar string) (Proxy, error) {
+	u, err := url.Parse(proxyEnvVar)
+	if err != nil {
+		return Proxy{}, err
+	}
+	proxy := Proxy{
+		Active:   true,
+		Protocol: u.Scheme,
+		Host:     u.Hostname(),
+		Port:     u.Port(),
+	}
+	if user := u.User; user != nil {
+		proxy.Username = user.Username()
+		if password, set := user.Password(); set {
+			proxy.Password = password
+		}
+	}
+	if noProxy := os.Getenv("NO_PROXY"); noProxy != "" {
+		nonProxyHosts := strings.ReplaceAll(noProxy, " ", "")
+		nonProxyHosts = strings.ReplaceAll(nonProxyHosts, ",", "|")
+		nonProxyHosts = strings.ReplaceAll(nonProxyHosts, "|.", "|*.")
+		proxy.NonProxyHosts = nonProxyHosts
+	}
+
+	return proxy, nil
+}
diff --git a/pkg/util/maven/maven_settings.go b/pkg/util/maven/maven_settings.go
index b9da8bf..8d61c49 100644
--- a/pkg/util/maven/maven_settings.go
+++ b/pkg/util/maven/maven_settings.go
@@ -18,7 +18,6 @@ limitations under the License.
 package maven
 
 import (
-	"bytes"
 	"encoding/xml"
 	"strings"
 
@@ -34,30 +33,38 @@ import (
 var DefaultMavenRepositories = "https://repo.maven.apache.org/maven2@id=central"
 
 func (s Settings) MarshalBytes() ([]byte, error) {
-	w := &bytes.Buffer{}
-	w.WriteString(xml.Header)
-
-	e := xml.NewEncoder(w)
-	e.Indent("", "  ")
-
-	if err := e.Encode(s); err != nil {
-		return []byte{}, err
-	}
+	return util.EncodeXML(s)
+}
 
-	return w.Bytes(), nil
+type SettingsOption interface {
+	apply(settings *Settings) error
 }
 
-func NewSettings() Settings {
-	return Settings{
+func NewSettings(options ...SettingsOption) (Settings, error) {
+	settings := Settings{
 		XMLName:           xml.Name{Local: "settings"},
 		XMLNs:             "http://maven.apache.org/SETTINGS/1.0.0",
 		XMLNsXsi:          "http://www.w3.org/2001/XMLSchema-instance",
 		XsiSchemaLocation: "http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd",
 	}
+
+	for _, option := range options {
+		err := option.apply(&settings)
+		if err != nil {
+			return Settings{}, err
+		}
+	}
+
+	return settings, nil
 }
 
 func NewDefaultSettings(repositories []v1.Repository, mirrors []Mirror) Settings {
-	settings := NewSettings()
+	settings := Settings{
+		XMLName:           xml.Name{Local: "settings"},
+		XMLNs:             "http://maven.apache.org/SETTINGS/1.0.0",
+		XMLNsXsi:          "http://www.w3.org/2001/XMLSchema-instance",
+		XsiSchemaLocation: "http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd",
+	}
 
 	var additionalRepos []v1.Repository
 	for _, defaultRepo := range defaultMavenRepositories() {
diff --git a/pkg/util/maven/maven_settings_test.go b/pkg/util/maven/maven_settings_test.go
index a6b6a6a..eabe87f 100644
--- a/pkg/util/maven/maven_settings_test.go
+++ b/pkg/util/maven/maven_settings_test.go
@@ -54,6 +54,7 @@ const expectedSettings = `<?xml version="1.0" encoding="UTF-8"?>
       <pluginRepositories></pluginRepositories>
     </profile>
   </profiles>
+  <proxies></proxies>
   <mirrors></mirrors>
 </settings>`
 
@@ -97,6 +98,7 @@ const expectedDefaultSettings = `<?xml version="1.0" encoding="UTF-8"?>
       </pluginRepositories>
     </profile>
   </profiles>
+  <proxies></proxies>
   <mirrors></mirrors>
 </settings>`
 
@@ -164,6 +166,7 @@ const expectedDefaultSettingsWithExtraRepo = `<?xml version="1.0" encoding="UTF-
       </pluginRepositories>
     </profile>
   </profiles>
+  <proxies></proxies>
   <mirrors>
     <mirror>
       <id>foo</id>
@@ -174,7 +177,9 @@ const expectedDefaultSettingsWithExtraRepo = `<?xml version="1.0" encoding="UTF-
 </settings>`
 
 func TestSettingsGeneration(t *testing.T) {
-	settings := NewSettings()
+	settings, err := NewSettings()
+	assert.Nil(t, err)
+
 	settings.LocalRepository = "/tmp/artifacts/m2"
 	settings.Profiles = []Profile{
 		{
diff --git a/pkg/util/maven/maven_types.go b/pkg/util/maven/maven_types.go
index 0874d0f..3a078bf 100644
--- a/pkg/util/maven/maven_types.go
+++ b/pkg/util/maven/maven_types.go
@@ -60,6 +60,7 @@ type Settings struct {
 	XsiSchemaLocation string    `xml:"xsi:schemaLocation,attr"`
 	LocalRepository   string    `xml:"localRepository"`
 	Profiles          []Profile `xml:"profiles>profile,omitempty"`
+	Proxies           []Proxy   `xml:"proxies>proxy,omitempty"`
 	Mirrors           []Mirror  `xml:"mirrors>mirror,omitempty"`
 }
 
@@ -120,3 +121,14 @@ type PropertyActivation struct {
 	Name  string `xml:"name"`
 	Value string `xml:"value"`
 }
+
+type Proxy struct {
+	ID            string `xml:"id"`
+	Active        bool   `xml:"active"`
+	Protocol      string `xml:"protocol"`
+	Host          string `xml:"host"`
+	Port          string `xml:"port,omitempty"`
+	Username      string `xml:"username,omitempty"`
+	Password      string `xml:"password,omitempty"`
+	NonProxyHosts string `xml:"nonProxyHosts,omitempty"`
+}

[camel-k] 03/31: chore(maven): Default to standard HTTP and HTTPS port numbers

Posted by as...@apache.org.
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 05a2737d66879c749b6f06a594d9bbae63c0773a
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Jan 6 17:59:40 2022 +0100

    chore(maven): Default to standard HTTP and HTTPS port numbers
---
 pkg/util/maven/maven_proxies.go | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/pkg/util/maven/maven_proxies.go b/pkg/util/maven/maven_proxies.go
index 4418ea5..abb8a91 100644
--- a/pkg/util/maven/maven_proxies.go
+++ b/pkg/util/maven/maven_proxies.go
@@ -58,6 +58,14 @@ func parseProxyFromEnvVar(proxyEnvVar string) (Proxy, error) {
 		Host:     u.Hostname(),
 		Port:     u.Port(),
 	}
+	if proxy.Port == "" {
+		switch proxy.Protocol {
+		case "http":
+			proxy.Port = "80"
+		case "https":
+			proxy.Port = "443"
+		}
+	}
 	if user := u.User; user != nil {
 		proxy.Username = user.Username()
 		if password, set := user.Password(); set {

[camel-k] 16/31: chore(e2e): Add environment trait e2e tests

Posted by as...@apache.org.
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 52fd932bb698ffde98fabb609915a6ad75ce478e
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 10 12:50:10 2022 +0100

    chore(e2e): Add environment trait e2e tests
---
 e2e/common/build/maven_http_proxy_test.go |   2 +-
 e2e/common/traits/environment_test.go     | 115 ++++++++++++++++++++++++++++++
 2 files changed, 116 insertions(+), 1 deletion(-)

diff --git a/e2e/common/build/maven_http_proxy_test.go b/e2e/common/build/maven_http_proxy_test.go
index ef7a6f3..dfc6e0f 100644
--- a/e2e/common/build/maven_http_proxy_test.go
+++ b/e2e/common/build/maven_http_proxy_test.go
@@ -309,7 +309,7 @@ ProxyVia Off
 		// Install Camel K with the HTTP proxy
 		Expect(Kamel("install", "-n", ns,
 			"--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://%s", hostname),
-			// FIXME: TLS handshake issue
+			// TODO: enable TLS for the HTTPS proxy when Maven supports it
 			// "--operator-env-vars", fmt.Sprintf("HTTPS_PROXY=https://%s", hostname),
 			// "--maven-ca-secret", secret.Name+"/"+corev1.TLSCertKey,
 			"--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","),
diff --git a/e2e/common/traits/environment_test.go b/e2e/common/traits/environment_test.go
new file mode 100644
index 0000000..630c9ad
--- /dev/null
+++ b/e2e/common/traits/environment_test.go
@@ -0,0 +1,115 @@
+//go:build integration
+// +build integration
+
+// To enable compilation of this file in Goland, go to "Settings -> Go -> Vendoring & Build Tags -> Custom Tags" and add "integration"
+
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package traits
+
+import (
+	"fmt"
+	"strings"
+	"testing"
+
+	. "github.com/onsi/gomega"
+
+	corev1 "k8s.io/api/core/v1"
+
+	. "github.com/apache/camel-k/e2e/support"
+	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
+	"github.com/apache/camel-k/pkg/util/defaults"
+)
+
+func TestEnvironmentTrait(t *testing.T) {
+	WithNewTestNamespace(t, func(ns string) {
+		// Retrieve the Kubernetes Service ClusterIPs to populate the NO_PROXY environment variable
+		svc := Service("default", "kubernetes")()
+		Expect(svc).NotTo(BeNil())
+
+		noProxy := []string{
+			".cluster.local",
+			".svc",
+			"localhost",
+		}
+		noProxy = append(noProxy, svc.Spec.ClusterIPs...)
+
+		// Install Camel K with the HTTP proxy environment variable
+		Expect(Kamel("install", "-n", ns,
+			"--operator-env-vars", fmt.Sprintf("HTTP_PROXY=http://proxy"),
+			"--operator-env-vars", "NO_PROXY="+strings.Join(noProxy, ","),
+		).Execute()).To(Succeed())
+
+		t.Run("Run integration with default environment", func(t *testing.T) {
+			Expect(Kamel("run", "-n", ns, "files/Java.java").Execute()).To(Succeed())
+			Eventually(IntegrationPodPhase(ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
+			Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+
+			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
+				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
+				ContainElement(corev1.EnvVar{Name: "NAMESPACE", Value: ns}),
+				ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: "http://proxy"}),
+				ContainElement(corev1.EnvVar{Name: "NO_PROXY", Value: strings.Join(noProxy, ",")}),
+			)))
+		})
+
+		t.Run("Run integration with custom environment", func(t *testing.T) {
+			Expect(Kamel("run", "-n", ns, "files/Java.java",
+				"-t", "environment.vars=\"HTTP_PROXY=http://custom.proxy\"",
+			).Execute()).To(Succeed())
+			Eventually(IntegrationPodPhase(ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
+			Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+
+			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
+				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
+				ContainElement(corev1.EnvVar{Name: "NAMESPACE", Value: ns}),
+				ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: "http://custom.proxy"}),
+				ContainElement(corev1.EnvVar{Name: "NO_PROXY", Value: strings.Join(noProxy, ",")}),
+			)))
+		})
+
+		t.Run("Run integration without default HTTP proxy environment", func(t *testing.T) {
+			Expect(Kamel("run", "-n", ns, "files/Java.java",
+				"-t", "environment.http-proxy=false",
+			).Execute()).To(Succeed())
+			Eventually(IntegrationPodPhase(ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
+			Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+
+			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
+				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
+				ContainElement(corev1.EnvVar{Name: "NAMESPACE", Value: ns}),
+				Not(ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: "http://proxy"})),
+				Not(ContainElement(corev1.EnvVar{Name: "NO_PROXY", Value: strings.Join(noProxy, ",")})),
+			)))
+		})
+
+		Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
+	})
+}
+
+func podEnvVars(pod *corev1.Pod) []corev1.EnvVar {
+	for _, container := range pod.Spec.Containers {
+		if container.Name == "integration" {
+			return container.Env
+		}
+	}
+	return nil
+}

[camel-k] 20/31: fix(jvm): NO_PROXY translates to -Dhttp.nonProxyHosts

Posted by as...@apache.org.
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 98bed0fc249be8d508a1ba9665843089497a0f9e
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 10 14:56:21 2022 +0100

    fix(jvm): NO_PROXY translates to -Dhttp.nonProxyHosts
---
 pkg/trait/jvm.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 57d442a..3c5fa6c 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -220,7 +220,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
 					hosts[i] = strings.Replace(host, ".", "*.", 1)
 				}
 			}
-			args = append(args, "-Dhttps.nonProxyHosts="+strings.Join(hosts, "|"))
+			args = append(args, "-Dhttp.nonProxyHosts="+strings.Join(hosts, "|"))
 		}
 	}
 

[camel-k] 07/31: fix(proxy): HTTPS proxy can use HTTP scheme

Posted by as...@apache.org.
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 e094e36e932be7dfe911591fbc2dceaf9c4c9519
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Jan 7 12:38:11 2022 +0100

    fix(proxy): HTTPS proxy can use HTTP scheme
---
 pkg/util/maven/maven_proxies.go | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/pkg/util/maven/maven_proxies.go b/pkg/util/maven/maven_proxies.go
index aa57d4d..91e0790 100644
--- a/pkg/util/maven/maven_proxies.go
+++ b/pkg/util/maven/maven_proxies.go
@@ -33,6 +33,7 @@ func (_ proxyFromEnvironment) apply(settings *Settings) error {
 		if err != nil {
 			return err
 		}
+		proxy.ID = "http-proxy"
 		settings.Proxies = append(settings.Proxies, proxy)
 	}
 
@@ -41,6 +42,7 @@ func (_ proxyFromEnvironment) apply(settings *Settings) error {
 		if err != nil {
 			return err
 		}
+		proxy.ID = "https-proxy"
 		settings.Proxies = append(settings.Proxies, proxy)
 	}
 
@@ -58,15 +60,11 @@ func parseProxyFromEnvVar(proxyEnvVar string) (Proxy, error) {
 		Host:     u.Hostname(),
 		Port:     u.Port(),
 	}
-	switch proxy.Protocol {
-	case "http":
-		proxy.ID = "http-proxy"
-		if proxy.Port == "" {
+	if proxy.Port == "" {
+		switch proxy.Protocol {
+		case "http":
 			proxy.Port = "80"
-		}
-	case "https":
-		proxy.ID = "https-proxy"
-		if proxy.Port == "" {
+		case "https":
 			proxy.Port = "443"
 		}
 	}

[camel-k] 22/31: fix(e2e): Add Maven repositories to NO_PROXY

Posted by as...@apache.org.
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 254c8e71562b8421abe646fc2fa6b40477c5ab2c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 10 18:29:26 2022 +0100

    fix(e2e): Add Maven repositories to NO_PROXY
---
 e2e/common/traits/environment_test.go | 1 +
 1 file changed, 1 insertion(+)

diff --git a/e2e/common/traits/environment_test.go b/e2e/common/traits/environment_test.go
index 630c9ad..57c0201 100644
--- a/e2e/common/traits/environment_test.go
+++ b/e2e/common/traits/environment_test.go
@@ -46,6 +46,7 @@ func TestEnvironmentTrait(t *testing.T) {
 			".cluster.local",
 			".svc",
 			"localhost",
+			".apache.org",
 		}
 		noProxy = append(noProxy, svc.Spec.ClusterIPs...)
 

[camel-k] 12/31: chore: Fix lints

Posted by as...@apache.org.
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 9d35c0525730001b82ede7c1dcb0fd5bf81cc8c4
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Jan 7 19:00:59 2022 +0100

    chore: Fix lints
---
 pkg/platform/defaults.go             |  4 ++--
 pkg/trait/openapi.go                 | 14 +++++++-------
 pkg/util/maven/maven_proxies.go      |  2 +-
 pkg/util/maven/maven_repositories.go |  1 +
 4 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/pkg/platform/defaults.go b/pkg/platform/defaults.go
index 8355b32..29c5dd0 100644
--- a/pkg/platform/defaults.go
+++ b/pkg/platform/defaults.go
@@ -84,7 +84,7 @@ func ConfigureDefaults(ctx context.Context, c client.Client, p *v1.IntegrationPl
 		}
 	}
 
-	err := setPlatformDefaults(ctx, c, p, verbose)
+	err := setPlatformDefaults(p, verbose)
 	if err != nil {
 		return err
 	}
@@ -152,7 +152,7 @@ func configureRegistry(ctx context.Context, c client.Client, p *v1.IntegrationPl
 	return nil
 }
 
-func setPlatformDefaults(ctx context.Context, c client.Client, p *v1.IntegrationPlatform, verbose bool) error {
+func setPlatformDefaults(p *v1.IntegrationPlatform, verbose bool) error {
 	if p.Status.Build.RuntimeVersion == "" {
 		p.Status.Build.RuntimeVersion = defaults.DefaultRuntimeVersion
 	}
diff --git a/pkg/trait/openapi.go b/pkg/trait/openapi.go
index 5cc3d4f..22d2eb5 100644
--- a/pkg/trait/openapi.go
+++ b/pkg/trait/openapi.go
@@ -262,15 +262,15 @@ func (t *openAPITrait) createNewOpenAPIConfigMap(e *Environment, resource v1.Dat
 		mc.UserSettings = []byte(settings)
 	}
 
-	if settings, err := maven.NewSettings(maven.DefaultRepositories, maven.ProxyFromEnvironment); err != nil {
+	settings, err := maven.NewSettings(maven.DefaultRepositories, maven.ProxyFromEnvironment)
+	if err != nil {
+		return err
+	}
+	data, err := settings.MarshalBytes()
+	if err != nil {
 		return err
-	} else {
-		data, err := settings.MarshalBytes()
-		if err != nil {
-			return err
-		}
-		mc.GlobalSettings = data
 	}
+	mc.GlobalSettings = data
 
 	if e.Platform.Status.Build.Maven.CASecret != nil {
 		certData, err := kubernetes.GetSecretRefData(e.Ctx, e.Client, e.Platform.Namespace, e.Platform.Status.Build.Maven.CASecret)
diff --git a/pkg/util/maven/maven_proxies.go b/pkg/util/maven/maven_proxies.go
index 91e0790..e767800 100644
--- a/pkg/util/maven/maven_proxies.go
+++ b/pkg/util/maven/maven_proxies.go
@@ -27,7 +27,7 @@ var ProxyFromEnvironment = proxyFromEnvironment{}
 
 type proxyFromEnvironment struct{}
 
-func (_ proxyFromEnvironment) apply(settings *Settings) error {
+func (proxyFromEnvironment) apply(settings *Settings) error {
 	if httpProxy := os.Getenv("HTTP_PROXY"); httpProxy != "" {
 		proxy, err := parseProxyFromEnvVar(httpProxy)
 		if err != nil {
diff --git a/pkg/util/maven/maven_repositories.go b/pkg/util/maven/maven_repositories.go
index 2576cbb..e35d686 100644
--- a/pkg/util/maven/maven_repositories.go
+++ b/pkg/util/maven/maven_repositories.go
@@ -27,6 +27,7 @@ var DefaultRepositories = &defaultRepositories{}
 
 type defaultRepositories struct{}
 
+// nolint: unparam
 func (o defaultRepositories) apply(settings *Settings) error {
 	for _, repository := range defaultMavenRepositories() {
 		upsertRepository(repository, &settings.Profiles[0].Repositories)

[camel-k] 31/31: chore(e2e): Move HTTPD resources creation in separate functions

Posted by as...@apache.org.
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 863887e33acb66f3495a154f75ac2fb86e24678c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Wed Jan 12 11:52:01 2022 +0100

    chore(e2e): Move HTTPD resources creation in separate functions
---
 e2e/common/build/maven_http_proxy_test.go | 363 ++++++++++++++++--------------
 1 file changed, 188 insertions(+), 175 deletions(-)

diff --git a/e2e/common/build/maven_http_proxy_test.go b/e2e/common/build/maven_http_proxy_test.go
index 9bbcbe3..4197672 100644
--- a/e2e/common/build/maven_http_proxy_test.go
+++ b/e2e/common/build/maven_http_proxy_test.go
@@ -49,10 +49,11 @@ import (
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 )
 
+var httpdTlsMountPath = "/etc/tls/private"
+
 func TestMavenProxy(t *testing.T) {
 	WithNewTestNamespace(t, func(ns string) {
 		hostname := fmt.Sprintf("%s.%s.svc", "proxy", ns)
-		tlsMountPath := "/etc/tls/private"
 
 		// Generate the TLS certificate
 		serialNumber := big.NewInt(rand2.Int63())
@@ -107,184 +108,15 @@ func TestMavenProxy(t *testing.T) {
 		}
 		Expect(TestClient().Create(TestContext, secret)).To(Succeed())
 
-		// HTTPD configuration
-		config := &corev1.ConfigMap{
-			TypeMeta: metav1.TypeMeta{
-				Kind:       "ConfigMap",
-				APIVersion: corev1.SchemeGroupVersion.String(),
-			},
-			ObjectMeta: metav1.ObjectMeta{
-				Namespace: ns,
-				Name:      "httpd-config",
-			},
-			Data: map[string]string{
-				"httpd.conf": fmt.Sprintf(`
-ServerRoot "/etc/httpd
-
-PidFile /var/run/httpd/httpd.pid"
-
-LoadModule mpm_event_module /usr/local/apache2/modules/mod_mpm_event.so
-LoadModule authn_core_module /usr/local/apache2/modules/mod_authn_core.so
-LoadModule authz_core_module /usr/local/apache2/modules/mod_authz_core.so
-LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
-LoadModule proxy_http_module /usr/local/apache2/modules/mod_proxy_http.so
-LoadModule proxy_connect_module /usr/local/apache2/modules/mod_proxy_connect.so
-LoadModule headers_module /usr/local/apache2/modules/mod_headers.so
-LoadModule setenvif_module /usr/local/apache2/modules/mod_setenvif.so
-LoadModule version_module /usr/local/apache2/modules/mod_version.so
-LoadModule log_config_module /usr/local/apache2/modules/mod_log_config.so
-LoadModule env_module /usr/local/apache2/modules/mod_env.so
-LoadModule unixd_module /usr/local/apache2/modules/mod_unixd.so
-LoadModule status_module /usr/local/apache2/modules/mod_status.so
-LoadModule autoindex_module /usr/local/apache2/modules/mod_autoindex.so
-LoadModule ssl_module /usr/local/apache2/modules/mod_ssl.so
-
-Mutex posixsem
-
-LogFormat "%%h %%l %%u %%t \"%%r\" %%>s %%b" common
-CustomLog /dev/stdout common
-ErrorLog /dev/stderr
-
-LogLevel warn
-
-Listen 8080
-Listen 8443
-
-ServerName %s
-
-ProxyRequests On
-ProxyVia Off
-
-<VirtualHost *:8443>
-  SSLEngine on
-
-  SSLCertificateFile "%s/%s"
-  SSLCertificateKeyFile "%s/%s"
-
-  AllowEncodedSlashes NoDecode
-</VirtualHost>
-`,
-					hostname, tlsMountPath, corev1.TLSCertKey, tlsMountPath, corev1.TLSPrivateKeyKey,
-				),
-			},
-		}
+		// HTTPD ConfigMap
+		config := newHTTPDConfigMap(ns, hostname)
 		Expect(TestClient().Create(TestContext, config)).To(Succeed())
 
-		// Deploy HTTPD
-		// $ curl --proxy-cacert ca.crt --proxy https://proxy.http-proxy.svc:443 https://www.google.com
-		// https://github.com/curl/curl/pull/1127
-		deployment := &appsv1.Deployment{
-			TypeMeta: metav1.TypeMeta{
-				Kind:       "Deployment",
-				APIVersion: appsv1.SchemeGroupVersion.String(),
-			},
-			ObjectMeta: metav1.ObjectMeta{
-				Namespace: ns,
-				Name:      "proxy",
-			},
-			Spec: appsv1.DeploymentSpec{
-				Selector: &metav1.LabelSelector{
-					MatchLabels: map[string]string{
-						"app": "proxy",
-					},
-				},
-				Template: corev1.PodTemplateSpec{
-					ObjectMeta: metav1.ObjectMeta{
-						Labels: map[string]string{
-							"app": "proxy",
-						},
-					},
-					Spec: corev1.PodSpec{
-						Containers: []corev1.Container{
-							{
-								Name:    "httpd",
-								Image:   "httpd:2.4.46",
-								Command: []string{"httpd", "-f", "/etc/httpd/httpd.conf", "-DFOREGROUND"},
-								Ports: []corev1.ContainerPort{
-									{
-										Name:          "http",
-										ContainerPort: 8080,
-									},
-									{
-										Name:          "https",
-										ContainerPort: 8443,
-									},
-								},
-								VolumeMounts: []corev1.VolumeMount{
-									{
-										Name:      "tls",
-										MountPath: tlsMountPath,
-										ReadOnly:  true,
-									},
-									{
-										Name:      "httpd-conf",
-										MountPath: "/etc/httpd",
-										ReadOnly:  true,
-									},
-									{
-										Name:      "httpd-run",
-										MountPath: "/var/run/httpd",
-									},
-								},
-							},
-						},
-						Volumes: []corev1.Volume{
-							{
-								Name: "tls",
-								VolumeSource: corev1.VolumeSource{
-									Secret: &corev1.SecretVolumeSource{
-										SecretName: secret.Name,
-									},
-								},
-							},
-							{
-								Name: "httpd-conf",
-								VolumeSource: corev1.VolumeSource{
-									ConfigMap: &corev1.ConfigMapVolumeSource{
-										LocalObjectReference: corev1.LocalObjectReference{
-											Name: config.Name,
-										},
-									},
-								},
-							},
-							{
-								Name: "httpd-run",
-								VolumeSource: corev1.VolumeSource{
-									EmptyDir: &corev1.EmptyDirVolumeSource{},
-								},
-							},
-						},
-					},
-				},
-			},
-		}
+		// HTTPD Deployment
+		deployment := newHTTPDDeployment(ns, config.Name, secret.Name)
 		Expect(TestClient().Create(TestContext, deployment)).To(Succeed())
 
-		service := &corev1.Service{
-			TypeMeta: metav1.TypeMeta{
-				Kind:       "Service",
-				APIVersion: corev1.SchemeGroupVersion.String(),
-			},
-			ObjectMeta: metav1.ObjectMeta{
-				Namespace: ns,
-				Name:      deployment.Name,
-			},
-			Spec: corev1.ServiceSpec{
-				Selector: deployment.Spec.Template.Labels,
-				Ports: []corev1.ServicePort{
-					{
-						Name:       "http",
-						Port:       80,
-						TargetPort: intstr.FromString("http"),
-					},
-					{
-						Name:       "https",
-						Port:       443,
-						TargetPort: intstr.FromString("https"),
-					},
-				},
-			},
-		}
+		service := newHTTPDService(deployment)
 		Expect(TestClient().Create(TestContext, service)).To(Succeed())
 
 		// Wait for the Deployment to become ready
@@ -352,3 +184,184 @@ ProxyVia Off
 		Expect(TestClient().Delete(TestContext, config)).To(Succeed())
 	})
 }
+
+func newHTTPDConfigMap(ns, hostname string) *corev1.ConfigMap {
+	return &corev1.ConfigMap{
+		TypeMeta: metav1.TypeMeta{
+			Kind:       "ConfigMap",
+			APIVersion: corev1.SchemeGroupVersion.String(),
+		},
+		ObjectMeta: metav1.ObjectMeta{
+			Namespace: ns,
+			Name:      "httpd-config",
+		},
+		Data: map[string]string{
+			"httpd.conf": fmt.Sprintf(`
+ServerRoot "/etc/httpd
+
+PidFile /var/run/httpd/httpd.pid"
+
+LoadModule mpm_event_module /usr/local/apache2/modules/mod_mpm_event.so
+LoadModule authn_core_module /usr/local/apache2/modules/mod_authn_core.so
+LoadModule authz_core_module /usr/local/apache2/modules/mod_authz_core.so
+LoadModule proxy_module /usr/local/apache2/modules/mod_proxy.so
+LoadModule proxy_http_module /usr/local/apache2/modules/mod_proxy_http.so
+LoadModule proxy_connect_module /usr/local/apache2/modules/mod_proxy_connect.so
+LoadModule headers_module /usr/local/apache2/modules/mod_headers.so
+LoadModule setenvif_module /usr/local/apache2/modules/mod_setenvif.so
+LoadModule version_module /usr/local/apache2/modules/mod_version.so
+LoadModule log_config_module /usr/local/apache2/modules/mod_log_config.so
+LoadModule env_module /usr/local/apache2/modules/mod_env.so
+LoadModule unixd_module /usr/local/apache2/modules/mod_unixd.so
+LoadModule status_module /usr/local/apache2/modules/mod_status.so
+LoadModule autoindex_module /usr/local/apache2/modules/mod_autoindex.so
+LoadModule ssl_module /usr/local/apache2/modules/mod_ssl.so
+
+Mutex posixsem
+
+LogFormat "%%h %%l %%u %%t \"%%r\" %%>s %%b" common
+CustomLog /dev/stdout common
+ErrorLog /dev/stderr
+
+LogLevel warn
+
+Listen 8080
+Listen 8443
+
+ServerName %s
+
+ProxyRequests On
+ProxyVia Off
+
+<VirtualHost *:8443>
+  SSLEngine on
+
+  SSLCertificateFile "%s/%s"
+  SSLCertificateKeyFile "%s/%s"
+
+  AllowEncodedSlashes NoDecode
+</VirtualHost>
+`,
+				hostname, httpdTlsMountPath, corev1.TLSCertKey, httpdTlsMountPath, corev1.TLSPrivateKeyKey,
+			),
+		},
+	}
+}
+
+func newHTTPDDeployment(ns, configName, secretName string) *appsv1.Deployment {
+	// $ curl --proxy-cacert ca.crt --proxy https://proxy.http-proxy.svc:443 https://www.google.com
+	// https://github.com/curl/curl/pull/1127
+	return &appsv1.Deployment{
+		TypeMeta: metav1.TypeMeta{
+			Kind:       "Deployment",
+			APIVersion: appsv1.SchemeGroupVersion.String(),
+		},
+		ObjectMeta: metav1.ObjectMeta{
+			Namespace: ns,
+			Name:      "proxy",
+		},
+		Spec: appsv1.DeploymentSpec{
+			Selector: &metav1.LabelSelector{
+				MatchLabels: map[string]string{
+					"app": "proxy",
+				},
+			},
+			Template: corev1.PodTemplateSpec{
+				ObjectMeta: metav1.ObjectMeta{
+					Labels: map[string]string{
+						"app": "proxy",
+					},
+				},
+				Spec: corev1.PodSpec{
+					Containers: []corev1.Container{
+						{
+							Name:    "httpd",
+							Image:   "httpd:2.4.46",
+							Command: []string{"httpd", "-f", "/etc/httpd/httpd.conf", "-DFOREGROUND"},
+							Ports: []corev1.ContainerPort{
+								{
+									Name:          "http",
+									ContainerPort: 8080,
+								},
+								{
+									Name:          "https",
+									ContainerPort: 8443,
+								},
+							},
+							VolumeMounts: []corev1.VolumeMount{
+								{
+									Name:      "tls",
+									MountPath: httpdTlsMountPath,
+									ReadOnly:  true,
+								},
+								{
+									Name:      "httpd-conf",
+									MountPath: "/etc/httpd",
+									ReadOnly:  true,
+								},
+								{
+									Name:      "httpd-run",
+									MountPath: "/var/run/httpd",
+								},
+							},
+						},
+					},
+					Volumes: []corev1.Volume{
+						{
+							Name: "tls",
+							VolumeSource: corev1.VolumeSource{
+								Secret: &corev1.SecretVolumeSource{
+									SecretName: secretName,
+								},
+							},
+						},
+						{
+							Name: "httpd-conf",
+							VolumeSource: corev1.VolumeSource{
+								ConfigMap: &corev1.ConfigMapVolumeSource{
+									LocalObjectReference: corev1.LocalObjectReference{
+										Name: configName,
+									},
+								},
+							},
+						},
+						{
+							Name: "httpd-run",
+							VolumeSource: corev1.VolumeSource{
+								EmptyDir: &corev1.EmptyDirVolumeSource{},
+							},
+						},
+					},
+				},
+			},
+		},
+	}
+}
+
+func newHTTPDService(deployment *appsv1.Deployment) *corev1.Service {
+	return &corev1.Service{
+		TypeMeta: metav1.TypeMeta{
+			Kind:       "Service",
+			APIVersion: corev1.SchemeGroupVersion.String(),
+		},
+		ObjectMeta: metav1.ObjectMeta{
+			Namespace: deployment.Namespace,
+			Name:      deployment.Name,
+		},
+		Spec: corev1.ServiceSpec{
+			Selector: deployment.Spec.Template.Labels,
+			Ports: []corev1.ServicePort{
+				{
+					Name:       "http",
+					Port:       80,
+					TargetPort: intstr.FromString("http"),
+				},
+				{
+					Name:       "https",
+					Port:       443,
+					TargetPort: intstr.FromString("https"),
+				},
+			},
+		},
+	}
+}

[camel-k] 27/31: fix(e2e): Use different integrations in environment trait tests

Posted by as...@apache.org.
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 39a1ea1b148f02b91be006a2e19c16faba494ca8
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 11 15:00:16 2022 +0100

    fix(e2e): Use different integrations in environment trait tests
---
 e2e/common/traits/environment_test.go | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/e2e/common/traits/environment_test.go b/e2e/common/traits/environment_test.go
index efd1ad2..80faa97 100644
--- a/e2e/common/traits/environment_test.go
+++ b/e2e/common/traits/environment_test.go
@@ -69,12 +69,13 @@ func TestEnvironmentTrait(t *testing.T) {
 		).Execute()).To(Succeed())
 
 		t.Run("Run integration with default environment", func(t *testing.T) {
-			Expect(Kamel("run", "-n", ns, "files/Java.java").Execute()).To(Succeed())
-			Eventually(IntegrationPodPhase(ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
-			Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
-			Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+			name := "java-default"
+			Expect(Kamel("run", "-n", ns, "--name", name, "files/Java.java").Execute()).To(Succeed())
+			Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
+			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
 
-			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
+			Expect(IntegrationPod(ns, name)()).To(WithTransform(podEnvVars, And(
 				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
 				ContainElement(corev1.EnvVar{Name: "NAMESPACE", ValueFrom: &corev1.EnvVarSource{
 					FieldRef: &corev1.ObjectFieldSelector{
@@ -94,14 +95,16 @@ func TestEnvironmentTrait(t *testing.T) {
 		})
 
 		t.Run("Run integration with custom environment", func(t *testing.T) {
+			name := "java-custom-proxy"
 			Expect(Kamel("run", "-n", ns, "files/Java.java",
-				"-t", "environment.vars=\"HTTP_PROXY=http://custom.proxy\"",
+				"--name", name,
+				"-t", "environment.vars=HTTP_PROXY=http://custom.proxy",
 			).Execute()).To(Succeed())
-			Eventually(IntegrationPodPhase(ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
-			Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
-			Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+			Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
+			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
 
-			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
+			Expect(IntegrationPod(ns, name)()).To(WithTransform(podEnvVars, And(
 				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
 				ContainElement(corev1.EnvVar{Name: "NAMESPACE", ValueFrom: &corev1.EnvVarSource{
 					FieldRef: &corev1.ObjectFieldSelector{
@@ -121,14 +124,16 @@ func TestEnvironmentTrait(t *testing.T) {
 		})
 
 		t.Run("Run integration without default HTTP proxy environment", func(t *testing.T) {
+			name := "java-no-proxy"
 			Expect(Kamel("run", "-n", ns, "files/Java.java",
+				"--name", name,
 				"-t", "environment.http-proxy=false",
 			).Execute()).To(Succeed())
-			Eventually(IntegrationPodPhase(ns, "java"), TestTimeoutLong).Should(Equal(corev1.PodRunning))
-			Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
-			Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
+			Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
+			Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
+			Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
 
-			Expect(IntegrationPod(ns, "java")()).To(WithTransform(podEnvVars, And(
+			Expect(IntegrationPod(ns, name)()).To(WithTransform(podEnvVars, And(
 				ContainElement(corev1.EnvVar{Name: "CAMEL_K_VERSION", Value: defaults.Version}),
 				ContainElement(corev1.EnvVar{Name: "NAMESPACE", ValueFrom: &corev1.EnvVarSource{
 					FieldRef: &corev1.ObjectFieldSelector{

[camel-k] 13/31: chore(maven): Unify settings API

Posted by as...@apache.org.
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 083c4f8d344b42e07b2fe432ca90a85a0fdb62a5
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 10 10:44:45 2022 +0100

    chore(maven): Unify settings API
---
 pkg/cmd/install.go                    | 55 +++++++++++++++-----------
 pkg/cmd/util_dependencies.go          | 21 ++--------
 pkg/util/maven/maven_repositories.go  | 44 ++++++++++++++++++++-
 pkg/util/maven/maven_settings.go      | 73 -----------------------------------
 pkg/util/maven/maven_settings_test.go | 35 +++++------------
 5 files changed, 87 insertions(+), 141 deletions(-)

diff --git a/pkg/cmd/install.go b/pkg/cmd/install.go
index 0f1225c..6807324 100644
--- a/pkg/cmd/install.go
+++ b/pkg/cmd/install.go
@@ -41,6 +41,7 @@ import (
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/client"
 	"github.com/apache/camel-k/pkg/install"
+	"github.com/apache/camel-k/pkg/util"
 	"github.com/apache/camel-k/pkg/util/kubernetes"
 	"github.com/apache/camel-k/pkg/util/maven"
 	"github.com/apache/camel-k/pkg/util/olm"
@@ -389,32 +390,14 @@ func (o *installCmdOptions) install(cobraCmd *cobra.Command, _ []string) error {
 		}
 
 		if len(o.MavenRepositories) > 0 {
-			var repositories []v1.Repository
-			var mirrors []maven.Mirror
-
-			for i, r := range o.MavenRepositories {
-				if strings.Contains(r, "@mirrorOf=") {
-					mirror := maven.NewMirror(r)
-					if mirror.ID == "" {
-						mirror.ID = fmt.Sprintf("mirror-%03d", i)
-					}
-					mirrors = append(mirrors, mirror)
-				} else {
-					repository := maven.NewRepository(r)
-					if repository.ID == "" {
-						repository.ID = fmt.Sprintf("repository-%03d", i)
-					}
-					repositories = append(repositories, repository)
-				}
+			settings, err := maven.NewSettings(maven.Repositories(o.MavenRepositories...))
+			if err != nil {
+				return err
 			}
-
-			settings := maven.NewDefaultSettings(repositories, mirrors)
-
-			err := createDefaultMavenSettingsConfigMap(o.Context, c, namespace, platform.Name, settings)
+			err = createDefaultMavenSettingsConfigMap(o.Context, c, namespace, platform.Name, settings)
 			if err != nil {
 				return err
 			}
-
 			platform.Spec.Build.Maven.Settings.ConfigMapKeyRef = &corev1.ConfigMapKeySelector{
 				LocalObjectReference: corev1.LocalObjectReference{
 					Name: platform.Name + "-maven-settings",
@@ -712,7 +695,7 @@ func decodeSecretKeySelector(secretKey string) (*corev1.SecretKeySelector, error
 }
 
 func createDefaultMavenSettingsConfigMap(ctx context.Context, client client.Client, namespace, name string, settings maven.Settings) error {
-	cm, err := maven.SettingsConfigMap(namespace, name, settings)
+	cm, err := settingsConfigMap(namespace, name, settings)
 	if err != nil {
 		return err
 	}
@@ -745,3 +728,29 @@ func createDefaultMavenSettingsConfigMap(ctx context.Context, client client.Clie
 
 	return nil
 }
+
+func settingsConfigMap(namespace string, name string, settings maven.Settings) (*corev1.ConfigMap, error) {
+	data, err := util.EncodeXML(settings)
+	if err != nil {
+		return nil, err
+	}
+
+	cm := &corev1.ConfigMap{
+		TypeMeta: metav1.TypeMeta{
+			Kind:       "ConfigMap",
+			APIVersion: corev1.SchemeGroupVersion.String(),
+		},
+		ObjectMeta: metav1.ObjectMeta{
+			Name:      name + "-maven-settings",
+			Namespace: namespace,
+			Labels: map[string]string{
+				"app": "camel-k",
+			},
+		},
+		Data: map[string]string{
+			"settings.xml": string(data),
+		},
+	}
+
+	return cm, nil
+}
diff --git a/pkg/cmd/util_dependencies.go b/pkg/cmd/util_dependencies.go
index 96b83f8..1409d7d 100644
--- a/pkg/cmd/util_dependencies.go
+++ b/pkg/cmd/util_dependencies.go
@@ -117,25 +117,10 @@ func getTransitiveDependencies(ctx context.Context, catalog *camel.RuntimeCatalo
 	mc.LocalRepository = ""
 
 	if len(repositories) > 0 {
-		var repoList []v1.Repository
-		var mirrors []maven.Mirror
-		for i, repo := range repositories {
-			if strings.Contains(repo, "@mirrorOf=") {
-				mirror := maven.NewMirror(repo)
-				if mirror.ID == "" {
-					mirror.ID = fmt.Sprintf("mirror-%03d", i)
-				}
-				mirrors = append(mirrors, mirror)
-			} else {
-				repository := maven.NewRepository(repo)
-				if repository.ID == "" {
-					repository.ID = fmt.Sprintf("repository-%03d", i)
-				}
-				repoList = append(repoList, repository)
-			}
+		settings, err := maven.NewSettings(maven.DefaultRepositories, maven.Repositories(repositories...))
+		if err != nil {
+			return nil, err
 		}
-
-		settings := maven.NewDefaultSettings(repoList, mirrors)
 		settingsData, err := util.EncodeXML(settings)
 		if err != nil {
 			return nil, err
diff --git a/pkg/util/maven/maven_repositories.go b/pkg/util/maven/maven_repositories.go
index e35d686..710dbad 100644
--- a/pkg/util/maven/maven_repositories.go
+++ b/pkg/util/maven/maven_repositories.go
@@ -18,16 +18,16 @@ limitations under the License.
 package maven
 
 import (
+	"fmt"
 	"strings"
 
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 )
 
-var DefaultRepositories = &defaultRepositories{}
+var DefaultRepositories = defaultRepositories{}
 
 type defaultRepositories struct{}
 
-// nolint: unparam
 func (o defaultRepositories) apply(settings *Settings) error {
 	for _, repository := range defaultMavenRepositories() {
 		upsertRepository(repository, &settings.Profiles[0].Repositories)
@@ -43,6 +43,36 @@ func defaultMavenRepositories() (repositories []v1.Repository) {
 	return
 }
 
+func Repositories(repositories ...string) SettingsOption {
+	return extraRepositories{
+		repositories: repositories,
+	}
+}
+
+type extraRepositories struct {
+	repositories []string
+}
+
+func (o extraRepositories) apply(settings *Settings) error {
+	for i, r := range o.repositories {
+		if strings.Contains(r, "@mirrorOf=") {
+			mirror := NewMirror(r)
+			if mirror.ID == "" {
+				mirror.ID = fmt.Sprintf("mirror-%03d", i)
+			}
+			upsertMirror(mirror, &settings.Mirrors)
+		} else {
+			repository := NewRepository(r)
+			if repository.ID == "" {
+				repository.ID = fmt.Sprintf("repository-%03d", i)
+			}
+			upsertRepository(repository, &settings.Profiles[0].Repositories)
+			upsertRepository(repository, &settings.Profiles[0].PluginRepositories)
+		}
+	}
+	return nil
+}
+
 func upsertRepository(repository v1.Repository, repositories *[]v1.Repository) {
 	for i, r := range *repositories {
 		if r.ID == repository.ID {
@@ -52,3 +82,13 @@ func upsertRepository(repository v1.Repository, repositories *[]v1.Repository) {
 	}
 	*repositories = append(*repositories, repository)
 }
+
+func upsertMirror(mirror Mirror, mirrors *[]Mirror) {
+	for i, r := range *mirrors {
+		if r.ID == mirror.ID {
+			(*mirrors)[i] = mirror
+			return
+		}
+	}
+	*mirrors = append(*mirrors, mirror)
+}
diff --git a/pkg/util/maven/maven_settings.go b/pkg/util/maven/maven_settings.go
index e1e03f3..87141c0 100644
--- a/pkg/util/maven/maven_settings.go
+++ b/pkg/util/maven/maven_settings.go
@@ -20,10 +20,6 @@ package maven
 import (
 	"encoding/xml"
 
-	corev1 "k8s.io/api/core/v1"
-	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-
-	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/util"
 )
 
@@ -64,72 +60,3 @@ func NewSettings(options ...SettingsOption) (Settings, error) {
 
 	return settings, nil
 }
-
-func NewDefaultSettings(repositories []v1.Repository, mirrors []Mirror) Settings {
-	settings := Settings{
-		XMLName:           xml.Name{Local: "settings"},
-		XMLNs:             "http://maven.apache.org/SETTINGS/1.0.0",
-		XMLNsXsi:          "http://www.w3.org/2001/XMLSchema-instance",
-		XsiSchemaLocation: "http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd",
-	}
-
-	var additionalRepos []v1.Repository
-	for _, defaultRepo := range defaultMavenRepositories() {
-		if !containsRepo(repositories, defaultRepo.ID) {
-			additionalRepos = append(additionalRepos, defaultRepo)
-		}
-	}
-	if len(additionalRepos) > 0 {
-		repositories = append(additionalRepos, repositories...)
-	}
-
-	settings.Profiles = []Profile{
-		{
-			ID: "maven-settings",
-			Activation: Activation{
-				ActiveByDefault: true,
-			},
-			Repositories:       repositories,
-			PluginRepositories: repositories,
-		},
-	}
-
-	settings.Mirrors = mirrors
-
-	return settings
-}
-
-func containsRepo(repositories []v1.Repository, id string) bool {
-	for _, r := range repositories {
-		if r.ID == id {
-			return true
-		}
-	}
-	return false
-}
-
-func SettingsConfigMap(namespace string, name string, settings Settings) (*corev1.ConfigMap, error) {
-	data, err := util.EncodeXML(settings)
-	if err != nil {
-		return nil, err
-	}
-
-	cm := &corev1.ConfigMap{
-		TypeMeta: metav1.TypeMeta{
-			Kind:       "ConfigMap",
-			APIVersion: corev1.SchemeGroupVersion.String(),
-		},
-		ObjectMeta: metav1.ObjectMeta{
-			Name:      name + "-maven-settings",
-			Namespace: namespace,
-			Labels: map[string]string{
-				"app": "camel-k",
-			},
-		},
-		Data: map[string]string{
-			"settings.xml": string(data),
-		},
-	}
-
-	return cm, nil
-}
diff --git a/pkg/util/maven/maven_settings_test.go b/pkg/util/maven/maven_settings_test.go
index eabe87f..3ad7ac1 100644
--- a/pkg/util/maven/maven_settings_test.go
+++ b/pkg/util/maven/maven_settings_test.go
@@ -64,7 +64,7 @@ const expectedDefaultSettings = `<?xml version="1.0" encoding="UTF-8"?>
   <localRepository></localRepository>
   <profiles>
     <profile>
-      <id>maven-settings</id>
+      <id>camel-k</id>
       <activation>
         <activeByDefault>true</activeByDefault>
       </activation>
@@ -108,7 +108,7 @@ const expectedDefaultSettingsWithExtraRepo = `<?xml version="1.0" encoding="UTF-
   <localRepository></localRepository>
   <profiles>
     <profile>
-      <id>maven-settings</id>
+      <id>camel-k</id>
       <activation>
         <activeByDefault>true</activeByDefault>
       </activation>
@@ -214,7 +214,8 @@ func TestSettingsGeneration(t *testing.T) {
 }
 
 func TestDefaultSettingsGeneration(t *testing.T) {
-	settings := NewDefaultSettings([]v1.Repository{}, []Mirror{})
+	settings, err := NewSettings(DefaultRepositories)
+	assert.Nil(t, err)
 
 	content, err := util.EncodeXML(settings)
 
@@ -225,34 +226,18 @@ func TestDefaultSettingsGeneration(t *testing.T) {
 }
 
 func TestDefaultSettingsGenerationWithAdditionalRepo(t *testing.T) {
-	repositories := []v1.Repository{
-		NewRepository("https://repo1.maven.org/maven2@id=central"),
-		NewRepository("https://foo.bar.org/repo@id=foo"),
-	}
-	mirrors := []Mirror{
-		NewMirror("https://foo.bar.org/repo@id=foo@mirrorOf=*"),
+	repositories := []string{
+		"https://repo1.maven.org/maven2@id=central",
+		"https://foo.bar.org/repo@id=foo",
+		"https://foo.bar.org/repo@id=foo@mirrorOf=*",
 	}
-	settings := NewDefaultSettings(repositories, mirrors)
-
-	content, err := util.EncodeXML(settings)
-
+	settings, err := NewSettings(Repositories(repositories...))
 	assert.Nil(t, err)
-	assert.NotNil(t, settings)
-
-	assert.Equal(t, expectedDefaultSettingsWithExtraRepo, string(content))
-}
-
-func TestCreateSettingsConfigMap(t *testing.T) {
-	settings := NewDefaultSettings([]v1.Repository{}, []Mirror{})
-
-	configMap, err := SettingsConfigMap("foo", "bar", settings)
-	assert.Nil(t, err)
-	assert.NotNil(t, configMap)
 
 	content, err := util.EncodeXML(settings)
 
 	assert.Nil(t, err)
 	assert.NotNil(t, settings)
 
-	assert.Equal(t, string(content), configMap.Data["settings.xml"])
+	assert.Equal(t, expectedDefaultSettingsWithExtraRepo, string(content))
 }

[camel-k] 24/31: feat: Propagate HTTP proxy environment to build Pods

Posted by as...@apache.org.
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 d0c16513cd1d8566a2000412253b722c068f3d2d
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 11 12:28:57 2022 +0100

    feat: Propagate HTTP proxy environment to build Pods
---
 pkg/controller/build/build_pod.go | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/pkg/controller/build/build_pod.go b/pkg/controller/build/build_pod.go
index a759c8e..d5e813f 100644
--- a/pkg/controller/build/build_pod.go
+++ b/pkg/controller/build/build_pod.go
@@ -20,18 +20,19 @@ package build
 import (
 	"context"
 	"fmt"
+	"os"
 	"path"
 	"strconv"
 	"strings"
 
+	"github.com/pkg/errors"
+
 	corev1 "k8s.io/api/core/v1"
 	k8serrors "k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 
 	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
 
-	"github.com/pkg/errors"
-
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 	"github.com/apache/camel-k/pkg/builder"
 	"github.com/apache/camel-k/pkg/platform"
@@ -231,6 +232,7 @@ func addBuildTaskToPod(build *v1.Build, taskName string, pod *corev1.Pod) {
 			taskName,
 		},
 		WorkingDir: path.Join(builderDir, build.Name),
+		Env:        proxyFromEnvironment(),
 	}
 
 	addContainerToPod(build, container, pod)
@@ -300,6 +302,7 @@ func addBuildahTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, ta
 		push = append(push[:2], append([]string{"--tls-verify=false"}, push[2:]...)...)
 	}
 
+	env = append(env, proxyFromEnvironment()...)
 	env = append(env, proxySecretEnvVars(task.HttpProxySecret)...)
 
 	args := []string{
@@ -364,6 +367,7 @@ func addKanikoTaskToPod(ctx context.Context, c ctrl.Reader, build *v1.Build, tas
 		args = append(args, "--insecure-pull")
 	}
 
+	env = append(env, proxyFromEnvironment()...)
 	env = append(env, proxySecretEnvVars(task.HttpProxySecret)...)
 
 	if cache {
@@ -571,3 +575,30 @@ func proxySecretEnvVar(name string, secret string) corev1.EnvVar {
 		},
 	}
 }
+
+func proxyFromEnvironment() []corev1.EnvVar {
+	var envVars []corev1.EnvVar
+
+	if httpProxy, ok := os.LookupEnv("HTTP_PROXY"); ok {
+		envVars = append(envVars, corev1.EnvVar{
+			Name:  "HTTP_PROXY",
+			Value: httpProxy,
+		})
+	}
+
+	if httpsProxy, ok := os.LookupEnv("HTTPS_PROXY"); ok {
+		envVars = append(envVars, corev1.EnvVar{
+			Name:  "HTTPS_PROXY",
+			Value: httpsProxy,
+		})
+	}
+
+	if noProxy, ok := os.LookupEnv("NO_PROXY"); ok {
+		envVars = append(envVars, corev1.EnvVar{
+			Name:  "NO_PROXY",
+			Value: noProxy,
+		})
+	}
+
+	return envVars
+}

[camel-k] 05/31: chore(maven): Convert NO_PROXY to http.nonProxyHosts JVM system property format

Posted by as...@apache.org.
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 59a87cf90fbbebb2b004d5ccdea5749bc7c6bd8e
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Fri Jan 7 10:21:27 2022 +0100

    chore(maven): Convert NO_PROXY to http.nonProxyHosts JVM system property format
---
 pkg/util/maven/maven_proxies.go | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/pkg/util/maven/maven_proxies.go b/pkg/util/maven/maven_proxies.go
index 94091a8..aa57d4d 100644
--- a/pkg/util/maven/maven_proxies.go
+++ b/pkg/util/maven/maven_proxies.go
@@ -77,10 +77,14 @@ func parseProxyFromEnvVar(proxyEnvVar string) (Proxy, error) {
 		}
 	}
 	if noProxy := os.Getenv("NO_PROXY"); noProxy != "" {
-		nonProxyHosts := strings.ReplaceAll(noProxy, " ", "")
-		nonProxyHosts = strings.ReplaceAll(nonProxyHosts, ",", "|")
-		nonProxyHosts = strings.ReplaceAll(nonProxyHosts, "|.", "|*.")
-		proxy.NonProxyHosts = nonProxyHosts
+		// Convert to the format expected by the JVM http.nonProxyHosts system property
+		hosts := strings.Split(strings.ReplaceAll(noProxy, " ", ""), ",")
+		for i, host := range hosts {
+			if strings.HasPrefix(host, ".") {
+				hosts[i] = strings.Replace(host, ".", "*.", 1)
+			}
+		}
+		proxy.NonProxyHosts = strings.Join(hosts, "|")
 	}
 
 	return proxy, nil

[camel-k] 18/31: chore(jvm): Fail fast when no integration container is found

Posted by as...@apache.org.
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 c74768345aa8615206aeff2d15d044078ccef03c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 10 12:53:04 2022 +0100

    chore(jvm): Fail fast when no integration container is found
---
 pkg/trait/jvm.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pkg/trait/jvm.go b/pkg/trait/jvm.go
index 306a068..200670b 100644
--- a/pkg/trait/jvm.go
+++ b/pkg/trait/jvm.go
@@ -137,7 +137,7 @@ func (t *jvmTrait) Apply(e *Environment) error {
 
 	container := e.GetIntegrationContainer()
 	if container == nil {
-		return nil
+		return fmt.Errorf("unable to find integration container")
 	}
 
 	// Build the container command

[camel-k] 28/31: chore(e2e): assert HTTP proxy logs

Posted by as...@apache.org.
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 a00770741ff95f73b8120447d3226a01173cbbd3
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Tue Jan 11 19:01:56 2022 +0100

    chore(e2e): assert HTTP proxy logs
---
 e2e/common/build/maven_http_proxy_test.go | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/e2e/common/build/maven_http_proxy_test.go b/e2e/common/build/maven_http_proxy_test.go
index dfc6e0f..9bbcbe3 100644
--- a/e2e/common/build/maven_http_proxy_test.go
+++ b/e2e/common/build/maven_http_proxy_test.go
@@ -43,6 +43,8 @@ import (
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/util/intstr"
 
+	ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+
 	. "github.com/apache/camel-k/e2e/support"
 	v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
 )
@@ -325,7 +327,22 @@ ProxyVia Off
 		Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue))
 		Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!"))
 
-		// TODO: assert the proxy logs
+		proxies := corev1.PodList{
+			TypeMeta: metav1.TypeMeta{
+				Kind:       "Pod",
+				APIVersion: corev1.SchemeGroupVersion.String(),
+			},
+		}
+		err = TestClient().List(TestContext, &proxies,
+			ctrl.InNamespace(ns),
+			ctrl.MatchingLabels(deployment.Spec.Selector.MatchLabels),
+		)
+		Expect(err).To(Succeed())
+		Expect(proxies.Items).To(HaveLen(1))
+
+		logs := Logs(ns, proxies.Items[0].Name, corev1.PodLogOptions{})()
+		Expect(logs).NotTo(BeEmpty())
+		Expect(logs).To(ContainSubstring("\"CONNECT repo.maven.apache.org:443 HTTP/1.1\" 200"))
 
 		// Clean up
 		Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())

[camel-k] 14/31: chore(e2e): Add extra RBAC permissions for the HTTP proxy tests

Posted by as...@apache.org.
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 c125dc979d79a83ea10bdd3a8a89644997ad952c
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Mon Jan 10 10:54:42 2022 +0100

    chore(e2e): Add extra RBAC permissions for the HTTP proxy tests
---
 .github/workflows/openshift.yml | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/.github/workflows/openshift.yml b/.github/workflows/openshift.yml
index 1febe06..c7cd72d 100644
--- a/.github/workflows/openshift.yml
+++ b/.github/workflows/openshift.yml
@@ -216,6 +216,34 @@ jobs:
           verbs: ["update"]
         EOF
 
+        # Grant read permission on the Kubernetes Service to the default developer user
+        # Required by the HTTP proxy tests
+        cat <<EOF | oc apply -f -
+        kind: ClusterRole
+        apiVersion: rbac.authorization.k8s.io/v1
+        metadata:
+          name: camel-k-test:kubernetes-service
+        rules:
+        - apiGroups: [""]
+          resources: ["services"]
+          verbs: ["get"]
+          resourceNames: ["kubernetes"]
+        EOF
+        cat <<EOF | oc apply -f -
+        kind: RoleBinding
+        apiVersion: rbac.authorization.k8s.io/v1
+        metadata:
+          namespace: default
+          name: camel-k-test:kubernetes-service
+        subjects:
+        - kind: User
+          name: developer
+        roleRef:
+          kind: ClusterRole
+          name: camel-k-test:kubernetes-service
+          apiGroup: rbac.authorization.k8s.io
+        EOF
+
         # Login as normal user
         oc login -u developer