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:54:10 UTC
[camel-k] 24/31: feat: Propagate HTTP proxy environment to build Pods
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
+}