AlinsRan commented on code in PR #2846:
URL:
https://github.com/apache/apisix-ingress-controller/pull/2846#discussion_r3780474283
##########
internal/controller/gateway_controller.go:
##########
@@ -194,10 +194,14 @@ func (r *GatewayReconciler) Reconcile(ctx
context.Context, req ctrl.Request) (ct
msg: "gateway proxy not found",
}
} else {
- for _, addr := range gatewayProxy.Spec.StatusAddress {
- if addr == "" {
- continue
- }
+ statusAddresses, err := r.resolveStatusAddresses(ctx,
&gatewayProxy)
+ if err != nil {
+ // fail the reconcile so a missing or invalid publish
Service retries
+ // with backoff, mirroring the Ingress status path
+ r.Log.Error(err, "failed to resolve gateway status
addresses", "gateway", req.NamespacedName)
+ return ctrl.Result{}, err
Review Comment:
This returns before `r.Provider.Update` (L234), so a `publishService` that
cannot be resolved — a typo, or the Service not created yet — stops the Gateway
from being pushed to APISIX at all. A status-only problem becomes a data plane
outage.
The comment has it backwards: `IngressReconciler.updateStatus` runs *after*
`r.Provider.Update` (ingress_controller.go:207 vs 216). Suggest logging and
publishing no address instead, as the `gateway proxy not found` branch above
already does.
##########
internal/controller/gateway_controller.go:
##########
@@ -259,6 +263,38 @@ func (r *GatewayReconciler) Reconcile(ctx context.Context,
req ctrl.Request) (ct
return ctrl.Result{}, nil
}
+// resolveStatusAddresses returns the addresses to publish in
+// Gateway.status.addresses: the statically configured statusAddress if set,
+// otherwise the external addresses of the Service named by publishService.
+// This mirrors the Ingress status path, so the same GatewayProxy yields the
+// same addresses for both APIs.
+func (r *GatewayReconciler) resolveStatusAddresses(
+ ctx context.Context,
+ gatewayProxy *v1alpha1.GatewayProxy,
+) ([]string, error) {
+ if len(gatewayProxy.Spec.StatusAddress) > 0 {
+ return utils.Filter(gatewayProxy.Spec.StatusAddress, func(addr
string) bool {
+ return addr != ""
+ }), nil
+ }
+
+ if gatewayProxy.Spec.PublishService == "" {
+ return nil, nil
+ }
+
+ // a bare name is resolved against the GatewayProxy's namespace
+ svc, err := resolvePublishService(ctx, r.Client,
gatewayProxy.Spec.PublishService, gatewayProxy.GetNamespace())
Review Comment:
A bare `publishService` name resolves to a different namespace here than in
the Ingress path, which uses `ingress.Namespace`
(ingress_controller.go:711-718). A Gateway's GatewayProxy always lives in the
Gateway's namespace (utils.go:1311), but an Ingress's comes from the
IngressClass parameters namespace, so the two rarely agree: GatewayProxy in
`ingress-apisix` + Ingress in `app` sends the Ingress path to
`app/apisix-gateway` (NotFound) and this one to `ingress-apisix/apisix-gateway`.
The namespace used here is the more defensible rule; the Ingress path should
follow it, and the comment needs adjusting either way.
--
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]