From 44a0c200f250fc6f736fb9a61ecfebab9bc5a7fd Mon Sep 17 00:00:00 2001 From: Andrey Volkov Date: Mon, 24 Sep 2018 08:56:51 -0700 Subject: [PATCH] Make haproxy-anchor cleanup more cautious There was a bug related to missing haproxy config files: /etc/promenade/haproxy/haproxy.cfg /etc/kubernetes/manifests/haproxy.yaml Those files are initially generated with static pods and after that it periodically updated by haproxy-anchor. Most plausible reason why it could be missed is haproxy-anchor cleaned it up while terminating. To solve the issue there were restored manually. This patch tries to make such a situation clearer by two things: 1) it leaves a message in a cleanup file that haproxy-anchor was terminated and the cleaup happened. 2) instead of removing files it moves them to backup dir from that they could be restored easily. Change-Id: Ia1449d188c15b71dd756e96b1ea2d4a672011a17 --- charts/haproxy/templates/bin/_anchor.tpl | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/charts/haproxy/templates/bin/_anchor.tpl b/charts/haproxy/templates/bin/_anchor.tpl index 237adbc3..d84ca166 100644 --- a/charts/haproxy/templates/bin/_anchor.tpl +++ b/charts/haproxy/templates/bin/_anchor.tpl @@ -108,10 +108,17 @@ install_config() { } cleanup() { + cleanup_message_file=$(dirname "$HAPROXY_CONF")/cleanup + backup_dir=$(dirname "$HAPROXY_CONF")/backup + mkdir -p $backup_dir + echo "Starting haproxy-anchor cleanup, files are backed up:" > $cleanup_message_file {{- range .Values.conf.anchor.files_to_copy }} - rm -f /host{{ .dest }} + echo /host{{ .dest }} >> $cleanup_message_file + mv /host{{ .dest }} $backup_dir {{- end }} - rm -f "$HAPROXY_CONF" "$NEXT_HAPROXY_CONF" + echo "$HAPROXY_CONF" >> $cleanup_message_file + echo "$NEXT_HAPROXY_CONF" >> $cleanup_message_file + mv "$HAPROXY_CONF" "$NEXT_HAPROXY_CONF" $backup_dir } while true; do