feat(infra): auto-inject cluster-internal CoreDNS for configured hostnames
What does this merge request do and why?
On k3s drivers (k3d + colima), Caproni now automatically injects a
coredns-custom ConfigMap that makes configured cluster hostnames resolvable
inside the cluster. Without this, pods — and local processes whose
outgoing traffic is routed through the cluster by mirrord — receive NXDOMAIN
for caproni hostnames (*.caproni.test), causing 502 errors on every upstream
call. Every mirrord-based Caproni project hits this wall; the fix belongs in
Caproni rather than in per-project kustomize workarounds.
How it works
The feature derives the DNS zone from cluster.network.hostname (parent
domain, e.g. caproni.test from gitlab.caproni.test) and renders one
additional manifest in WriteManifests: a coredns-custom ConfigMap in
kube-system (the name is mandated by k3s). The ConfigMap carries a
caproni.server key with a <zone>:53 CoreDNS block that rewrites
*.<zone> to traefik.kube-system.svc.cluster.local (answer auto),
resolved via the kubernetes plugin to Traefik's ClusterIP. No hardcoded
node IP, no runtime lookup — it survives cluster recreation.
k3s auto-applies manifests delivered into the node's auto-deploy directory
(the existing K3sInstaller/WriteManifests path), so no change to
Installer was required.
Commits (droppable structure)
Commits 1–3 (bare auto-inject) are self-contained and mergeable alone:
feat(config): derive cluster DNS zone from network hostname— testableClusterConfig.DNSZonemethod with ≤2-label guard.feat(infra): render coredns-custom rewrite for cluster hostnames— template +manifests.gowiring.feat(infra): auto-inject coredns-custom rewrite for cluster hostnames—buildInfraParamswiring.
Commits 4–6 + validation add the optional cluster.network.dns.extra_hosts
surface (user-declared A-records for names not covered by the wildcard
rewrite). Each extra host gets its own dedicated per-FQDN server block
(registry.caproni.test:53 { hosts { 10.0.0.5 ... } }) so the more-specific
zone wins over the wildcard without any duplicate-zone conflict. A semantic
validator (validateExtraHosts) rejects duplicate hostnames and hostnames
equal to the zone. These 4 commits can be dropped to leave a minimal MR.
References
-
Caproni config reference:
docs/config/_index.md(new "Cluster-internal DNS" subsection) -
Motivated by Membrane's
coredns-capronikustomize workaround (hardcoded node IP172.19.0.2) which can be seen at gitlab-org/cells/membrane!23 (closed); this MR makes that workaround unnecessary for any k3s-driver project.
How to set up and validate locally
- Check out the branch and build:
mise run build - In a project using
cluster.network.hostname:Runcluster: driver: k3d network: hostname: gitlab.caproni.testcaproni up. - Confirm the ConfigMap is created:
Expected: a
kubectl -n kube-system get configmap coredns-custom -o yamlcaproni.serverkey withcaproni.test:53 { rewrite name regex ... }. - From a pod, verify resolution:
Expected: resolves to Traefik's ClusterIP (not NXDOMAIN).
kubectl run -it --rm dns-test --image=busybox --restart=Never -- \ nslookup gitlab.caproni.test - (optional) Add
dns.extra_hosts:Runcluster: network: hostname: gitlab.caproni.test dns: extra_hosts: - hostname: registry.caproni.test ip: 10.43.0.20caproni upagain and confirm anextra_hosts.serverkey appears in the ConfigMap with a dedicatedregistry.caproni.test:53block.