fix: derive kubelet clusterDNS for a custom serviceSubnet (C2)#23
Merged
Conversation
…1, C2) When serviceSubnet is non-default, the kubelet clusterDNS must be the DNS service IP of that CIDR, not the default 10.96.0.10. The provider previously relied on kubeadm's implicit derivation; this makes it correct-by-construction and unit-testable (ADR-17). - DeriveDNSIP(serviceSubnet): pure function returning the 10th host IP of the service CIDR, matching kubeadm's GetDNSIP. Uses the primary (first) CIDR for a dual-stack value, big-endian byte addition so IPv4/IPv6 and non-zero-aligned bases are correct, and fails fast on empty/malformed/too-small/empty-secondary CIDRs rather than guessing. - KubeletConfiguration type + BuildKubeletConfiguration: emit clusterDNS only when the operator set a custom serviceSubnet; empty subnet emits no document so the default path is byte-for-byte unchanged (kubeadm derives it). - Emitted in the init flow and in the ADR-12-R1 kubelet-start repair (both regenerate /var/lib/kubelet/config.yaml); the join path omits it, as workers inherit clusterDNS from the kubelet-config ConfigMap uploaded at init. Tests: full DeriveDNSIP matrix (default/custom IPv4, IPv6, dual-stack primary, non-zero-aligned bases, /28 boundary, and error cases), a builder test, an action behavior test (init emits the derived clusterDNS for a custom subnet, omits it for the default), and a join-omits regression test. Credential-free; no security gate. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: William Rizzo <william.rizzo@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When
serviceSubnetis non-default, the kubeletclusterDNSmust be the DNSservice IP of that CIDR (the 10th host IP), not the default
10.96.0.10. Theprovider previously relied on kubeadm's implicit derivation; this makes the
provider own the value, correct-by-construction and hardware-free testable.
Closes kairos-io/kairos#4201 (pitfall C2).
How (ADR-17, option B)
DeriveDNSIP(serviceSubnet)(internal/kubeadmconfig/dns.go): pure functionreturning the 10th host IP of the service CIDR, matching kubeadm's
GetDNSIP.Uses the primary (first) CIDR for a dual-stack value; big-endian byte
addition so IPv4/IPv6 and non-zero-aligned bases are correct (e.g.
10.96.0.64/26 -> 10.96.0.74); fails fast on empty / malformed / too-small /empty-secondary CIDRs rather than guessing.
KubeletConfigurationtype +BuildKubeletConfiguration: emitsclusterDNSonly when the operator set a custom
serviceSubnet; an empty subnet emits nodocument, so the default path is byte-for-byte unchanged (kubeadm derives it).
regenerate
/var/lib/kubelet/config.yaml); the join path omits it, sinceworkers inherit
clusterDNSfrom the kubelet-config ConfigMap kubeadm uploads atinit.
Tests
DeriveDNSIPmatrix: default/custom IPv4, IPv6, dual-stack primary,non-zero-aligned bases,
/28boundary, and all error cases (empty, garbage,too-small
/29&/125, three CIDRs, empty primary/secondary).clusterDNS; empty -> none).clusterDNSfor a custom subnetand omits the document for the default; join never emits it.
go build/go test ./.../vet/golangci-lintall green. Credential-free,so no security-architect gate.
Review
staff-engineer code-reviewed this and ran a differential test reimplementing
kubeadm's
GetDNSIP/GetIndexedIPfromk8s.io/utils/netagainstDeriveDNSIPacross the matrix + 9 extra edge cases — byte-for-byte parity on value and error.
Both should-fix items (repair-path consistency; reject empty-secondary CIDR) were
actioned before this PR.