From 3b7797b1a1d478493fc9b1510499fe371ddd7e2c Mon Sep 17 00:00:00 2001 From: Matthew Mosesohn Date: Mon, 10 Jun 2019 15:59:08 +0300 Subject: [PATCH] Ensure haproxy and nginx reload when config changes (#4862) Change-Id: Ia9a41e7b1cfcb1e6acb2dbae6eecc541dce25a74 --- .../node/tasks/loadbalancer/haproxy.yml | 15 ++++++++++----- .../node/tasks/loadbalancer/nginx-proxy.yml | 15 ++++++++++----- .../node/templates/manifests/haproxy.manifest.j2 | 2 ++ .../templates/manifests/nginx-proxy.manifest.j2 | 2 ++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/roles/kubernetes/node/tasks/loadbalancer/haproxy.yml b/roles/kubernetes/node/tasks/loadbalancer/haproxy.yml index e7cb579a6..fcbf6b5f2 100644 --- a/roles/kubernetes/node/tasks/loadbalancer/haproxy.yml +++ b/roles/kubernetes/node/tasks/loadbalancer/haproxy.yml @@ -4,11 +4,6 @@ path: "{{ kube_manifest_dir }}/nginx-proxy.yml" state: absent -- name: haproxy | Write static pod - template: - src: manifests/haproxy.manifest.j2 - dest: "{{ kube_manifest_dir }}/haproxy.yml" - - name: haproxy | Make haproxy directory file: path: "{{ haproxy_config_dir }}" @@ -23,3 +18,13 @@ owner: root mode: 0755 backup: yes + +- name: haproxy | Get checksum from config + stat: + path: "{{ haproxy_config_dir }}/haproxy.cfg" + register: haproxy_stat + +- name: haproxy | Write static pod + template: + src: manifests/haproxy.manifest.j2 + dest: "{{ kube_manifest_dir }}/haproxy.yml" diff --git a/roles/kubernetes/node/tasks/loadbalancer/nginx-proxy.yml b/roles/kubernetes/node/tasks/loadbalancer/nginx-proxy.yml index e19101379..91908791b 100644 --- a/roles/kubernetes/node/tasks/loadbalancer/nginx-proxy.yml +++ b/roles/kubernetes/node/tasks/loadbalancer/nginx-proxy.yml @@ -4,11 +4,6 @@ path: "{{ kube_manifest_dir }}/haproxy.yml" state: absent -- name: nginx-proxy | Write static pod - template: - src: manifests/nginx-proxy.manifest.j2 - dest: "{{ kube_manifest_dir }}/nginx-proxy.yml" - - name: nginx-proxy | Make nginx directory file: path: "{{ nginx_config_dir }}" @@ -23,3 +18,13 @@ owner: root mode: 0755 backup: yes + +- name: nginx-proxy | Get checksum from config + stat: + path: "{{ nginx_config_dir }}/nginx.conf" + register: nginx_stat + +- name: nginx-proxy | Write static pod + template: + src: manifests/nginx-proxy.manifest.j2 + dest: "{{ kube_manifest_dir }}/nginx-proxy.yml" diff --git a/roles/kubernetes/node/templates/manifests/haproxy.manifest.j2 b/roles/kubernetes/node/templates/manifests/haproxy.manifest.j2 index 8a53007bc..6b46f5b48 100644 --- a/roles/kubernetes/node/templates/manifests/haproxy.manifest.j2 +++ b/roles/kubernetes/node/templates/manifests/haproxy.manifest.j2 @@ -6,6 +6,8 @@ metadata: labels: addonmanager.kubernetes.io/mode: Reconcile k8s-app: kube-haproxy + annotations: + haproxy-cfg-checksum: "{{ haproxy_stat.stat.checksum }}" spec: hostNetwork: true dnsPolicy: ClusterFirstWithHostNet diff --git a/roles/kubernetes/node/templates/manifests/nginx-proxy.manifest.j2 b/roles/kubernetes/node/templates/manifests/nginx-proxy.manifest.j2 index d8b5eb1fa..beb3e9660 100644 --- a/roles/kubernetes/node/templates/manifests/nginx-proxy.manifest.j2 +++ b/roles/kubernetes/node/templates/manifests/nginx-proxy.manifest.j2 @@ -6,6 +6,8 @@ metadata: labels: addonmanager.kubernetes.io/mode: Reconcile k8s-app: kube-nginx + annotations: + nginx-cfg-checksum: "{{ nginx_stat.stat.checksum }}" spec: hostNetwork: true dnsPolicy: ClusterFirstWithHostNet