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 — testable ClusterConfig.DNSZone method with ≤2-label guard.
  • feat(infra): render coredns-custom rewrite for cluster hostnames — template + manifests.go wiring.
  • feat(infra): auto-inject coredns-custom rewrite for cluster hostnames — buildInfraParams wiring.

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-caproni kustomize workaround (hardcoded node IP 172.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

  1. Check out the branch and build: mise run build
  2. In a project using cluster.network.hostname:
    cluster:
      driver: k3d
      network:
        hostname: gitlab.caproni.test
    Run caproni up.
  3. Confirm the ConfigMap is created:
    kubectl -n kube-system get configmap coredns-custom -o yaml
    Expected: a caproni.server key with caproni.test:53 { rewrite name regex ... }.
  4. From a pod, verify resolution:
    kubectl run -it --rm dns-test --image=busybox --restart=Never -- \
      nslookup gitlab.caproni.test
    Expected: resolves to Traefik's ClusterIP (not NXDOMAIN).
  5. (optional) Add dns.extra_hosts:
    cluster:
      network:
        hostname: gitlab.caproni.test
        dns:
          extra_hosts:
            - hostname: registry.caproni.test
              ip: 10.43.0.20
    Run caproni up again and confirm an extra_hosts.server key appears in the ConfigMap with a dedicated registry.caproni.test:53 block.
Edited by Reuben Pereira

Merge request reports

Loading
Loading