fix(k3d): resolve cluster hostnames inside the cluster

What does this merge request do and why?

Makes cluster.network.hostname and additional_hostnames resolve inside a k3d cluster, not just on the host.

On Linux the k3d driver only wrote the hostnames to the host's /etc/hosts, so pods (and mirrord sessions, which resolve DNS in-cluster) got NXDOMAIN for gitlab.caproni.test. With the ai-gateway fragment that meant the AI Gateway pod couldn't fetch JWKS from GitLab, and the edit-mode Duo Workflow Service timed out waiting for GitLab. macOS/Colima was never affected because the VM's resolver forwards to the host.

The driver now writes a coredns-custom ConfigMap manifest (a CoreDNS rewrite from each hostname to the k3s Traefik service) into the profile's data directory and bind-mounts it into k3s's manifests directory at cluster create, the same way registries.yaml is handled. k3s applies it before CoreDNS starts and re-applies it whenever the file changes, so hostname edits reach a running cluster on the next caproni up. Skipped when cluster.k3d.k3s.disable includes traefik.

Two things worth knowing:

  • caproni now owns coredns-custom on k3d (k3s CoreDNS only reads that one name). Rigs that added their own copy as a workaround should drop it.
  • Clusters created before this change don't have the bind mount and need one caproni destroy && caproni up.

References

Closes #299 (closed)

How to set up and validate locally

  1. On Linux with the k3d driver, use a rig with cluster.network.hostname set (e.g. gitlab-org/gitlab-caproni with fragments/caproni.ai-gateway.yaml enabled).
  2. caproni destroy && caproni up with this branch's binary.
  3. caproni kubectl get cm -n kube-system coredns-custom -o yaml shows a rewrite stop block for each configured hostname.
  4. caproni kubectl run dns-check --rm -i --restart=Never --image=busybox:1.36 -- nslookup <hostname> answers with the traefik ClusterIP (caproni kubectl get svc -n kube-system traefik).
  5. Once GitLab is up, caproni kubectl run curl -n ai-gateway --rm -i --restart=Never --image=curlimages/curl -- curl -s -o /dev/null -w '%{http_code}' http://<hostname>/oauth/discovery/keys returns 200, and caproni kubectl logs -n ai-gateway deploy/ai-gateway has no NameResolutionError.
  6. Add an entry to cluster.network.additional_hostnames, caproni up again (no recreate), and repeat step 4 for the new name.

Merge request reports

Loading
Loading