@@ -36,7 +36,7 @@ import (
3636 "github.com/apache/apisix-ingress-controller/internal/utils"
3737)
3838
39- func (t * Translator ) TranslateGatewayProxyToConfig (tctx * provider.TranslateContext , gatewayProxy * v1alpha1.GatewayProxy ) (* types.Config , error ) {
39+ func (t * Translator ) TranslateGatewayProxyToConfig (tctx * provider.TranslateContext , gatewayProxy * v1alpha1.GatewayProxy , mode string ) (* types.Config , error ) {
4040 if gatewayProxy == nil || gatewayProxy .Spec .Provider == nil {
4141 return nil , nil
4242 }
@@ -94,28 +94,34 @@ func (t *Translator) TranslateGatewayProxyToConfig(tctx *provider.TranslateConte
9494
9595 // APISIXStandalone, configurations need to be sent to each data plane instance;
9696 // In other cases, the service is directly accessed as the adc backend server address.
97- endpoint := tctx .EndpointSlices [namespacedName ]
98- if endpoint == nil {
99- return nil , nil
100- }
101- upstreamNodes , err := t .TranslateBackendRefWithFilter (tctx , gatewayv1.BackendRef {
102- BackendObjectReference : gatewayv1.BackendObjectReference {
103- Name : gatewayv1 .ObjectName (provider .ControlPlane .Service .Name ),
104- Namespace : (* gatewayv1 .Namespace )(& gatewayProxy .Namespace ),
105- Port : ptr .To (gatewayv1 .PortNumber (provider .ControlPlane .Service .Port )),
106- },
107- }, func (endpoint * discoveryv1.Endpoint ) bool {
108- if endpoint .Conditions .Terminating != nil && * endpoint .Conditions .Terminating {
109- log .Debugw ("skip terminating endpoint" , zap .Any ("endpoint" , endpoint ))
110- return false
97+ if mode == "endpoints" {
98+ endpoint := tctx .EndpointSlices [namespacedName ]
99+ if endpoint == nil {
100+ return nil , nil
101+ }
102+ upstreamNodes , err := t .TranslateBackendRefWithFilter (tctx , gatewayv1.BackendRef {
103+ BackendObjectReference : gatewayv1.BackendObjectReference {
104+ Name : gatewayv1 .ObjectName (provider .ControlPlane .Service .Name ),
105+ Namespace : (* gatewayv1 .Namespace )(& gatewayProxy .Namespace ),
106+ Port : ptr .To (gatewayv1 .PortNumber (provider .ControlPlane .Service .Port )),
107+ },
108+ }, func (endpoint * discoveryv1.Endpoint ) bool {
109+ if endpoint .Conditions .Terminating != nil && * endpoint .Conditions .Terminating {
110+ log .Debugw ("skip terminating endpoint" , zap .Any ("endpoint" , endpoint ))
111+ return false
112+ }
113+ return true
114+ })
115+ if err != nil {
116+ return nil , err
117+ }
118+ for _ , node := range upstreamNodes {
119+ config .ServerAddrs = append (config .ServerAddrs , "http://" + net .JoinHostPort (node .Host , strconv .Itoa (node .Port )))
120+ }
121+ } else {
122+ config .ServerAddrs = []string {
123+ fmt .Sprintf ("http://%s.%s:%d" , provider .ControlPlane .Service .Name , gatewayProxy .Namespace , provider .ControlPlane .Service .Port ),
111124 }
112- return true
113- })
114- if err != nil {
115- return nil , err
116- }
117- for _ , node := range upstreamNodes {
118- config .ServerAddrs = append (config .ServerAddrs , "http://" + net .JoinHostPort (node .Host , strconv .Itoa (node .Port )))
119125 }
120126
121127 log .Debugw ("add server address to config.ServiceAddrs" , zap .Strings ("config.ServerAddrs" , config .ServerAddrs ))
0 commit comments