From f15305a5f62a84d4f384415600bedcb503962e9c Mon Sep 17 00:00:00 2001 From: Kampit Ojha <97059622+kampitojha@users.noreply.github.com> Date: Thu, 6 Aug 2026 09:49:20 +0530 Subject: [PATCH] Feat: add containerPort support to sidecar trait (#7254) * feat: add containerPort support to sidecar trait (#6420) Signed-off-by: kampitojha * test: increase eventually timeout in trait_test.go to prevent E2E flakes Signed-off-by: kampitojha --------- Signed-off-by: kampitojha Co-authored-by: kampitojha --- .../templates/defwithtemplate/sidecar.yaml | 15 +++++++++++++++ references/docgen/def-doc/trait/sidecar.eg.md | 4 ++++ test/e2e-test/trait_test.go | 4 ++-- .../definitions/internal/trait/sidecar.cue | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/charts/vela-core/templates/defwithtemplate/sidecar.yaml b/charts/vela-core/templates/defwithtemplate/sidecar.yaml index 316f21b73..31e8c7f9a 100644 --- a/charts/vela-core/templates/defwithtemplate/sidecar.yaml +++ b/charts/vela-core/templates/defwithtemplate/sidecar.yaml @@ -46,6 +46,9 @@ spec: if parameter["readinessProbe"] != _|_ { readinessProbe: parameter.readinessProbe } + if parameter["ports"] != _|_ { + ports: parameter.ports + } }] } parameter: { @@ -102,6 +105,18 @@ spec: // +usage=Instructions for assessing whether the container is in a suitable state to serve traffic. readinessProbe?: #HealthProbe + + // +usage=Specify the ports of the sidecar container + ports?: [...{ + // +usage=The port that the container exposes + containerPort: int & >0 & <=65535 + // +usage=The protocol for the port + protocol: *"TCP" | "UDP" | "SCTP" + // +usage=The name for the port + name?: string + // +usage=The host port to map to the container port + hostPort?: int & >0 & <=65535 + }] } #HealthProbe: { diff --git a/references/docgen/def-doc/trait/sidecar.eg.md b/references/docgen/def-doc/trait/sidecar.eg.md index 8945ba435..1eb2b447b 100644 --- a/references/docgen/def-doc/trait/sidecar.eg.md +++ b/references/docgen/def-doc/trait/sidecar.eg.md @@ -33,4 +33,8 @@ spec: volumes: - name: varlog path: /var/log + ports: + - containerPort: 8080 + protocol: TCP + name: http ``` diff --git a/test/e2e-test/trait_test.go b/test/e2e-test/trait_test.go index 28d6003d1..bb0ba59e7 100644 --- a/test/e2e-test/trait_test.go +++ b/test/e2e-test/trait_test.go @@ -78,7 +78,7 @@ var _ = Describe("Trait tests", func() { g.Expect(deploy.Spec.Template.Spec.Containers[1].Name).Should(Equal("busybox-sidecar")) g.Expect(deploy.Spec.Template.Spec.Containers[1].Image).Should(Equal("busybox:1.34")) g.Expect(deploy.Spec.Template.Spec.Containers[1].Command).Should(Equal([]string{"sleep", "864000"})) - }, 15*time.Second).Should(Succeed()) + }, 60*time.Second).Should(Succeed()) }) It("Test json-merge-patch trait", func() { @@ -100,7 +100,7 @@ var _ = Describe("Trait tests", func() { g.Expect(deploy.Spec.Template.Spec.Containers[0].Name).Should(Equal("busybox-new")) g.Expect(deploy.Spec.Template.Spec.Containers[0].Image).Should(Equal("busybox:1.34")) g.Expect(deploy.Spec.Template.Spec.Containers[0].Command).Should(Equal([]string{"sleep", "864000"})) - }, 15*time.Second).Should(Succeed()) + }, 60*time.Second).Should(Succeed()) }) }) }) diff --git a/vela-templates/definitions/internal/trait/sidecar.cue b/vela-templates/definitions/internal/trait/sidecar.cue index 2d3dbf4a3..845e2bd2a 100644 --- a/vela-templates/definitions/internal/trait/sidecar.cue +++ b/vela-templates/definitions/internal/trait/sidecar.cue @@ -37,6 +37,9 @@ template: { if parameter["readinessProbe"] != _|_ { readinessProbe: parameter.readinessProbe } + if parameter["ports"] != _|_ { + ports: parameter.ports + } }] } parameter: { @@ -93,6 +96,18 @@ template: { // +usage=Instructions for assessing whether the container is in a suitable state to serve traffic. readinessProbe?: #HealthProbe + + // +usage=Specify the ports of the sidecar container + ports?: [...{ + // +usage=The port that the container exposes + containerPort: int & >0 & <=65535 + // +usage=The protocol for the port + protocol: *"TCP" | "UDP" | "SCTP" + // +usage=The name for the port + name?: string + // +usage=The host port to map to the container port + hostPort?: int & >0 & <=65535 + }] } #HealthProbe: {