This is an automated email from the ASF dual-hosted git repository. squakez pushed a commit to branch v3 in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit c52157a3b53076936ddc8de5dd2d9495db8468c5 Author: Sanjeev Kumar <[email protected]> AuthorDate: Fri Nov 20 12:46:51 2026 +0530 test(e2e): cover owner trait configuration (#6966) * test(e2e): cover owner trait configuration * test(e2e): simplify owner deployment assertions * test(e2e): assert Integration owner reference type * test(e2e): fix owner reference assertions * test(e2e): fix owner annotation propagation coverage * test(e2e): scope owner assertions to subtests * test(e2e): scope owner assertions to each subtest * test(e2e): use medium timeout for owner annotation test * test(e2e): assert preserved pod template annotation * test(e2e): wait for owner deployment before assertions * test(e2e): use custom owner annotation keys * test(e2e): verify owner annotation filtering on Service --- e2e/common/traits/owner_test.go | 150 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/e2e/common/traits/owner_test.go b/e2e/common/traits/owner_test.go new file mode 100644 index 000000000..9be9588ae --- /dev/null +++ b/e2e/common/traits/owner_test.go @@ -0,0 +1,150 @@ +//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 common + +import ( + "context" + "testing" + + . "github.com/onsi/gomega" + + corev1 "k8s.io/api/core/v1" + + . "github.com/apache/camel-k/v2/e2e/support" + v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1" +) + +func TestOwnerTrait(t *testing.T) { + t.Parallel() + + WithNewTestNamespace(t, func(ctx context.Context, _ *WithT, ns string) { + t.Run("selected labels and annotations are propagated to owned resources", func(t *testing.T) { + g := NewWithT(t) + name := RandomizedSuffixName("owner-selected") + selectedLabel := "owner-test-selected-label" + unselectedLabel := "owner-test-unselected-label" + selectedAnnotation := "owner-test.camel.apache.org/selected" + unselectedAnnotation := "owner-test.camel.apache.org/unselected" + + g.Expect(KamelRun(t, ctx, ns, "files/PlatformHttpServer.java", + "--name", name, + "--label", selectedLabel+"=selected", + "--label", unselectedLabel+"=unselected", + "--annotation", selectedAnnotation+"=selected", + "--annotation", unselectedAnnotation+"=unselected", + "-t", "owner.target-labels="+selectedLabel, + "-t", "owner.target-annotations="+selectedAnnotation, + ).Execute()).To(Succeed()) + + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium). + Should(Equal(corev1.ConditionTrue)) + + integration := Integration(t, ctx, ns, name)() + g.Expect(integration).NotTo(BeNil()) + g.Eventually(Deployment(t, ctx, ns, name), TestTimeoutMedium).ShouldNot(BeNil()) + + deployment := Deployment(t, ctx, ns, name)() + g.Expect(deployment).NotTo(BeNil()) + g.Expect(deployment.Labels).To(HaveKeyWithValue(selectedLabel, "selected")) + g.Expect(deployment.Labels).NotTo(HaveKey(unselectedLabel)) + g.Expect(deployment.Spec.Template.Labels).To(HaveKeyWithValue(selectedLabel, "selected")) + g.Expect(deployment.Spec.Template.Labels).NotTo(HaveKey(unselectedLabel)) + + g.Expect(deployment.Annotations).To(HaveKeyWithValue(selectedAnnotation, "selected")) + g.Expect(deployment.Spec.Template.Annotations).To(HaveKeyWithValue(selectedAnnotation, "selected")) + + // The Deployment trait copies transferable Integration annotations before + // the Owner trait runs. Check filtering on the Service, which starts with + // only Service-trait annotations. + g.Eventually(Service(t, ctx, ns, name), TestTimeoutMedium).ShouldNot(BeNil()) + service := Service(t, ctx, ns, name)() + g.Expect(service.Annotations).To(HaveKeyWithValue(selectedAnnotation, "selected")) + g.Expect(service.Annotations).NotTo(HaveKey(unselectedAnnotation)) + + g.Expect(deployment.OwnerReferences).To(HaveLen(1)) + ownerReference := deployment.OwnerReferences[0] + g.Expect(ownerReference.APIVersion).To(Equal(v1.SchemeGroupVersion.String())) + g.Expect(ownerReference.Kind).To(Equal("Integration")) + g.Expect(ownerReference.Name).To(Equal(integration.Name)) + g.Expect(ownerReference.UID).To(Equal(integration.UID)) + g.Expect(ownerReference.Controller).NotTo(BeNil()) + g.Expect(*ownerReference.Controller).To(BeTrue()) + g.Expect(ownerReference.BlockOwnerDeletion).NotTo(BeNil()) + g.Expect(*ownerReference.BlockOwnerDeletion).To(BeTrue()) + }) + + t.Run("existing Pod template annotation is not overwritten", func(t *testing.T) { + g := NewWithT(t) + name := RandomizedSuffixName("owner-annotation-conflict") + defaultContainerAnnotation := "kubectl.kubernetes.io/default-container" + + g.Expect(KamelRun(t, ctx, ns, "files/PlatformHttpServer.java", + "--name", name, + "--annotation", defaultContainerAnnotation+"=must-not-overwrite", + "-t", "owner.target-annotations="+defaultContainerAnnotation, + ).Execute()).To(Succeed()) + + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium). + Should(Equal(corev1.ConditionTrue)) + g.Eventually(Deployment(t, ctx, ns, name), TestTimeoutMedium).ShouldNot(BeNil()) + + deployment := Deployment(t, ctx, ns, name)() + g.Expect(deployment.Spec.Template.Annotations).To(HaveKeyWithValue(defaultContainerAnnotation, "integration")) + }) + + t.Run("wildcard propagates all labels and annotations", func(t *testing.T) { + g := NewWithT(t) + name := RandomizedSuffixName("owner-wildcard") + labelOne := "owner-test-wildcard-one" + labelTwo := "owner-test-wildcard-two" + annotationOne := "owner-test.camel.apache.org/wildcard-one" + annotationTwo := "owner-test.camel.apache.org/wildcard-two" + + g.Expect(KamelRun(t, ctx, ns, "files/PlatformHttpServer.java", + "--name", name, + "--label", labelOne+"=one", + "--label", labelTwo+"=two", + "--annotation", annotationOne+"=one", + "--annotation", annotationTwo+"=two", + "-t", "owner.target-labels=*", + "-t", "owner.target-annotations=*", + ).Execute()).To(Succeed()) + + g.Eventually(IntegrationConditionStatus(t, ctx, ns, name, v1.IntegrationConditionReady), TestTimeoutMedium). + Should(Equal(corev1.ConditionTrue)) + g.Eventually(Deployment(t, ctx, ns, name), TestTimeoutMedium).ShouldNot(BeNil()) + + deployment := Deployment(t, ctx, ns, name)() + g.Expect(deployment.Labels).To(HaveKeyWithValue(labelOne, "one")) + g.Expect(deployment.Labels).To(HaveKeyWithValue(labelTwo, "two")) + g.Expect(deployment.Spec.Template.Labels).To(HaveKeyWithValue(labelOne, "one")) + g.Expect(deployment.Spec.Template.Labels).To(HaveKeyWithValue(labelTwo, "two")) + g.Expect(deployment.Annotations).To(HaveKeyWithValue(annotationOne, "one")) + g.Expect(deployment.Annotations).To(HaveKeyWithValue(annotationTwo, "two")) + g.Expect(deployment.Spec.Template.Annotations).To(HaveKeyWithValue(annotationOne, "one")) + g.Expect(deployment.Spec.Template.Annotations).To(HaveKeyWithValue(annotationTwo, "two")) + g.Expect(deployment.OwnerReferences).To(HaveLen(1)) + }) + + }) +}
