in pkg/k8s/pod_utils.go [24:46]
func LookupContainerPortAndName(pod *corev1.Pod, port intstr.IntOrString, protocol corev1.Protocol) (int32, string, error) {
for _, podContainer := range pod.Spec.Containers {
for _, podPort := range podContainer.Ports {
if podPort.Protocol != protocol {
continue
}
switch port.Type {
case intstr.String:
if podPort.Name == port.StrVal {
return podPort.ContainerPort, podPort.Name, nil
}
case intstr.Int:
if podPort.ContainerPort == port.IntVal {
return podPort.ContainerPort, podPort.Name, nil
}
}
}
}
if port.Type == intstr.Int {
return port.IntVal, "", nil
}
return 0, "", errors.Errorf("unable to find port %s on pod %s", port.String(), NamespacedName(pod))
}