Skip to content

Commit 4e98d75

Browse files
committed
focus
1 parent b22dd57 commit 4e98d75

File tree

5 files changed

+43
-28
lines changed

5 files changed

+43
-28
lines changed

internal/adc/translator/gatewayproxy.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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))

internal/provider/api7ee/provider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ func (d *api7eeProvider) NeedLeaderElection() bool {
262262

263263
// updateConfigForGatewayProxy update config for all referrers of the GatewayProxy
264264
func (d *api7eeProvider) updateConfigForGatewayProxy(tctx *provider.TranslateContext, gp *v1alpha1.GatewayProxy) error {
265-
config, err := d.translator.TranslateGatewayProxyToConfig(tctx, gp)
265+
config, err := d.translator.TranslateGatewayProxyToConfig(tctx, gp, "")
266266
if err != nil {
267267
return err
268268
}
@@ -282,7 +282,7 @@ func (d *api7eeProvider) updateConfigForGatewayProxy(tctx *provider.TranslateCon
282282
func (d *api7eeProvider) buildConfig(tctx *provider.TranslateContext, nnk types.NamespacedNameKind) (map[types.NamespacedNameKind]adctypes.Config, error) {
283283
configs := make(map[types.NamespacedNameKind]adctypes.Config, len(tctx.ResourceParentRefs[nnk]))
284284
for _, gp := range tctx.GatewayProxies {
285-
config, err := d.translator.TranslateGatewayProxyToConfig(tctx, &gp)
285+
config, err := d.translator.TranslateGatewayProxyToConfig(tctx, &gp, "")
286286
if err != nil {
287287
return nil, err
288288
}

internal/provider/apisix/provider.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
)
4545

4646
const ProviderType = "apisix"
47+
const ProviderTypeAPISIXStandalone = "apisix-standalone"
4748

4849
type apisixProvider struct {
4950
provider.Options
@@ -214,8 +215,12 @@ func (d *apisixProvider) Delete(ctx context.Context, obj client.Object) error {
214215

215216
func (d *apisixProvider) buildConfig(tctx *provider.TranslateContext, nnk types.NamespacedNameKind) (map[types.NamespacedNameKind]adctypes.Config, error) {
216217
configs := make(map[types.NamespacedNameKind]adctypes.Config, len(tctx.ResourceParentRefs[nnk]))
218+
var mode string
219+
if d.BackendMode == ProviderTypeAPISIXStandalone {
220+
mode = "endpoints"
221+
}
217222
for _, gp := range tctx.GatewayProxies {
218-
config, err := d.translator.TranslateGatewayProxyToConfig(tctx, &gp)
223+
config, err := d.translator.TranslateGatewayProxyToConfig(tctx, &gp, mode)
219224
if err != nil {
220225
return nil, err
221226
}
@@ -285,7 +290,11 @@ func (d *apisixProvider) NeedLeaderElection() bool {
285290

286291
// updateConfigForGatewayProxy update config for all referrers of the GatewayProxy
287292
func (d *apisixProvider) updateConfigForGatewayProxy(tctx *provider.TranslateContext, gp *v1alpha1.GatewayProxy) error {
288-
config, err := d.translator.TranslateGatewayProxyToConfig(tctx, gp)
293+
var mode string
294+
if d.BackendMode == ProviderTypeAPISIXStandalone {
295+
mode = "endpoints"
296+
}
297+
config, err := d.translator.TranslateGatewayProxyToConfig(tctx, gp, mode)
289298
if err != nil {
290299
return err
291300
}

test/e2e/crds/v2/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ spec:
155155
})
156156
})
157157

158-
It("dataplane unavailable", func() {
158+
FIt("dataplane unavailable", func() {
159159
if os.Getenv("PROVIDER_TYPE") == framework.ProviderTypeAPI7EE {
160160
Skip("skip for api7ee mode because it use dashboard admin api")
161161
}

test/e2e/gatewayapi/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ spec:
107107
Expect(gwyaml).To(ContainSubstring("message: the gateway has been accepted by the apisix-ingress-controller"), "checking Gateway condition message")
108108
})
109109

110-
It("dataplane unavailable", func() {
110+
FIt("dataplane unavailable", func() {
111111
if os.Getenv("PROVIDER_TYPE") == framework.ProviderTypeAPI7EE {
112112
Skip("skip for api7ee mode because it use dashboard admin api")
113113
}

0 commit comments

Comments
 (0)