plugin/kubernetes: Add support for topology-aware headless services via "az-pinned" subdomains (#8388)

This commit is contained in:
rpb-ant
2026-08-10 16:24:50 -04:00
committed by GitHub
parent b2ef1a13e8
commit c2ca1b2c23
10 changed files with 624 additions and 39 deletions

View File

@@ -13,28 +13,38 @@ func TestParseRequest(t *testing.T) {
query string
expected string // output from r.String()
multicluster bool
zonal bool
zone string // expected r.zone
}{
// valid SRV request
{"_http._tcp.webs.mynamespace.svc.inter.webs.tests.", "http.tcp...webs.mynamespace.svc", false},
{"_http._tcp.webs.mynamespace.svc.inter.webs.tests.", "http.tcp...webs.mynamespace.svc", false, false, ""},
// A request of endpoint
{"1-2-3-4.webs.mynamespace.svc.inter.webs.tests.", "..1-2-3-4..webs.mynamespace.svc", false},
{"1-2-3-4.webs.mynamespace.svc.inter.webs.tests.", "..1-2-3-4..webs.mynamespace.svc", false, false, ""},
// bare zone
{"inter.webs.tests.", "......", false},
{"inter.webs.tests.", "......", false, false, ""},
// bare svc type
{"svc.inter.webs.tests.", "......", false},
{"svc.inter.webs.tests.", "......", false, false, ""},
// bare pod type
{"pod.inter.webs.tests.", "......", false},
{"pod.inter.webs.tests.", "......", false, false, ""},
// SRV request with empty segments
{"..webs.mynamespace.svc.inter.webs.tests.", "....webs.mynamespace.svc", false},
{"..webs.mynamespace.svc.inter.webs.tests.", "....webs.mynamespace.svc", false, false, ""},
// A multicluster request with a clusterid
{"1-2-3-4.cluster1.webs.mynamespace.svc.inter.webs.tests.", "..1-2-3-4.cluster1.webs.mynamespace.svc", true},
{"1-2-3-4.cluster1.webs.mynamespace.svc.inter.webs.tests.", "..1-2-3-4.cluster1.webs.mynamespace.svc", true, false, ""},
// zone-scoped names, both directives
{"us-west-2a.pin._zone.webs.mynamespace.svc.inter.webs.tests.", "....webs.mynamespace.svc", false, true, "us-west-2a"},
{"us-west-2a.prefer._zone.webs.mynamespace.svc.inter.webs.tests.", "....webs.mynamespace.svc", false, true, "us-west-2a"},
// zone label values may contain dots; the value spans every label
// left of the directive
{"corp.example.com.pin._zone.webs.mynamespace.svc.inter.webs.tests.", "....webs.mynamespace.svc", false, true, "corp.example.com"},
// two-labels-left with an underscore still reads as port/protocol
{"us-west-2a._zone.webs.mynamespace.svc.inter.webs.tests.", "us-west-2a.zone...webs.mynamespace.svc", false, true, ""},
}
for i, tc := range tests {
m := new(dns.Msg)
m.SetQuestion(tc.query, dns.TypeA)
state := request.Request{Zone: zone, Req: m}
r, e := parseRequest(state.Name(), state.Zone, tc.multicluster)
r, e := parseRequest(state.Name(), state.Zone, tc.multicluster, tc.zonal)
if e != nil {
t.Errorf("Test %d, expected no error, got '%v'.", i, e)
}
@@ -42,13 +52,36 @@ func TestParseRequest(t *testing.T) {
if rs != tc.expected {
t.Errorf("Test %d, expected (stringified) recordRequest: %s, got %s", i, tc.expected, rs)
}
if r.zone != tc.zone {
t.Errorf("Test %d, expected zone %q, got %q", i, tc.zone, r.zone)
}
}
}
func TestParseInvalidRequest(t *testing.T) {
invalid := []string{
"webs.mynamespace.pood.inter.webs.test.", // Request must be for pod or svc subdomain.
"too.long.for.what.I.am.trying.to.pod.inter.webs.tests.", // Too long.
"webs.mynamespace.pood.inter.webs.test.", // Request must be for pod or svc subdomain.
"too.long.for.what.I.am.trying.to.pod.inter.webs.tests.", // Too long.
"us-west-2a.pin._zone.webs.mynamespace.svc.inter.webs.tests.", // Zonal shape without the zonal option.
}
// The zonal-shaped rejections that must hold even WITH the option on:
// wrong subtree, unknown directive, and multicluster zones.
zonalInvalid := []struct {
query string
multicluster bool
}{
{"us-west-2a.pin._zone.webs.mynamespace.pod.inter.webs.tests.", false},
{"us-west-2a.florp._zone.webs.mynamespace.svc.inter.webs.tests.", false},
{"us-west-2a.pin._zone.webs.mynamespace.svc.inter.webs.tests.", true},
}
for i, tc := range zonalInvalid {
m := new(dns.Msg)
m.SetQuestion(tc.query, dns.TypeA)
state := request.Request{Zone: zone, Req: m}
if _, e := parseRequest(state.Name(), state.Zone, tc.multicluster, true); e == nil {
t.Errorf("Zonal-invalid test %d: expected error from %s, got none", i, tc.query)
}
}
for i, query := range invalid {
@@ -56,7 +89,7 @@ func TestParseInvalidRequest(t *testing.T) {
m.SetQuestion(query, dns.TypeA)
state := request.Request{Zone: zone, Req: m}
if _, e := parseRequest(state.Name(), state.Zone, false); e == nil {
if _, e := parseRequest(state.Name(), state.Zone, false, false); e == nil {
t.Errorf("Test %d: expected error from %s, got none", i, query)
}
}
@@ -67,6 +100,6 @@ const zone = "inter.webs.tests."
func BenchmarkParseRequest(b *testing.B) {
b.ReportAllocs()
for b.Loop() {
_, _ = parseRequest("1-2-3-4.webs.mynamespace.svc.inter.webs.tests.", zone, false)
_, _ = parseRequest("1-2-3-4.webs.mynamespace.svc.inter.webs.tests.", zone, false, false)
}
}