From eee4e8efb30bd27373eaf08f852312ce598e01ed Mon Sep 17 00:00:00 2001 From: ilyam8 Date: Fri, 3 Feb 2023 16:12:30 +0200 Subject: [PATCH] fix targets discovery for containers with no exposed ports --- pipeline/discovery/kubernetes/pod.go | 54 ++++++++++++++-------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/pipeline/discovery/kubernetes/pod.go b/pipeline/discovery/kubernetes/pod.go index c32c5f2..4001026 100644 --- a/pipeline/discovery/kubernetes/pod.go +++ b/pipeline/discovery/kubernetes/pod.go @@ -174,34 +174,34 @@ func (p Pod) buildTargets(pod *apiv1.Pod) (targets []model.Target) { } target.hash = hash - return []model.Target{target} - } - - for _, port := range container.Ports { - portNum := strconv.FormatUint(uint64(port.ContainerPort), 10) - target := &PodTarget{ - tuid: podTUIDWithPort(pod, container, port), - Address: net.JoinHostPort(pod.Status.PodIP, portNum), - Namespace: pod.Namespace, - Name: pod.Name, - Annotations: toMapInterface(pod.Annotations), - Labels: toMapInterface(pod.Labels), - NodeName: pod.Spec.NodeName, - PodIP: pod.Status.PodIP, - ContName: container.Name, - Image: container.Image, - Env: toMapInterface(env), - Port: portNum, - PortName: port.Name, - PortProtocol: string(port.Protocol), - } - hash, err := calcHash(target) - if err != nil { - continue - } - target.hash = hash - targets = append(targets, target) + } else { + for _, port := range container.Ports { + portNum := strconv.FormatUint(uint64(port.ContainerPort), 10) + target := &PodTarget{ + tuid: podTUIDWithPort(pod, container, port), + Address: net.JoinHostPort(pod.Status.PodIP, portNum), + Namespace: pod.Namespace, + Name: pod.Name, + Annotations: toMapInterface(pod.Annotations), + Labels: toMapInterface(pod.Labels), + NodeName: pod.Spec.NodeName, + PodIP: pod.Status.PodIP, + ContName: container.Name, + Image: container.Image, + Env: toMapInterface(env), + Port: portNum, + PortName: port.Name, + PortProtocol: string(port.Protocol), + } + hash, err := calcHash(target) + if err != nil { + continue + } + target.hash = hash + + targets = append(targets, target) + } } } return targets