Skip to content

Commit d63474e

Browse files
authored
Fix a bug where a TCP connection to a hostNetwork pod could rarely be resolved to the wrong service (#228)
1 parent 224680e commit d63474e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/mapper/pkg/kubefinder/kubefinder.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ func (k *KubeFinder) initIndexes(ctx context.Context) error {
5656
err := k.mgr.GetCache().IndexField(ctx, &corev1.Pod{}, podIPIndexField, func(object client.Object) []string {
5757
res := make([]string, 0)
5858
pod := object.(*corev1.Pod)
59+
60+
// host network pods use their node's IP address, it's not safe to assume this IP is unique to this pod
61+
if pod.Spec.HostNetwork || pod.DeletionTimestamp != nil || pod.Status.Phase != corev1.PodRunning {
62+
return res
63+
}
5964
for _, ip := range pod.Status.PodIPs {
60-
if pod.DeletionTimestamp != nil || pod.Status.Phase != corev1.PodRunning {
61-
continue
62-
}
6365
res = append(res, ip.IP)
6466
}
6567
return res

0 commit comments

Comments
 (0)