jittering / traefik-kop

A dynamic docker->redis->traefik discovery agent
MIT License
179 stars 13 forks source link

Add support for `traefik.docker.network` #8

Closed hcooper closed 2 years ago

hcooper commented 2 years ago

Hi,

I hoping to use traefik-kop in a setup where each container has it's own routable IP address, taken from a specific network the host has been assigned for its containers, and unique from the IP or network the host itself is using.

Traefik itself previously had problems identifying the correct IP to use for these containers. However now the traefik.docker.network label tells traefik which docker network it should examine to find the correct IP address.

This PR attempts to add support for this flag to traefik-kop.

Example of it working....

~/traefik-kop$ go run ./bin/traefik-kop --verbose --redis-addr $redis_server:6379 --redis-pass $redis_pass
[...]
time="2022-03-14T21:53:49-07:00" level=debug msg="found network name routable_net for cloudflared"
[...]

// this is a "control" container, running without the `traefik.docker.network` flag, and reports the host's IP:
time="2022-03-14T21:53:49-07:00" level=debug msg="writing traefik/http/services/authelia/loadBalancer/servers/0/url = http://10.10.2.194:9091"

// this is the "test" container, running with the `traefik.docker.network` flag, and correctly reports the container's IP
time="2022-03-14T21:53:49-07:00" level=debug msg="writing traefik/http/services/cloudflared/loadBalancer/servers/0/url = http://10.254.254.253:49312"

[...]

I've dog-scienced this PR, as I'm unfamiliar with both the internals of traefik and writing golang. Therefore comments on code, structure, etc, all welcome!

Coops.

chetan commented 2 years ago

Finally got around to testing this change. Looks great. Thanks for the contribution!