| new file mode 100644 |
| index 000000000..5a804e382 |
| --- /dev/null |
| +++ b/internal/registry/pathroute.go |
| @@ -0,0 +1,51 @@ |
| +package registry |
| + |
| +// Path routes across boxes (#186): the eligibility rule for a path route |
| +// whose front and target live on different boxes. The same-box case keeps |
| +// the edge's own answer; these two predicates are the cross-box rule only, |
| +// shared by the registry's reconcile (which writes path_front/path_target |
| +// into the edges file) and the edge's selection, so the two can never |
| +// disagree about which routes take part. |
| + |
| +// PathFront reports whether rt may front a cross-box path route: an |
| +// instance or static route that is not a forward row, a demo or a sidecar. |
| +// Status does not matter (a starting front still owns its hostname), and |
| +// HA changes nothing. |
| +func PathFront(rt Route) bool { |
| + if rt.Kind != "instance" && rt.Kind != "static" { |
| + return false |
| + } |
| + return !rt.IsForward() && !rt.IsDemo() && !rt.IsSidecar() |
| +} |
| + |
| +// PathTarget reports whether rt may be the target of a cross-box path |
| +// route: PathFront's rule plus Status "ready". HA changes nothing. |
| +func PathTarget(rt Route) bool { |
| + return rt.Status == "ready" && PathFront(rt) |
| +} |
| + |
| +// PathEligibilityCase is one row of PathEligibilityCases. |
| +type PathEligibilityCase struct { |
| + Name string |
| + Route Route |
| + Front, Target bool |
| +} |
| + |
| +// PathEligibilityCases is a test table, not runtime data: the expected |
| +// PathFront and PathTarget answers for one route of every kind plus the |
| +// flags that must not change them. It lives in a non-test file so tests |
| +// in other packages (the edges-file equivalence guard) run the same rows. |
| +// Every kind named on Route.Kind, plus KindForward, needs a row here |
| +// (TestPathPredicatesNameEveryKind). |
| +var PathEligibilityCases = []PathEligibilityCase{ |
| + {Name: "ready instance", Route: Route{Kind: "instance", Status: "ready"}, Front: true, Target: true}, |
| + {Name: "ready static", Route: Route{Kind: "static", Status: "ready"}, Front: true, Target: true}, |
| + {Name: "starting instance", Route: Route{Kind: "instance", Status: "starting"}, Front: true, Target: false}, |
| + {Name: "ready service", Route: Route{Kind: "service", Status: "ready"}, Front: false, Target: false}, |
| + {Name: "ready sidecar", Route: Route{Kind: "sidecar", Status: "ready"}, Front: false, Target: false}, |
| + {Name: "ready forward", Route: Route{Kind: KindForward, Status: "ready"}, Front: false, Target: false}, |
| + {Name: "ready demo instance", Route: Route{Kind: "instance", Status: "ready", DemoID: "demo-1"}, Front: false, Target: false}, |
| + {Name: "ready HA instance", Route: Route{Kind: "instance", Status: "ready", HA: true}, Front: true, Target: true}, |
| + {Name: "ready replica instance", Route: Route{Kind: "instance", Status: "ready", Replica: true}, Front: true, Target: true}, |
| + {Name: "ready hibernating instance", Route: Route{Kind: "instance", Status: "ready", Hibernate: true}, Front: true, Target: true}, |
| +} |