Feat: add containerPort support to sidecar trait (#7254)

* feat: add containerPort support to sidecar trait (#6420)

Signed-off-by: kampitojha <kampitojha@users.noreply.github.com>

* test: increase eventually timeout in trait_test.go to prevent E2E flakes

Signed-off-by: kampitojha <kampitojha@users.noreply.github.com>

---------

Signed-off-by: kampitojha <kampitojha@users.noreply.github.com>
Co-authored-by: kampitojha <kampitojha@users.noreply.github.com>
This commit is contained in:
Kampit Ojha
2026-08-05 21:19:20 -07:00
committed by GitHub
co-authored by kampitojha
parent c1abcb8bdf
commit f15305a5f6
4 changed files with 36 additions and 2 deletions
@@ -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: {
@@ -33,4 +33,8 @@ spec:
volumes:
- name: varlog
path: /var/log
ports:
- containerPort: 8080
protocol: TCP
name: http
```
+2 -2
View File
@@ -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())
})
})
})
@@ -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: {