ha: limit ingress pool refusal to activator-managed routes
Co-Authored-By: GPT-6 Astra <noreply@openai.com>
4 files changed,
+54
−2
internal/activator/activator.go+1 −1internal/activator/ha_pool_test.go+21 −0internal/edge/haingress.go+1 −1internal/edge/haingress_internal_test.go+31 −0
diff --git a/internal/activator/activator.go b/internal/activator/activator.go| index 1a57b0161..e66ed4ec6 100644 |
| --- a/internal/activator/activator.go |
| +++ b/internal/activator/activator.go |
| @@ -6281,7 +6281,7 @@ func (a *Service) logUnresolvedAtExit() { |
| // it); false means "not activator-managed — proxy straight", so the edge can |
| // call it unconditionally. |
| func (a *Service) ServeHTTP(w http.ResponseWriter, r *http.Request, rt registry.Route, proxy http.Handler) bool { |
| - if !a.LocalEligible(rt) { |
| + if rt.ActivatorOwned() && !a.LocalEligible(rt) { |
| edge.HAUnavailableResponse(w, r) |
| return true |
| } |
diff --git a/internal/activator/ha_pool_test.go b/internal/activator/ha_pool_test.go| index 135465da7..6bcaddcab 100644 |
| --- a/internal/activator/ha_pool_test.go |
| +++ b/internal/activator/ha_pool_test.go |
| @@ -13,6 +13,27 @@ import ( |
| ) |
| func TestPoolGateCannotFallBackLocal(t *testing.T) { |
| + for _, kind := range []string{"forward", "static", "unit", "non-hibernating", "tunnel"} { |
| + t.Run(kind, func(t *testing.T) { |
| + a := New(Config{}, poolDeniedBackend{}, nil) |
| + rt := registry.Route{Host: "pass.example.com", Kind: kind, Pool: ""} |
| + if kind == "unit" || kind == "non-hibernating" || kind == "tunnel" { |
| + rt.Kind = "instance" |
| + } |
| + if kind == "unit" { |
| + rt.Backing = "unit" |
| + } |
| + if kind == "tunnel" { |
| + rt.Tunnel = "peer" |
| + } |
| + w := httptest.NewRecorder() |
| + handled := a.ServeHTTP(w, httptest.NewRequest(http.MethodGet, "https://"+rt.Host+"/", nil), rt, http.HandlerFunc(func(http.ResponseWriter, *http.Request) { t.Fatal("activator called upstream") })) |
| + if handled || w.Body.Len() != 0 { |
| + t.Fatalf("unmanaged route handled=%v status=%d body=%s", handled, w.Code, w.Body.String()) |
| + } |
| + }) |
| + } |
| + |
| t.Run("placement", func(t *testing.T) { |
| now := time.Now() |
| for _, mode := range []string{"off", "nil", "unusable", "self only", "peer", "low peer"} { |
diff --git a/internal/edge/haingress.go b/internal/edge/haingress.go| index f1bb5831c..335c1007f 100644 |
| --- a/internal/edge/haingress.go |
| +++ b/internal/edge/haingress.go |
| @@ -77,7 +77,7 @@ func (e *Edge) routeHAIngress(w http.ResponseWriter, r *http.Request, host strin |
| return false |
| } |
| if !known { |
| - if local && !e.localPoolEligible(up.route) { |
| + if local && up.hibernating && !up.route.IsForward() && !up.platformAlias && !up.viaTunnel && !e.localPoolEligible(up.route) { |
| HAUnavailableResponse(w, r) |
| return true |
| } |
diff --git a/internal/edge/haingress_internal_test.go b/internal/edge/haingress_internal_test.go| index 60c7b7ec8..257b5b9d6 100644 |
| --- a/internal/edge/haingress_internal_test.go |
| +++ b/internal/edge/haingress_internal_test.go |
| @@ -267,3 +267,34 @@ func TestHAIngressRegionalReceiver(t *testing.T) { |
| }) |
| } |
| } |
| + |
| +func TestPoolGateCannotFallBackLocal(t *testing.T) { |
| + for _, kind := range []string{"forward", "static", "unit", "non-hibernating", "tunnel", "platform-alias", "managed"} { |
| + t.Run(kind, func(t *testing.T) { |
| + x := newFwScene(t, fwOpts{aAct: &ingressForwarder{&fwAct{}}}) |
| + up := upstream{route: registry.Route{Host: fwHost, Kind: "instance"}, hibernating: true} |
| + switch kind { |
| + case "forward": |
| + up.route.Kind = registry.KindForward |
| + case "static": |
| + up.route.Kind, up.hibernating = "static", false |
| + case "unit": |
| + up.route.Backing, up.hibernating = "unit", false |
| + case "non-hibernating": |
| + up.hibernating = false |
| + case "tunnel": |
| + up.viaTunnel = true |
| + case "platform-alias": |
| + up.platformAlias = true |
| + } |
| + w := httptest.NewRecorder() |
| + handled := x.a.edge.routeHAIngress(w, httptest.NewRequest(http.MethodGet, "https://"+fwHost+"/", nil), fwHost, up, true) |
| + if handled != (kind == "managed") { |
| + t.Fatalf("handled=%v status=%d", handled, w.Code) |
| + } |
| + if kind == "managed" && w.Code != http.StatusServiceUnavailable { |
| + t.Fatalf("status=%d", w.Code) |
| + } |
| + }) |
| + } |
| +} |