HAProxy community

Updating server address through admin API when current address is empty

Hi community,

I’m facing an issue where HAProxy refuses to update backend servers target address when their current address is empty.

The target address is empty in my case because in some situations the backend services may not be deployed and therefore not resolvable as they haven’t been registered in consul.

My resolvers config is as follow:

defaults
[…]
default-server init-addr last,libc,none

resolvers dns
# Uses default resolution
parse-resolv-conf
resolve_retries 3
[…]

and backend are defined using server-template:

listen listen-name
bind “${LISTEN_BIND}”

server-template my-server- 1-6 “${BACKEND_ENDPOINT}” check resolvers dns resolve-prefer ipv4

When BACKEND_ENDPOINT resolves, I get up to 6 servers configured that I can update, but when it doesn’t resolve at start, all servers are set with empty address and I am unable to update their address through the API, getting the following message:

Update for the current server address family is only supported through configuration file

I see in server.c:3801 it is checked if the current address is AF_INET or AF_INET6 but in this situations that condition doesn’t match as current address is empty. However, wouldn’t it be possible to set it also if current_addr is empty?
E.g.:

if ((sizeof(current_addr) != 0) && (ret != AF_INET) && (ret != AF_INET6)) {

Hi,
you should use init-addr on your server line.
https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#init-addr

Thanks for your reply @jerome
Setting the init-addr to a dummy IP instead of none as the last option did help running the set server */* addr * command.
However, the new IP is not taking effect and the old one keeps being the one configured. Is HAProxy overwrtting it as it will be checking the DNS entries configured for the server? Is there a way to update that DNS entry from the API? (This message suggests that: [WARNING] 329/102409 (6) : backend/server-3 changed its IP from 10.5.0.31 to 10.5.128.89 by DNS cache.)
I tried switching from server-template to individual server lines but the behavior is the same.

You can’t use both DNS resolver and API, or resolver will always erase changes provided by the API.
Simply remove resolvers then and use API only.

Or use resolvers and update your DNS server updated to what you need.