From 821ffbb42b909f1e93ef63818fb89a96c02759bf Mon Sep 17 00:00:00 2001 From: ugurkenar Date: Tue, 15 Oct 2024 18:36:04 +0300 Subject: [PATCH] fix linter service port check for native sidecars --- internal/lint/svc.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/lint/svc.go b/internal/lint/svc.go index bb33e466..c55e5b81 100644 --- a/internal/lint/svc.go +++ b/internal/lint/svc.go @@ -143,7 +143,15 @@ func checkServicePort(port v1.ServicePort, ports map[string]string) bool { // PortsForPod computes a port map for a given pod. func portsForPod(pod *v1.Pod, ports map[string]string) { - for _, co := range pod.Spec.Containers { + cos := append([]v1.Container{}, pod.Spec.Containers...) + + for _, ico := range pod.Spec.InitContainers { + if ico.RestartPolicy != nil && *ico.RestartPolicy == v1.ContainerRestartPolicyAlways { + cos = append(cos, ico) + } + } + + for _, co := range cos { for _, p := range co.Ports { ports[portFQN(p.Protocol, strconv.Itoa(int(p.ContainerPort)))] = co.Name if p.Name != "" {