@@ -427,3 +427,118 @@ func TestFilterIstioEndpoint(t *testing.T) {
427427 })
428428 }
429429}
430+
431+ func TestBuildClusterLoadAssignment_InferenceServicePortFiltering (t * testing.T ) {
432+ tests := []struct {
433+ name string
434+ InferencePoolService bool
435+ expectedEndpoints int
436+ }{
437+ {
438+ name : "inference service includes endpoints from all ports" ,
439+ InferencePoolService : true ,
440+ expectedEndpoints : 3 ,
441+ },
442+ {
443+ name : "regular service filters endpoints by port name" ,
444+ InferencePoolService : false ,
445+ expectedEndpoints : 1 ,
446+ },
447+ }
448+
449+ for _ , tt := range tests {
450+ t .Run (tt .name , func (t * testing.T ) {
451+ svcLabels := make (map [string ]string )
452+ if tt .InferencePoolService {
453+ svcLabels [constants .InternalServiceSemantics ] = constants .ServiceSemanticsInferencePool
454+ }
455+
456+ svc := & model.Service {
457+ Hostname : "example.ns.svc.cluster.local" ,
458+ Attributes : model.ServiceAttributes {
459+ Name : "example" ,
460+ Namespace : "ns" ,
461+ Labels : svcLabels ,
462+ },
463+ Ports : model.PortList {
464+ {Port : 80 , Protocol : protocol .HTTP , Name : "http-80" },
465+ {Port : 8000 , Protocol : protocol .HTTP , Name : "http-8000" },
466+ {Port : 8001 , Protocol : protocol .HTTP , Name : "http-8001" },
467+ },
468+ }
469+
470+ proxy := & model.Proxy {
471+ Type : model .SidecarProxy ,
472+ IPAddresses : []string {"127.0.0.1" },
473+ Metadata : & model.NodeMetadata {
474+ Namespace : "ns" ,
475+ NodeName : "example" ,
476+ },
477+ ConfigNamespace : "ns" ,
478+ }
479+
480+ endpointIndex := model .NewEndpointIndex (model .NewXdsCache ())
481+ shards , _ := endpointIndex .GetOrCreateEndpointShard ("example.ns.svc.cluster.local" , "ns" )
482+ shards .Lock ()
483+ shards .Shards [model.ShardKey {Cluster : "cluster1" }] = []* model.IstioEndpoint {
484+ {
485+ Addresses : []string {"10.0.0.1" },
486+ ServicePortName : "http-80" ,
487+ EndpointPort : 80 ,
488+ HostName : "example.ns.svc.cluster.local" ,
489+ Namespace : "ns" ,
490+ },
491+ {
492+ Addresses : []string {"10.0.0.2" },
493+ ServicePortName : "http-8000" ,
494+ EndpointPort : 8000 ,
495+ HostName : "example.ns.svc.cluster.local" ,
496+ Namespace : "ns" ,
497+ },
498+ {
499+ Addresses : []string {"10.0.0.3" },
500+ ServicePortName : "http-8001" ,
501+ EndpointPort : 8001 ,
502+ HostName : "example.ns.svc.cluster.local" ,
503+ Namespace : "ns" ,
504+ },
505+ }
506+ shards .Unlock ()
507+
508+ env := model .NewEnvironment ()
509+ env .ConfigStore = model .NewFakeStore ()
510+ env .Watcher = meshwatcher .NewTestWatcher (& meshconfig.MeshConfig {RootNamespace : "istio-system" })
511+ meshNetworks := meshwatcher .NewFixedNetworksWatcher (nil )
512+ env .NetworksWatcher = meshNetworks
513+ env .ServiceDiscovery = & localServiceDiscovery {
514+ services : []* model.Service {svc },
515+ }
516+ xdsUpdater := xdsfake .NewFakeXDS ()
517+ if err := env .InitNetworksManager (xdsUpdater ); err != nil {
518+ t .Fatal (err )
519+ }
520+ env .Init ()
521+
522+ push := model .NewPushContext ()
523+ push .InitContext (env , nil , nil )
524+ env .SetPushContext (push )
525+
526+ builder := NewCDSEndpointBuilder (
527+ proxy , push ,
528+ "outbound|80||example.ns.svc.cluster.local" ,
529+ model .TrafficDirectionOutbound , "" , "example.ns.svc.cluster.local" , 80 ,
530+ svc , nil )
531+
532+ cla := builder .BuildClusterLoadAssignment (endpointIndex )
533+
534+ var totalEndpoints int
535+ for _ , localityLbEndpoints := range cla .Endpoints {
536+ totalEndpoints += len (localityLbEndpoints .LbEndpoints )
537+ }
538+
539+ if totalEndpoints != tt .expectedEndpoints {
540+ t .Errorf ("expected %d endpoints, got %d" , tt .expectedEndpoints , totalEndpoints )
541+ }
542+ })
543+ }
544+ }
0 commit comments