Roll pods on config change via a pod-template config hash #10
Reference in New Issue
Block a user
Delete Branch "benvin/config-hash-rollout"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Why
Config changes never reached running pods, which caused the resolver
validate-exceptfix (and earlier the primary-ClusterIP change) to require manual pod deletes. Two compounding causes:cp … /run/named/named.conf). The live ConfigMap updates at/etc/bind-operator, but the filenamedreads is never re-synced, andrndc reconfigre-reads that stale startup copy — soreloadReadyPodsis a no-op for config changes.kubectl rollout restartis reverted:reconcileStatefulSetoverwrites the whole pod template each reconcile (existing.Spec.Template = sts.Spec.Template), stripping therestartedAtannotation before the roll completes. (This is exactly why "only one resolver restarted".)So the only thing that applies new config is a restart, and nothing triggered one reliably.
Fix
Stamp a hash of the projected config (the rendered ConfigMap + the
keys.confSecret) onto the pod template asbind.unkin.net/config-hash. When the config changes, the hash flips → the template changes → the StatefulSet performs a normal rolling restart, so every pod re-copies fresh config on startup. Because the operator owns the template, the restart is operator-driven and never reverted; a stable hash means no spurious restarts.Covers all
named.confchanges (ACLs, views, forwarders,validate-except, primary address) and TSIG key rotation (keys.conf).Notes
Tests
TestConfigHashStableAndSensitive: hash is stable when nothing changes and flips on both a ConfigMap change and akeys.confchange.go build/vet/testclean.