diff --git a/e2e/common/config/config_test.go b/e2e/common/config/config_test.go index 3ea3ba8f06..ab7094b13c 100644 --- a/e2e/common/config/config_test.go +++ b/e2e/common/config/config_test.go @@ -28,6 +28,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -120,6 +121,15 @@ func TestRunConfigExamples(t *testing.T) { Eventually(IntegrationPodPhase(ns, "property-secret-route"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) Eventually(IntegrationConditionStatus(ns, "property-secret-route", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, "property-secret-route"), TestTimeoutShort).Should(ContainSubstring("my-secret-external-value")) + + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, "property-secret-route")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, "property-secret-route")() + mountTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "mount") + Expect(mountTrait).ToNot(BeNil()) + Expect(len(mountTrait)).To(Equal(1)) + Expect(mountTrait["configs"]).ToNot(BeNil()) + Expect(Kamel("delete", "property-secret-route", "-n", ns).Execute()).To(Succeed()) }) diff --git a/e2e/common/misc/kamelet_test.go b/e2e/common/misc/kamelet_test.go index 6de1b1999c..66c8c38391 100644 --- a/e2e/common/misc/kamelet_test.go +++ b/e2e/common/misc/kamelet_test.go @@ -27,6 +27,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" ) @@ -119,6 +120,14 @@ spec: "-d", "camel:timer").Execute()).To(Succeed()) Eventually(IntegrationPodPhase(ns, "timer-kamelet-integration"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) Eventually(IntegrationLogs(ns, "timer-kamelet-integration")).Should(ContainSubstring("important message")) + + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, "timer-kamelet-integration")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, "timer-kamelet-integration")() + kameletsTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "kamelets") + Expect(kameletsTrait).ToNot(BeNil()) + Expect(len(kameletsTrait)).To(Equal(1)) + Expect(kameletsTrait["enabled"]).To(Equal(false)) }) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) diff --git a/e2e/common/traits/affinity_test.go b/e2e/common/traits/affinity_test.go index 19fa2ccc27..7ce8a20eba 100644 --- a/e2e/common/traits/affinity_test.go +++ b/e2e/common/traits/affinity_test.go @@ -30,6 +30,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -48,21 +49,31 @@ func TestAffinityTrait(t *testing.T) { if hostname != "" { t.Run("Run Java with node affinity", func(t *testing.T) { + name1 := RandomizedSuffixName("java1") Expect(KamelRunWithID(operatorID, ns, "files/Java.java", - "--name", "java1", + "--name", name1, "-t", "affinity.enabled=true", "-t", fmt.Sprintf("affinity.node-affinity-labels=kubernetes.io/hostname in(%s)", hostname)).Execute()).To(Succeed()) - Eventually(IntegrationPodPhase(ns, "java1"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - Eventually(IntegrationConditionStatus(ns, "java1", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) - Eventually(IntegrationLogs(ns, "java1"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + Eventually(IntegrationPodPhase(ns, name1), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + Eventually(IntegrationConditionStatus(ns, name1, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + Eventually(IntegrationLogs(ns, name1), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) - pod := IntegrationPod(ns, "java1")() + pod := IntegrationPod(ns, name1)() Expect(pod.Spec.Affinity).NotTo(BeNil()) Expect(pod.Spec.Affinity.NodeAffinity).To(Equal(&corev1.NodeAffinity{ RequiredDuringSchedulingIgnoredDuringExecution: nodeSelector("kubernetes.io/hostname", corev1.NodeSelectorOpIn, hostname), })) Expect(pod.Spec.NodeName).To(Equal(hostname)) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name1)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name1)() + affinityTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "affinity") + Expect(affinityTrait).NotTo(BeNil()) + Expect(len(affinityTrait)).To(Equal(2)) + Expect(affinityTrait["enabled"]).To(Equal(true)) + Expect(affinityTrait["nodeAffinityLabels"]).NotTo(BeNil()) + Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/builder_test.go b/e2e/common/traits/builder_test.go index a994c4ccd4..5a1df5d308 100644 --- a/e2e/common/traits/builder_test.go +++ b/e2e/common/traits/builder_test.go @@ -30,6 +30,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -66,7 +67,7 @@ func TestBuilderTrait(t *testing.T) { }) t.Run("Run build order strategy dependencies", func(t *testing.T) { - name := RandomizedSuffixName("java-fifo-strategy") + name := RandomizedSuffixName("java-dependencies-strategy") Expect(KamelRunWithID(operatorID, ns, "files/Java.java", "--name", name, "-t", "builder.order-strategy=dependencies").Execute()).To(Succeed()) @@ -88,6 +89,14 @@ func TestBuilderTrait(t *testing.T) { Eventually(BuilderPod(integrationKitNamespace, builderKitName), TestTimeoutShort).Should(BeNil()) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + builderTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "builder") + Expect(builderTrait).NotTo(BeNil()) + Expect(len(builderTrait)).To(Equal(1)) + Expect(builderTrait["orderStrategy"]).To(Equal("dependencies")) + // We need to remove the kit as well Expect(Kamel("reset", "-n", ns).Execute()).To(Succeed()) }) diff --git a/e2e/common/traits/container_test.go b/e2e/common/traits/container_test.go index b379b79132..6bd6ba4ec6 100644 --- a/e2e/common/traits/container_test.go +++ b/e2e/common/traits/container_test.go @@ -28,6 +28,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -93,6 +94,14 @@ func TestContainerTrait(t *testing.T) { return podContainerName == containerName }), TestTimeoutShort).Should(BeTrue()) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + containerTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "container") + Expect(containerTrait).ToNot(BeNil()) + Expect(len(containerTrait)).To(Equal(1)) + Expect(containerTrait["name"]).To(Equal(containerName)) + }) // Clean-up diff --git a/e2e/common/traits/deployment_test.go b/e2e/common/traits/deployment_test.go index 7b9f2e5b46..08a589e5ed 100644 --- a/e2e/common/traits/deployment_test.go +++ b/e2e/common/traits/deployment_test.go @@ -26,6 +26,7 @@ import ( "testing" appsv1 "k8s.io/api/apps/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gstruct" @@ -40,15 +41,17 @@ func TestRecreateDeploymentStrategyTrait(t *testing.T) { RegisterTestingT(t) t.Run("Run with Recreate Deployment Strategy", func(t *testing.T) { + name := RandomizedSuffixName("java") Expect(KamelRunWithID(operatorID, ns, "files/Java.java", + "--name", name, "-t", "deployment.strategy="+string(appsv1.RecreateDeploymentStrategyType)). 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!")) - Eventually(Deployment(ns, "java"), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, + Eventually(Deployment(ns, name), TestTimeoutMedium).Should(PointTo(MatchFields(IgnoreExtras, Fields{ "Spec": MatchFields(IgnoreExtras, Fields{ @@ -60,6 +63,14 @@ func TestRecreateDeploymentStrategyTrait(t *testing.T) { }), )) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + deploymentTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "deployment") + Expect(deploymentTrait).ToNot(BeNil()) + Expect(len(deploymentTrait)).To(Equal(1)) + Expect(deploymentTrait["strategy"]).To(Equal(string(appsv1.RecreateDeploymentStrategyType))) + }) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) diff --git a/e2e/common/traits/health_test.go b/e2e/common/traits/health_test.go index 0d4656b4d5..6cbdefb360 100644 --- a/e2e/common/traits/health_test.go +++ b/e2e/common/traits/health_test.go @@ -36,6 +36,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -72,6 +73,14 @@ func TestHealthTrait(t *testing.T) { // Finally check the readiness condition becomes truthy back Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue)) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + healthTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "health") + Expect(healthTrait).ToNot(BeNil()) + Expect(len(healthTrait)).To(Equal(1)) + Expect(healthTrait["enabled"]).To(Equal(true)) + pods := IntegrationPods(ns, name)() for i, pod := range pods { diff --git a/e2e/common/traits/istio_test.go b/e2e/common/traits/istio_test.go index c2fcc07b33..5d507c8235 100644 --- a/e2e/common/traits/istio_test.go +++ b/e2e/common/traits/istio_test.go @@ -28,6 +28,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -51,6 +52,14 @@ func TestIstioTrait(t *testing.T) { Expect(annotations["sidecar.istio.io/inject"]).To(Equal("true")) Expect(annotations["traffic.sidecar.istio.io/includeOutboundIPRanges"]).To(Equal("10.0.0.0/8,172.16.0.0/12,192.168.0.0/16")) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + istioTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "istio") + Expect(istioTrait).ToNot(BeNil()) + Expect(len(istioTrait)).To(Equal(1)) + Expect(istioTrait["enabled"]).To(Equal(true)) + }) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) diff --git a/e2e/common/traits/jolokia_test.go b/e2e/common/traits/jolokia_test.go index 6145ffc3f9..c06e8d53a3 100644 --- a/e2e/common/traits/jolokia_test.go +++ b/e2e/common/traits/jolokia_test.go @@ -29,6 +29,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -38,21 +39,34 @@ func TestJolokiaTrait(t *testing.T) { RegisterTestingT(t) t.Run("Run Java with Jolokia", func(t *testing.T) { + name := RandomizedSuffixName("java") Expect(KamelRunWithID(operatorID, ns, "files/Java.java", + "--name", name, "-t", "jolokia.enabled=true", "-t", "jolokia.use-ssl-client-authentication=false", "-t", "jolokia.protocol=http", "-t", "jolokia.extended-client-check=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!")) - pod := IntegrationPod(ns, "java") + pod := IntegrationPod(ns, name) response, err := TestClient().CoreV1().RESTClient().Get(). AbsPath(fmt.Sprintf("/api/v1/namespaces/%s/pods/%s/proxy/jolokia/", ns, pod().Name)).DoRaw(TestContext) Expect(err).To(BeNil()) Expect(response).To(ContainSubstring(`"status":200`)) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + jolokiaTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "jolokia") + Expect(jolokiaTrait).ToNot(BeNil()) + Expect(len(jolokiaTrait)).To(Equal(4)) + Expect(jolokiaTrait["enabled"]).To(Equal(true)) + Expect(jolokiaTrait["useSSLClientAuthentication"]).To(Equal(false)) + Expect(jolokiaTrait["protocol"]).To(Equal("http")) + Expect(jolokiaTrait["extendedClientCheck"]).To(Equal(false)) + }) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) diff --git a/e2e/common/traits/jvm_test.go b/e2e/common/traits/jvm_test.go index 3d8bde71c3..395a51705c 100644 --- a/e2e/common/traits/jvm_test.go +++ b/e2e/common/traits/jvm_test.go @@ -30,6 +30,7 @@ import ( "github.com/stretchr/testify/assert" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -55,6 +56,15 @@ func TestJVMTrait(t *testing.T) { Eventually(IntegrationPodPhase(ns, "classpath"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) Eventually(IntegrationConditionStatus(ns, "classpath", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, "classpath"), TestTimeoutShort).Should(ContainSubstring("Hello World!")) + + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, "classpath")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, "classpath")() + jvmTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "jvm") + Expect(jvmTrait).ToNot(BeNil()) + Expect(len(jvmTrait)).To(Equal(1)) + Expect(jvmTrait["classpath"]).To(Equal("/etc/camel/resources/my-deps/sample-1.0.jar")) + Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) }) } diff --git a/e2e/common/traits/master_test.go b/e2e/common/traits/master_test.go index fd53aa0148..111760b022 100644 --- a/e2e/common/traits/master_test.go +++ b/e2e/common/traits/master_test.go @@ -29,6 +29,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" ) @@ -44,25 +45,36 @@ func TestMasterTrait(t *testing.T) { }) t.Run("only one integration with master runs", func(t *testing.T) { + nameFirst := RandomizedSuffixName("first") Expect(KamelRunWithID(operatorID, ns, "files/Master.java", - "--name", "first", + "--name", nameFirst, "--label", "leader-group=same", "-t", "master.label-key=leader-group", "-t", "master.label-value=same", "-t", "owner.target-labels=leader-group").Execute()).To(Succeed()) - Eventually(IntegrationPodPhase(ns, "first"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - Eventually(IntegrationLogs(ns, "first"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + Eventually(IntegrationPodPhase(ns, nameFirst), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + Eventually(IntegrationLogs(ns, nameFirst), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) // Start a second integration with the same lock (it should not start the route) + nameSecond := RandomizedSuffixName("second") Expect(KamelRunWithID(operatorID, ns, "files/Master.java", - "--name", "second", + "--name", nameSecond, "--label", "leader-group=same", "-t", "master.label-key=leader-group", "-t", "master.label-value=same", "-t", "master.resource-name=first-lock", "-t", "owner.target-labels=leader-group").Execute()).To(Succeed()) - Eventually(IntegrationPodPhase(ns, "second"), TestTimeoutLong).Should(Equal(corev1.PodRunning)) - Eventually(IntegrationLogs(ns, "second"), TestTimeoutShort).Should(ContainSubstring("started in")) - Eventually(IntegrationLogs(ns, "second"), 30*time.Second).ShouldNot(ContainSubstring("Magicstring!")) + Eventually(IntegrationPodPhase(ns, nameSecond), TestTimeoutLong).Should(Equal(corev1.PodRunning)) + Eventually(IntegrationLogs(ns, nameSecond), TestTimeoutShort).Should(ContainSubstring("started in")) + Eventually(IntegrationLogs(ns, nameSecond), 30*time.Second).ShouldNot(ContainSubstring("Magicstring!")) + + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, nameFirst)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, nameFirst)() + builderTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "addons", "master") + Expect(builderTrait).ToNot(BeNil()) + Expect(len(builderTrait)).To(Equal(2)) + Expect(builderTrait["labelKey"]).To(Equal("leader-group")) + Expect(builderTrait["labelValue"]).To(Equal("same")) }) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) diff --git a/e2e/common/traits/pdb_test.go b/e2e/common/traits/pdb_test.go index cc3b038c8e..7c43e1ff75 100644 --- a/e2e/common/traits/pdb_test.go +++ b/e2e/common/traits/pdb_test.go @@ -33,6 +33,7 @@ import ( policyv1 "k8s.io/api/policy/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/util/intstr" ctrl "sigs.k8s.io/controller-runtime/pkg/client" @@ -55,6 +56,15 @@ func TestPodDisruptionBudgetTrait(t *testing.T) { Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + pdbTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "pdb") + Expect(pdbTrait).ToNot(BeNil()) + Expect(len(pdbTrait)).To(Equal(2)) + Expect(pdbTrait["enabled"]).To(Equal(true)) + Expect(pdbTrait["minAvailable"]).To(Equal("2")) + // Check PodDisruptionBudget Eventually(podDisruptionBudget(ns, name), TestTimeoutShort).ShouldNot(BeNil()) pdb := podDisruptionBudget(ns, name)() diff --git a/e2e/common/traits/prometheus_test.go b/e2e/common/traits/prometheus_test.go index 7a63772c7e..1a40ddab74 100644 --- a/e2e/common/traits/prometheus_test.go +++ b/e2e/common/traits/prometheus_test.go @@ -31,6 +31,7 @@ import ( corev1 "k8s.io/api/core/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ctrl "sigs.k8s.io/controller-runtime/pkg/client" @@ -55,6 +56,14 @@ func TestPrometheusTrait(t *testing.T) { Eventually(IntegrationConditionStatus(ns, "java", v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, "java"), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, "java")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, "java")() + prometheusTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "prometheus") + Expect(prometheusTrait).ToNot(BeNil()) + Expect(len(prometheusTrait)).To(Equal(2)) + Expect(prometheusTrait["enabled"]).To(Equal(true)) + Expect(prometheusTrait["podMonitor"]).ToNot(BeNil()) t.Run("Metrics endpoint works", func(t *testing.T) { pod := IntegrationPod(ns, "java") response, err := TestClient().CoreV1().RESTClient().Get(). diff --git a/e2e/common/traits/pull_secret_test.go b/e2e/common/traits/pull_secret_test.go index eab6d7c83d..ade72f1447 100644 --- a/e2e/common/traits/pull_secret_test.go +++ b/e2e/common/traits/pull_secret_test.go @@ -28,6 +28,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -61,6 +62,14 @@ func TestPullSecretTrait(t *testing.T) { Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) Eventually(IntegrationLogs(ns, name), TestTimeoutShort).Should(ContainSubstring("Magicstring!")) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + pullSecretTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "pull-secret") + Expect(pullSecretTrait).ToNot(BeNil()) + Expect(len(pullSecretTrait)).To(Equal(1)) + Expect(pullSecretTrait["enabled"]).To(Equal(false)) + pod := IntegrationPod(ns, name)() if ocp { // OpenShift `default` service account has imagePullSecrets so it's always set diff --git a/e2e/common/traits/route_test.go b/e2e/common/traits/route_test.go index ee90e16ac1..a06b03bbbe 100644 --- a/e2e/common/traits/route_test.go +++ b/e2e/common/traits/route_test.go @@ -41,6 +41,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" "github.com/apache/camel-k/v2/pkg/util" @@ -211,6 +212,15 @@ func TestRunRoutes(t *testing.T) { time.Sleep(waitBeforeHttpRequest) var annotations = route.ObjectMeta.Annotations Expect(annotations["haproxy.router.openshift.io/balance"]).To(Equal("roundrobin")) + + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, integrationName)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, integrationName)() + routeTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "route") + Expect(routeTrait).ToNot(BeNil()) + Expect(len(routeTrait)).To(Equal(1)) + Expect(routeTrait["enabled"]).To(Equal(true)) + Expect(Kamel("delete", "--all", "-n", ns).Execute()).Should(BeNil()) }) Expect(TestClient().Delete(TestContext, &secret)).To(Succeed()) diff --git a/e2e/common/traits/service_test.go b/e2e/common/traits/service_test.go index 401eeb842f..8b5e5f168c 100644 --- a/e2e/common/traits/service_test.go +++ b/e2e/common/traits/service_test.go @@ -28,6 +28,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" ) @@ -91,6 +92,15 @@ func TestServiceTrait(t *testing.T) { // Eventually(ServicesByType(ns, corev1.ServiceTypeClusterIP), TestTimeoutLong).ShouldNot(BeEmpty()) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, "platform-http-server")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, "platform-http-server")() + serviceTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "service") + Expect(serviceTrait).ToNot(BeNil()) + Expect(len(serviceTrait)).To(Equal(2)) + Expect(serviceTrait["enabled"]).To(Equal(true)) + Expect(serviceTrait["type"]).To(Equal("ClusterIP")) + Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) }) diff --git a/e2e/commonwithcustominstall/environment_test.go b/e2e/commonwithcustominstall/environment_test.go index 469ecbc367..3b8f13c5d7 100644 --- a/e2e/commonwithcustominstall/environment_test.go +++ b/e2e/commonwithcustominstall/environment_test.go @@ -31,6 +31,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -151,6 +152,14 @@ func TestEnvironmentTrait(t *testing.T) { Not(ContainElement(corev1.EnvVar{Name: "HTTP_PROXY", Value: httpProxy})), Not(ContainElement(corev1.EnvVar{Name: "NO_PROXY", Value: strings.Join(noProxy, ",")})), ))) + + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + envTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "environment") + Expect(envTrait).ToNot(BeNil()) + Expect(len(envTrait)).To(Equal(1)) + Expect(envTrait["httpProxy"]).To(Equal(false)) }) Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) diff --git a/e2e/native/native_test.go b/e2e/native/native_test.go index 88b5916df9..b4d0cc8b67 100644 --- a/e2e/native/native_test.go +++ b/e2e/native/native_test.go @@ -28,6 +28,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" @@ -53,7 +54,15 @@ func TestNativeIntegrations(t *testing.T) { Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionKitAvailable)). Should(Equal(corev1.ConditionFalse)) - // Clean up + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, name)).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, name)() + quarkusTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "quarkus") + Expect(quarkusTrait).ToNot(BeNil()) + Expect(len(quarkusTrait)).To(Equal(1)) + Expect(quarkusTrait["buildMode"]).ToNot(BeNil()) + + // Clean up Expect(Kamel("delete", name, "-n", ns).Execute()).To(Succeed()) }) diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index 4b67c6dc65..434d5ecd8d 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -54,6 +54,7 @@ import ( rbacv1 "k8s.io/api/rbac/v1" k8serrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/serializer" @@ -1012,6 +1013,28 @@ func Integration(ns string, name string) func() *v1.Integration { } } +func UnstructuredIntegration(ns string, name string) func() *unstructured.Unstructured { + return func() *unstructured.Unstructured { + gvk := schema.GroupVersionKind{Group: v1.SchemeGroupVersion.Group, Version: v1.SchemeGroupVersion.Version, Kind: v1.IntegrationKind} + return UnstructuredObject(ns, name, gvk)() + } +} + +func UnstructuredObject(ns string, name string, gvk schema.GroupVersionKind) func() *unstructured.Unstructured { + return func() *unstructured.Unstructured { + object := &unstructured.Unstructured{} + object.SetNamespace(ns) + object.SetName(name) + object.SetGroupVersionKind(gvk) + if err := TestClient().Get(TestContext, ctrl.ObjectKeyFromObject(object), object); err != nil && !k8serrors.IsNotFound(err) { + failTest(err) + } else if err != nil && k8serrors.IsNotFound(err) { + return nil + } + return object + } +} + func IntegrationVersion(ns string, name string) func() string { return func() string { it := Integration(ns, name)() diff --git a/e2e/support/test_util.go b/e2e/support/test_util.go index 88842a85da..61fbc3f2f6 100644 --- a/e2e/support/test_util.go +++ b/e2e/support/test_util.go @@ -76,9 +76,7 @@ func ExpectExecSucceed(t *testing.T, command *exec.Cmd) { assert.NotContains(t, strings.ToUpper(cmdErr.String()), "ERROR") } -// // Expect a command error with an exit code of 1 -// func ExpectExecError(t *testing.T, command *exec.Cmd) { t.Helper() diff --git a/e2e/telemetry/telemetry_test.go b/e2e/telemetry/telemetry_test.go index 0d772e7bc1..b327300923 100644 --- a/e2e/telemetry/telemetry_test.go +++ b/e2e/telemetry/telemetry_test.go @@ -29,6 +29,7 @@ import ( . "github.com/onsi/gomega" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" . "github.com/apache/camel-k/v2/e2e/support" ) @@ -67,6 +68,15 @@ func TestTelemetryTrait(t *testing.T) { Eventually(TailedLogs(pod.Namespace, pod.Name, 100), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("http.target: Str(/customers/%s)", name))) Eventually(TailedLogs(pod.Namespace, pod.Name, 100), TestTimeoutLong).Should(ContainSubstring(fmt.Sprintf("http.url: Str(http://rest-consumer/customers/%s)", name))) + // check integration schema does not contains unwanted default trait value. + Eventually(UnstructuredIntegration(ns, "rest-consumer")).ShouldNot(BeNil()) + unstructuredIntegration := UnstructuredIntegration(ns, "rest-consumer")() + builderTrait, _, _ := unstructured.NestedMap(unstructuredIntegration.Object, "spec", "traits", "addons", "telemetry") + Expect(builderTrait).NotTo(BeNil()) + Expect(len(builderTrait)).To(Equal(2)) + Expect(builderTrait["enabled"]).To(Equal(true)) + Expect(builderTrait["endpoint"]).To(Equal("http://opentelemetrycollector.otlp.svc.cluster.local:4317")) + // Clean up Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed()) })