0

How can I test the validity of a haproxy config file without trying to resolve all addresses?

I'm running a haproxy in Kubernetes, getting its config file (haproxy.cfg) from a ConfigMap. When updating the ConfigMap with a new configuration, I'm testing the validity of the configuration before updating the config map.

I do the validation from the CI/CD environment, and here the DNS entries from the Kubernetes cluster will not resolve. So basically I will only learn if the configuration is syntaxial correct or not, but that is still an important check.

My problem is that instead on seconds, the validation of the haproxy configuration takes well over half an hour, because I have to wait for it to fail all the 120 backends (micro service) that are configured for our api-gateway... 120 error messages of type:

server service-a/k8s_service' : could not resolve address 'service-a.svc.cluster.local', disabling server.

I use a command like this (from the folder where my haproxy.cfg file resides):

docker run --rm -v $(pwd):/etc/haproxy/ haproxy:2.6-alpine haproxy -c -dr -f /etc/haproxy/haproxy.cfg

Triva

My full script to apply an update the haproxy config looks basically like this, although maybe not relevant for the actual question:

docker run --rm -v $(pwd):/etc/haproxy/ haproxy:2.6-alpine haproxy -c -dr -f /etc/haproxy/haproxy.cfg
if [ $? -ne 0 ]; then
  echo "Invalid haproxy configuration in $(pwd)/haproxy.cfg"
  exit 1
fi

kubectl create configmap api-gateway-config --from-file=haproxy.cfg -o yaml --dry-run=client | kubectl apply -f -
kubectl rollout restart deployment api-gateway

The Kubernetes deployment will define and mount a volume with the ConfigMap into the folder /etc/haproxy of the running container.

Andreas L
  • 81
  • 1
  • 7

1 Answers1

0

I have a line like this in my "default" section in the config file:

default-server init-addr last,libc,none

The none at the end is extra, compared to the default settings. It allows haproxy to start if no IP address is found for a server. Useful in case a machine is missing and the config hasn't been updated yet. It is also needed for github action's haproxy config check: our internal DNS names aren't known to github.

The same probably applies to your case.

Reinout van Rees
  • 13,486
  • 2
  • 36
  • 68