feat: add "nearest.<service>.internal" mode to internal DNS (#159)

* feat: Adding a "nearest.service.local" mode to internal DNS

* Pass listenAddr to internal DNS server (rather than calling into network.MachineIP)

Also adds an exact round-robin via "rr.{service}" mode. Not sure we want that over random or not, though.

* Remove the resolved count and rotating round-robin. "rr.name" mode is now the same as default with random shuffle.

* Add test on nearest internal DNS lookup

* Add docs on internal DNS order modes
This commit is contained in:
Justin Bradford
2025-10-29 14:25:59 +10:00
committed by GitHub
parent 6af7a9861d
commit ba6290d616
4 changed files with 147 additions and 4 deletions
@@ -59,3 +59,75 @@ Address: 10.210.1.3
Name: worker.internal
Address: 10.210.1.4
```
## IP Ordering Mode
Additionally, the IP ordering preference can be specified with a `rr` (round-robin) or `nearest` subdomain prefix.
### `rr` (round-robin) *current default*
Randomly shuffled order on each lookup.
```
$ nslookup rr.worker.internal
Server: 127.0.0.11
Address: 127.0.0.11#53
Name: rr.worker.internal
Address: 10.210.0.3
Name: rr.worker.internal
Address: 10.210.0.4
Name: rr.worker.internal
Address: 10.210.1.3
Name: rr.worker.internal
Address: 10.210.1.4
$ nslookup rr.worker.internal
Server: 127.0.0.11
Address: 127.0.0.11#53
Name: rr.worker.internal
Address: 10.210.0.4
Name: rr.worker.internal
Address: 10.210.1.3
Name: rr.worker.internal
Address: 10.210.1.4
Name: rr.worker.internal
Address: 10.210.0.3
```
## Nearest scope
Returns machine-local instances first.
`machine-a`:
```
$ nslookup nearest.worker.internal
Server: 127.0.0.11
Address: 127.0.0.11#53
Name: nearest.worker.internal
Address: 10.210.0.3
Name: nearest.worker.internal
Address: 10.210.0.4
Name: nearest.worker.internal
Address: 10.210.1.3
Name: nearest.worker.internal
Address: 10.210.1.4
```
`machine-b`:
```
$ nslookup nearest.worker.internal
Server: 127.0.0.11
Address: 127.0.0.11#53
Name: nearest.worker.internal
Address: 10.210.1.3
Name: nearest.worker.internal
Address: 10.210.1.4
Name: nearest.worker.internal
Address: 10.210.0.3
Name: nearest.worker.internal
Address: 10.210.0.4
```
The prefixes can be used with service ID and machine-scoped service names, as well (e.g. `nearest.3ecb3a8bbec5fd3f46efb056a934714a.internal` or `rr.0903f0ee483aa97d559eeeaac5e22283.m.worker.internal`).