fix: add DNS resolution fallback in CheckProtocol() and export resolved env vars in start-db.sh - #7342
fix: add DNS resolution fallback in CheckProtocol() and export resolved env vars in start-db.sh#7342cleman95 wants to merge 2 commits into
Conversation
8e24c48 to
8695344
Compare
zhangzujian
left a comment
There was a problem hiding this comment.
Request changes. Issue #7341 is valid: HCP ovn-central intentionally supplies a headless-Service hostname as POD_IP, while the leader checker needs the address family. The two DNS-related changes are directionally relevant, but the current implementation introduces a broad validator regression and lacks deterministic hostname coverage. The capability change is unrelated to this issue and should not be bundled without covering both chart variants.
| if ip == nil { | ||
| klog.Errorf("failed to parse address %q", address) | ||
| return "" | ||
| addrs, err := net.LookupIP(address) |
There was a problem hiding this comment.
[P1] Please keep the generic CheckProtocol validator literal-only, or move hostname resolution behind an explicit resolver used by the HCP leader-checker path. CheckProtocol is called throughout IP/CIDR validation, so this fallback makes arbitrary invalid strings trigger blocking ambient DNS lookups and changes them into valid protocols when they happen to resolve. In the PR worktree, go test ./pkg/util already fails because the existing invalid-input cases not-an-ip and 1.2.3 resolve to IPv4. Please add controlled regression tests for hostname success/failure without making all validation dependent on cluster DNS.
There was a problem hiding this comment.
Done. CheckProtocol is back to literal-only, and hostname resolution now lives in an explicit resolver:
util.resolveProtocol(ctx, lookup, address)injectable lookup function so regression tests are deterministic and independent of cluster DNSutil.ResolveProtocolexported wrapper overnet.DefaultResolver
The leader checker is the only caller. Regression tests added in TestResolveProtocol cover hostname success/failure; TestCheckProtocol keeps its invalid-input cases (not-an-ip, 1.2.3) as literal-only.
| klog.Errorf("failed to parse or resolve address %q: %v", address, err) | ||
| return "" | ||
| } | ||
| ip = addrs[0] |
There was a problem hiding this comment.
[P1] addrs[0] is not a deterministic protocol choice for a hostname with both A and AAAA records. Resolver ordering can vary, so the same HCP pod may be classified as IPv4 or IPv6 across environments. Please define the dual-stack behavior explicitly (or use an address-family-aware lookup) and add a regression test covering a hostname that returns both families.
There was a problem hiding this comment.
Done. Dual-stack behavior is now defined explicitly: when a hostname resolves to both A and AAAA records, IPv4 is preferred. The choice must be deterministic because resolver ordering is not, and callers (EndpointSlice address type) only distinguish IPv4 from IPv6. Both orderings (v6-first and v4-first resolver output) are asserted in TestResolveProtocol/hostnameResolvesBothFamilies*.
| {{- if .Values.central.hcp.enabled }} | ||
| add: | ||
| - CHOWN | ||
| - DAC_OVERRIDE |
There was a problem hiding this comment.
[P2] This capability change is unrelated to #7341's DNS/leader-checker fix and changes the HCP container privilege model. It also updates only kube-ovn-v2; the equivalent v1 HCP template still runs the same chown -R with only CHOWN while dropping all other capabilities. Please split this into a separate PR, or update both supported charts with focused rendering tests and explain why it belongs here.
There was a problem hiding this comment.
Agreed this change was unrelated to #7341 and only touched one chart. It is removed from this PR and will be submitted separately, covering both charts (kube-ovn and kube-ovn-v2)
…lver In HCP mode ovn-central intentionally supplies a headless-Service hostname (e.g. ovn-central-0.ovn-central.kube-system.svc) as POD_IP, while the leader checker needs the address family to pick the EndpointSlice address type. Keep the generic CheckProtocol validator literal-only: it is called throughout IP/CIDR validation and a DNS fallback there would make arbitrary invalid strings trigger blocking cluster DNS lookups and turn them into valid protocols when they happen to resolve. Instead, add an explicit resolver: - util.resolveProtocol classifies a literal IP or hostname into ProtocolIPv4/ProtocolIPv6, with an injectable lookup function so regression tests are deterministic and independent of cluster DNS. - util.ResolveProtocol is the exported wrapper over net.DefaultResolver. Dual-stack behavior is defined explicitly: when a hostname resolves to both address families, IPv4 is preferred. The choice must be deterministic because resolver ordering is not, and callers only distinguish IPv4 from IPv6. The leader checker uses ResolveProtocol for POD_IP and falls back to IPv4 with a warning when resolution fails, preserving its previous defaulting behavior. POD_IPS (real pod IPs from the downward API) is unaffected. Fixes kubeovn#7341 Signed-off-by: Clement Phu <[email protected]>
normalize_raft_addrs resolves the HCP raft addresses from hostnames to IPs in the shell, but the resolved values were only visible to child processes spawned by start-db.sh. Export POD_IP, NODE_IPS and DB_CLUSTER_ADDR after normalization so every consumer gets the resolved values. Signed-off-by: Clement Phu <[email protected]>
533e532 to
9ceee60
Compare
|
The capabilities change is now in a standalone PR covering both charts: #7386. |
Description
In HCP mode, ovn-central intentionally supplies a headless-Service hostname as
POD_IP(e.g.ovn-central-0.ovn-central.kube-system.svc), while the leader checker needs the address family to pick the EndpointSlice address type (#7341).Per review feedback, this PR keeps the generic
CheckProtocolvalidator literal-only and introduces an explicit, testable resolver used only by the HCP leader-checker path:util.resolveProtocol(injectable lookup) +util.ResolveProtocol(wrapper overnet.DefaultResolver) inpkg/util/net.goCheckProtocolis unchanged: no ambient DNS lookups from IP/CIDR validation pathsstart-db.sh: export the shell-resolvedPOD_IP/NODE_IPS/DB_CLUSTER_ADDRafternormalize_raft_addrsChanges
pkg/util/net.go: addresolveProtocol(injectable lookup) +ResolveProtocol;CheckProtocoluntouchedpkg/ovn_leader_checker/ovn.go: classifyPOD_IPviaResolveProtocol, warn + default to IPv4 on failurepkg/util/net_test.go:TestResolveProtocolwith fake lookup covering literal v4/v6, hostname→v4/v6, hostname→both families (asserts IPv4 determinism), lookup failure, empty result, empty inputdist/images/start-db.sh: export resolved env valuesReview notes
Test Plan
go test ./pkg/util/ -run "TestCheckProtocol|TestResolveProtocol" -v— all pass, including the previously failing invalid-input cases (not-an-ip,1.2.3)go test ./pkg/ovn_leader_checker/— all passFixes #7341