@@ -117,11 +117,31 @@ func (t *Translator) TranslateIngress(tctx *provider.TranslateContext, obj *netw
117117 } else if backendService .Port .Name != "" {
118118 servicePortName = backendService .Port .Name
119119 }
120- _ = servicePort
120+
121+ getService := tctx .Services [types.NamespacedName {
122+ Namespace : obj .Namespace ,
123+ Name : backendService .Name ,
124+ }]
125+ if getService == nil {
126+ continue
127+ }
128+
129+ var getServicePort * corev1.ServicePort
130+ for _ , port := range getService .Spec .Ports {
131+ port := port
132+ if servicePort > 0 && port .Port == servicePort {
133+ getServicePort = & port
134+ break
135+ }
136+ if servicePortName != "" && port .Name == servicePortName {
137+ getServicePort = & port
138+ break
139+ }
140+ }
121141
122142 // convert the EndpointSlice to upstream nodes
123143 if len (endpointSlices ) > 0 {
124- upstream .Nodes = t .translateEndpointSliceForIngress (1 , endpointSlices , servicePortName )
144+ upstream .Nodes = t .translateEndpointSliceForIngress (1 , endpointSlices , getServicePort )
125145 }
126146
127147 // if there is no upstream node, create a placeholder node
@@ -171,16 +191,16 @@ func (t *Translator) TranslateIngress(tctx *provider.TranslateContext, obj *netw
171191}
172192
173193// translateEndpointSliceForIngress create upstream nodes from EndpointSlice
174- func (t * Translator ) translateEndpointSliceForIngress (weight int , endpointSlices []discoveryv1.EndpointSlice , portName string ) adctypes.UpstreamNodes {
194+ func (t * Translator ) translateEndpointSliceForIngress (weight int , endpointSlices []discoveryv1.EndpointSlice , servciePort * corev1. ServicePort ) adctypes.UpstreamNodes {
175195 var nodes adctypes.UpstreamNodes
176196 if len (endpointSlices ) == 0 {
177197 return nodes
178198 }
179199
180200 for _ , endpointSlice := range endpointSlices {
181201 for _ , port := range endpointSlice .Ports {
182- // if the port name is specified, only use the matching port
183- if portName != "" && * port .Name != portName {
202+ // if the port number is specified, only use the matching port
203+ if servciePort != nil && * port .Name != servciePort . Name {
184204 continue
185205 }
186206 for _ , endpoint := range endpointSlice .Endpoints {
0 commit comments