fix: drop k3s-traefik priority, wrap caddy web reverse_proxy in handle

The k3s-traefik IngressRoute was emitting priority: len(path) on the route rule but no priority on the bare-Host catch-all. Traefik defaults missing priority to rule length, so the catch-all rule got ~32 while the path rule got 7, and the catch-all always won. Same exact priority bug we fixed for docker-traefik. Dropping the priority line lets traefik use its rule-length default which gives longest-prefix-wins naturally because Host && PathPrefix is always longer than bare Host. The caddy web container's emission was a bare reverse_proxy directive that runs at caddy default order ~190, well before the handle directive at ~210 where my route emission lives. The bare reverse_proxy caught every request including paths intended for the route. When at least one route exists for the app, the web container now wraps its reverse_proxy in a catch-all handle block via caddy.9_handle.0_reverse_proxy=...; both the route's handle (at 0_) and web's catch-all (at 9_) live at the same directive order ~210 and caddy's mutually-exclusive handle logic picks the route handle for matched paths and the catch-all for everything else. The "9_" prefix orders web's catch-all after the route handles in the docker-proxy generated Caddyfile. Apps without routes keep the original bare reverse_proxy behaviour.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-11-04 14:56:38 -05:00
1 parent 3449c11a59
commit 123fdc700c
3 files changed
+31 -11

No files matched your search

-8
View File
@@ -45,14 +45,6 @@ teardown() {
# Give the daemon a moment to read the new labels.
sleep 5
# Surface the generated Caddyfile so we can see how caddy-docker-proxy
# merged the web + api containers' labels and figure out why /api/v0/*
# routing isn't taking effect.
run /bin/bash -c "docker exec caddy-caddy-1 cat /etc/caddy/Caddyfile 2>&1"
echo "caddy config: $output"
run /bin/bash -c "docker exec caddy-caddy-1 caddy adapt --config /etc/caddy/Caddyfile 2>&1 | head -200"
echo "caddy adapt json: $output"
# Without --strip-prefix, /api/v0/Procfile reaches api as /api/v0/Procfile
# which python's http.server returns 404 for. A 404 here proves the route
# reaches api - web's catch-all would have returned 200.