Re: [PR] fix: support filter endpoint when translate backend ref. [apisix-ingress-controller]

2025-07-03 Thread via GitHub


ronething merged PR #2451:
URL: https://github.com/apache/apisix-ingress-controller/pull/2451


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] fix: support filter endpoint when translate backend ref. [apisix-ingress-controller]

2025-07-03 Thread via GitHub


ronething commented on code in PR #2451:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/2451#discussion_r2184469943


##
internal/provider/adc/translator/httproute.go:
##
@@ -312,11 +315,19 @@ func (t *Translator) translateEndpointSlice(portName 
*string, weight int, endpoi
return nodes
 }
 
-func (t *Translator) TranslateBackendRef(tctx *provider.TranslateContext, ref 
gatewayv1.BackendRef) (adctypes.UpstreamNodes, error) {
-   return t.translateBackendRef(tctx, ref)
+func DefaultEndpointFilter(endpoint *discoveryv1.Endpoint) bool {
+   if endpoint.Conditions.Ready != nil && !*endpoint.Conditions.Ready {
+   log.Debugw("skip not ready endpoint", zap.Any("endpoint", 
endpoint))
+   return false
+   }
+   return true
+}
+
+func (t *Translator) TranslateBackendRefWithFilter(tctx 
*provider.TranslateContext, ref gatewayv1.BackendRef, endpointFilter 
func(*discoveryv1.Endpoint) bool) (adctypes.UpstreamNodes, error) {
+   return t.translateBackendRef(tctx, ref, endpointFilter)
 }
 
-func (t *Translator) translateBackendRef(tctx *provider.TranslateContext, ref 
gatewayv1.BackendRef) (adctypes.UpstreamNodes, error) {
+func (t *Translator) translateBackendRef(tctx *provider.TranslateContext, ref 
gatewayv1.BackendRef, endpointFilter func(*discoveryv1.Endpoint) bool) 
(adctypes.UpstreamNodes, error) {

Review Comment:
   Currently, only the code that retrieves apisix standalone nodes calls the 
`TranslateBackendRefWithFilter` method, as it is called from another package, 
so it has been exported.
   
   We can consider making a unified adjustment in the next PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] fix: support filter endpoint when translate backend ref. [apisix-ingress-controller]

2025-07-03 Thread via GitHub


ronething commented on code in PR #2451:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/2451#discussion_r2184467656


##
internal/provider/adc/translator/httproute.go:
##
@@ -283,7 +283,7 @@ func (t *Translator) fillHTTPRoutePolicies(routes 
[]*adctypes.Route, policies []
}
 }
 
-func (t *Translator) translateEndpointSlice(portName *string, weight int, 
endpointSlices []discoveryv1.EndpointSlice) adctypes.UpstreamNodes {
+func (t *Translator) translateEndpointSlice(portName *string, weight int, 
endpointSlices []discoveryv1.EndpointSlice, endpointFilter 
func(*discoveryv1.Endpoint) bool) adctypes.UpstreamNodes {

Review Comment:
   There is still a need for more clarification. It may not be appropriate to 
make adjustments in this PR, as it involves more code changes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



Re: [PR] fix: support filter endpoint when translate backend ref. [apisix-ingress-controller]

2025-07-03 Thread via GitHub


dspo commented on code in PR #2451:
URL: 
https://github.com/apache/apisix-ingress-controller/pull/2451#discussion_r2184269082


##
internal/provider/adc/translator/httproute.go:
##
@@ -312,11 +315,19 @@ func (t *Translator) translateEndpointSlice(portName 
*string, weight int, endpoi
return nodes
 }
 
-func (t *Translator) TranslateBackendRef(tctx *provider.TranslateContext, ref 
gatewayv1.BackendRef) (adctypes.UpstreamNodes, error) {
-   return t.translateBackendRef(tctx, ref)
+func DefaultEndpointFilter(endpoint *discoveryv1.Endpoint) bool {
+   if endpoint.Conditions.Ready != nil && !*endpoint.Conditions.Ready {
+   log.Debugw("skip not ready endpoint", zap.Any("endpoint", 
endpoint))
+   return false
+   }
+   return true
+}
+
+func (t *Translator) TranslateBackendRefWithFilter(tctx 
*provider.TranslateContext, ref gatewayv1.BackendRef, endpointFilter 
func(*discoveryv1.Endpoint) bool) (adctypes.UpstreamNodes, error) {
+   return t.translateBackendRef(tctx, ref, endpointFilter)
 }
 
-func (t *Translator) translateBackendRef(tctx *provider.TranslateContext, ref 
gatewayv1.BackendRef) (adctypes.UpstreamNodes, error) {
+func (t *Translator) translateBackendRef(tctx *provider.TranslateContext, ref 
gatewayv1.BackendRef, endpointFilter func(*discoveryv1.Endpoint) bool) 
(adctypes.UpstreamNodes, error) {

Review Comment:
   These two functions are exactly the same. Can they be combined into one 
function?



##
internal/provider/adc/translator/httproute.go:
##
@@ -283,7 +283,7 @@ func (t *Translator) fillHTTPRoutePolicies(routes 
[]*adctypes.Route, policies []
}
 }
 
-func (t *Translator) translateEndpointSlice(portName *string, weight int, 
endpointSlices []discoveryv1.EndpointSlice) adctypes.UpstreamNodes {
+func (t *Translator) translateEndpointSlice(portName *string, weight int, 
endpointSlices []discoveryv1.EndpointSlice, endpointFilter 
func(*discoveryv1.Endpoint) bool) adctypes.UpstreamNodes {

Review Comment:
   This method seems to cover the functionality of 
`translateEndpointSliceForIngress`. It seems that 
`translateEndpointSliceForIngress` can be removed or called 
`translateEndpointSlice ` in it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]