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 <[email protected]> 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 +}
