@@ -247,6 +247,50 @@ func TestNewServiceDiscovery_ExplicitProviderSurvivesALocalEnvironment(t *testin
247247
248248// The clusters registry owns orchestrator nodes only when the resolved provider
249249// is the static local one — there both planes are the same single instance.
250+ // A pod with host networking reports the same address twice, so the fixture
251+ // pulls them apart: the node's address is where the reference deploy listens,
252+ // the pod's where an orchestrator with its own network namespace does.
253+ func TestNewServiceDiscovery_KubernetesDialsTheNodeUnlessPreferPodIP (t * testing.T ) {
254+ t .Parallel ()
255+
256+ const (
257+ nodeIP = "10.0.0.5"
258+ podIP = "10.42.1.3"
259+ )
260+
261+ tests := map [string ]struct {
262+ preferPodIP bool
263+ want string
264+ }{
265+ "the default dials the node, where a host-network pod listens" : {
266+ preferPodIP : false , want : nodeIP ,
267+ },
268+ "K8S_PREFER_POD_IP dials the pod network" : {
269+ preferPodIP : true , want : podIP ,
270+ },
271+ }
272+
273+ for name , tt := range tests {
274+ t .Run (name , func (t * testing.T ) {
275+ t .Parallel ()
276+
277+ orchestrator := discoveredPod ("orchestrator-1" , "orchestrator" , nodeIP )
278+ orchestrator .Status .PodIP = podIP
279+ builder := discoveredPod ("template-manager-1" , "template-manager" , nodeIP )
280+ builder .Status .PodIP = podIP
281+
282+ config := discoveryConfig (cfg .ServiceDiscoveryProviderKubernetes , "" )
283+ config .K8sPreferPodIP = tt .preferPodIP
284+
285+ sd , err := newServiceDiscovery (t .Context (), config , fixedKubeClient (orchestrator , builder ), cfg .ServiceDiscoveryProviderKubernetes )
286+ require .NoError (t , err )
287+
288+ assert .Equal (t , []string {tt .want }, planeIPs (t , sd .nodes ))
289+ assert .Equal (t , []string {tt .want }, planeIPs (t , sd .templateBuilders ))
290+ })
291+ }
292+ }
293+
250294// Deriving it from the environment instead builds a Nomad or Kubernetes node
251295// plane that neither the periodic loop nor on-demand discovery ever consults,
252296// so an orchestrator that is not also a template builder never registers.
0 commit comments