@@ -161,6 +161,7 @@ type podConfiguration struct {
161161 isPrivileged bool
162162 labels map [string ]string
163163 requiresExtraNamespace bool
164+ hostNetwork bool
164165 needsIPRequestFromHostSubnet bool
165166}
166167
@@ -171,6 +172,7 @@ func generatePodSpec(config podConfiguration) *v1.Pod {
171172 }
172173 podSpec .Spec .NodeSelector = config .nodeSelector
173174 podSpec .Labels = config .labels
175+ podSpec .Spec .HostNetwork = config .hostNetwork
174176 if config .isPrivileged {
175177 podSpec .Spec .Containers [0 ].SecurityContext .Privileged = ptr .To (true )
176178 } else {
@@ -253,17 +255,19 @@ func inRange(cidr string, ip string) error {
253255 return fmt .Errorf ("ip [%s] is NOT in range %s" , ip , cidr )
254256}
255257
256- func connectToServer (clientPodConfig podConfiguration , serverIP string , port int ) error {
257- _ , err := e2ekubectl . RunKubectl (
258- clientPodConfig . namespace ,
258+ func connectToServer (clientPodConfig podConfiguration , serverIP string , port int , args ... string ) error {
259+ target := net . JoinHostPort ( serverIP , fmt . Sprintf ( "%d" , port ))
260+ baseArgs := [] string {
259261 "exec" ,
260262 clientPodConfig .name ,
261263 "--" ,
262264 "curl" ,
263265 "--connect-timeout" ,
264266 "2" ,
265- net .JoinHostPort (serverIP , fmt .Sprintf ("%d" , port )),
266- )
267+ }
268+ baseArgs = append (baseArgs , args ... )
269+
270+ _ , err := e2ekubectl .RunKubectl (clientPodConfig .namespace , append (baseArgs , target )... )
267271 return err
268272}
269273
@@ -308,16 +312,19 @@ func getSecondaryInterfaceMTU(clientPodConfig podConfiguration) (int, error) {
308312 return mtu , nil
309313}
310314
311- func pingServer (clientPodConfig podConfiguration , serverIP string ) error {
312- _ , err := e2ekubectl .RunKubectl (
313- clientPodConfig .namespace ,
315+ func pingServer (clientPodConfig podConfiguration , serverIP string , args ... string ) error {
316+ baseArgs := []string {
314317 "exec" ,
315318 clientPodConfig .name ,
316319 "--" ,
317320 "ping" ,
318321 "-c" , "1" , // send one ICMP echo request
319322 "-W" , "2" , // timeout after 2 seconds if no response
320- serverIP )
323+ }
324+ baseArgs = append (baseArgs , args ... )
325+
326+ _ , err := e2ekubectl .RunKubectl (clientPodConfig .namespace , append (baseArgs , serverIP )... )
327+
321328 return err
322329}
323330
@@ -381,6 +388,18 @@ func podIPForAttachment(k8sClient clientset.Interface, podNamespace string, podN
381388 return ips [ipIndex ], nil
382389}
383390
391+ func podIPsFromStatus (k8sClient clientset.Interface , podNamespace string , podName string ) ([]string , error ) {
392+ pod , err := k8sClient .CoreV1 ().Pods (podNamespace ).Get (context .Background (), podName , metav1.GetOptions {})
393+ if err != nil {
394+ return nil , err
395+ }
396+ podIPs := make ([]string , 0 , len (pod .Status .PodIPs ))
397+ for _ , podIP := range pod .Status .PodIPs {
398+ podIPs = append (podIPs , podIP .IP )
399+ }
400+ return podIPs , nil
401+ }
402+
384403func allowedClient (podName string ) string {
385404 return "allowed-" + podName
386405}
@@ -610,27 +629,27 @@ func allowedTCPPortsForPolicy(allowPorts ...int) []mnpapi.MultiNetworkPolicyPort
610629 return portAllowlist
611630}
612631
613- func reachServerPodFromClient (cs clientset.Interface , serverConfig podConfiguration , clientConfig podConfiguration , serverIP string , serverPort int ) error {
632+ func reachServerPodFromClient (cs clientset.Interface , serverConfig podConfiguration , clientConfig podConfiguration , serverIP string , serverPort int , args ... string ) error {
614633 updatedPod , err := cs .CoreV1 ().Pods (serverConfig .namespace ).Get (context .Background (), serverConfig .name , metav1.GetOptions {})
615634 if err != nil {
616635 return err
617636 }
618637
619638 if updatedPod .Status .Phase == v1 .PodRunning {
620- return connectToServer (clientConfig , serverIP , serverPort )
639+ return connectToServer (clientConfig , serverIP , serverPort , args ... )
621640 }
622641
623642 return fmt .Errorf ("pod not running. /me is sad" )
624643}
625644
626- func pingServerPodFromClient (cs clientset.Interface , serverConfig podConfiguration , clientConfig podConfiguration , serverIP string ) error {
645+ func pingServerPodFromClient (cs clientset.Interface , serverConfig podConfiguration , clientConfig podConfiguration , serverIP string , args ... string ) error {
627646 updatedPod , err := cs .CoreV1 ().Pods (serverConfig .namespace ).Get (context .Background (), serverConfig .name , metav1.GetOptions {})
628647 if err != nil {
629648 return err
630649 }
631650
632651 if updatedPod .Status .Phase == v1 .PodRunning {
633- return pingServer (clientConfig , serverIP )
652+ return pingServer (clientConfig , serverIP , args ... )
634653 }
635654
636655 return fmt .Errorf ("pod not running. /me is sad" )
0 commit comments