You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by GitBox <gi...@apache.org> on 2022/12/21 14:31:19 UTC

[GitHub] [camel-k] squakez commented on a diff in pull request #3951: fix(controller): ensure `container.name` trait is used by the integration controller

squakez commented on code in PR #3951:
URL: https://github.com/apache/camel-k/pull/3951#discussion_r1054452211


##########
pkg/controller/integration/monitor.go:
##########
@@ -407,9 +407,11 @@ func getIntegrationDigest(envs []corev1.EnvVar) string {
 	return ""
 }
 
-func findIntegrationContainer(spec corev1.PodSpec) *corev1.Container {
+// findIntegrationContainer find if present the integration container in the pod spec using the integration specifications.
+func findIntegrationContainer(environment *trait.Environment, spec corev1.PodSpec) *corev1.Container {
+	integrationContainerName := environment.GetIntegrationContainerName()

Review Comment:
   Any reason why not to expect the integration container name here and passing the whole `environment` along all the methods? I'd be more cautious just passing what we need and keep more readable the func signature.



##########
e2e/global/common/traits/container_test.go:
##########
@@ -0,0 +1,104 @@
+//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 (
+	"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"
+)
+
+func TestContainerTrait(t *testing.T) {
+	WithNewTestNamespace(t, func(ns string) {
+		operatorID := "camel-k-trait-container"
+		Expect(KamelInstallWithID(operatorID, ns).Execute()).To(Succeed())
+
+		t.Run("Container image pull policy and resources configuration", func(t *testing.T) {
+			name := "java1"
+			Expect(KamelRunWithID(operatorID, ns, "files/Java.java",
+				"-t", "container.image-pull-policy=Always",
+				"-t", "container.request-cpu=0.005",
+				"-t", "container.request-memory=100Mi",
+				"-t", "container.limit-cpu=200m",
+				"-t", "container.limit-memory=500Mi",
+				"--name", name,
+			).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!"))
+			Eventually(IntegrationPodHas(ns, name, func(pod *corev1.Pod) bool {
+				if len(pod.Spec.Containers) != 1 {
+					return false
+				}
+				imagePullPolicy := pod.Spec.Containers[0].ImagePullPolicy
+				return imagePullPolicy == "Always"
+			}), TestTimeoutShort).Should(BeTrue())
+			Eventually(IntegrationPodHas(ns, name, func(pod *corev1.Pod) bool {
+				if len(pod.Spec.Containers) != 1 {
+					return false
+				}
+				limitsCpu := pod.Spec.Containers[0].Resources.Limits.Cpu()
+				requestsCpu := pod.Spec.Containers[0].Resources.Requests.Cpu()
+				return limitsCpu != nil && limitsCpu.String() == "200m" && requestsCpu != nil && requestsCpu.String() == "5m"
+			}), TestTimeoutShort).Should(BeTrue())
+			Eventually(IntegrationPodHas(ns, name, func(pod *corev1.Pod) bool {
+				if len(pod.Spec.Containers) != 1 {
+					return false
+				}
+				limitsMemory := pod.Spec.Containers[0].Resources.Limits.Memory()
+				requestsMemory := pod.Spec.Containers[0].Resources.Requests.Memory()
+				return limitsMemory != nil && limitsMemory.String() == "500Mi" && requestsMemory != nil && requestsMemory.String() == "100Mi"
+			}), TestTimeoutShort).Should(BeTrue())
+
+		})
+
+		t.Run("Container name", func(t *testing.T) {
+			name := "java2"
+			containerName := "notintegration"
+			Expect(KamelRunWithID(operatorID, ns, "files/Java.java",
+				"-t", "container.name="+containerName,

Review Comment:
   I think it would be easier to maintain calling it `my-container-name` instead of `notintegration`. We both understand why `notintegration` now but in the future I will forget for sure... :P



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org