feat: Propagate HTTP proxy environment to build Pods
@@ -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
+}
