From cc9cf540dbe4bf7efed6642c08fd3442247bd0a9 Mon Sep 17 00:00:00 2001
From: Ovidiu Poncea <ovidiu.poncea@windriver.com>
Date: Mon, 29 Jul 2019 09:14:18 -0400
Subject: [PATCH] Fix nova&neutron pod restarted on all workers when worker
 added

This is based on upstream(openstack-helm/openstack-helm-infra) review:
https://review.opendev.org/#/c/672966/

The only difference is that we do not carry over the Ceph changes
as we do not use Helm's Ceph in StarlingX.

Change-Id: Iabc3689bca198a861f2ade03a620895320897568
Closes-Bug: 1820902
Signed-off-by: Ovidiu Poncea <ovidiu.poncea@windriver.com>
---
 openstack-helm-infra/centos/build_srpm.data   |  2 +-
 .../centos/openstack-helm-infra.spec          |  2 +
 ...-on-all-workers-when-worker-added-re.patch | 46 +++++++++++++++++++
 3 files changed, 49 insertions(+), 1 deletion(-)
 create mode 100644 openstack-helm-infra/files/0007-Fix-pod-restarts-on-all-workers-when-worker-added-re.patch

diff --git a/openstack-helm-infra/centos/build_srpm.data b/openstack-helm-infra/centos/build_srpm.data
index d143a1cb..e811e2ee 100644
--- a/openstack-helm-infra/centos/build_srpm.data
+++ b/openstack-helm-infra/centos/build_srpm.data
@@ -5,4 +5,4 @@ TAR="$TAR_NAME-$SHA.tar.gz"
 
 COPY_LIST="${CGCS_BASE}/downloads/$TAR $PKG_BASE/files/*"
 
-TIS_PATCH_VER=12
+TIS_PATCH_VER=13
diff --git a/openstack-helm-infra/centos/openstack-helm-infra.spec b/openstack-helm-infra/centos/openstack-helm-infra.spec
index b1a41d66..112f80bd 100644
--- a/openstack-helm-infra/centos/openstack-helm-infra.spec
+++ b/openstack-helm-infra/centos/openstack-helm-infra.spec
@@ -21,6 +21,7 @@ Patch03: 0003-Set-Min-NGINX-handles.patch
 Patch04: 0004-Partial-revert-of-31e3469d28858d7b5eb6355e88b6f49fd6.patch
 Patch05: 0005-Add-a-configmap-for-ingress-controller-config.patch
 Patch06: 0006-Add-TLS-support-for-Gnocchi-public-endpoint.patch
+Patch07: 0007-Fix-pod-restarts-on-all-workers-when-worker-added-re.patch
 
 BuildRequires: helm
 
@@ -35,6 +36,7 @@ Openstack Helm Infra charts
 %patch04 -p1
 %patch05 -p1
 %patch06 -p1
+%patch07 -p1
 
 %build
 # initialize helm and build the toolkit
diff --git a/openstack-helm-infra/files/0007-Fix-pod-restarts-on-all-workers-when-worker-added-re.patch b/openstack-helm-infra/files/0007-Fix-pod-restarts-on-all-workers-when-worker-added-re.patch
new file mode 100644
index 00000000..b4097d65
--- /dev/null
+++ b/openstack-helm-infra/files/0007-Fix-pod-restarts-on-all-workers-when-worker-added-re.patch
@@ -0,0 +1,46 @@
+From 326fcd76f54d7c099f4c3da6c31eefe0eef2e236 Mon Sep 17 00:00:00 2001
+From: Ovidiu Poncea <ovidiu.poncea@windriver.com>
+Date: Mon, 29 Jul 2019 08:00:01 -0400
+Subject: [PATCH] Fix pod restarts on all workers when worker added/removed
+
+---
+ helm-toolkit/templates/utils/_daemonset_overrides.tpl | 4 ++--
+ helm-toolkit/templates/utils/_hash.tpl                | 2 +-
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/helm-toolkit/templates/utils/_daemonset_overrides.tpl b/helm-toolkit/templates/utils/_daemonset_overrides.tpl
+index ef52592..d7194af 100644
+--- a/helm-toolkit/templates/utils/_daemonset_overrides.tpl
++++ b/helm-toolkit/templates/utils/_daemonset_overrides.tpl
+@@ -213,7 +213,7 @@ limitations under the License.
+     name uniqueness */}}
+     {{- $_ := set $current_dict "dns_1123_name" dict }}
+     {{- if hasKey $current_dict "matchExpressions" }}
+-      {{- $_ := set $current_dict "dns_1123_name" (printf (print $name_format2 "-" ($current_dict.matchExpressions | quote | sha256sum | trunc 8))) }}
++      {{- $_ := set $current_dict "dns_1123_name" (printf (print $name_format2 "-" ($current_dict.matchExpressions | toJson | sha256sum | trunc 8))) }}
+     {{- else }}
+       {{- $_ := set $current_dict "dns_1123_name" $name_format2 }}
+     {{- end }}
+@@ -256,7 +256,7 @@ limitations under the License.
+     {{- if not $context.Values.__daemonset_yaml.spec.template.metadata }}{{- $_ := set $context.Values.__daemonset_yaml.spec.template "metadata" dict }}{{- end }}
+     {{- if not $context.Values.__daemonset_yaml.spec.template.metadata.annotations }}{{- $_ := set $context.Values.__daemonset_yaml.spec.template.metadata "annotations" dict }}{{- end }}
+     {{- $cmap := list $current_dict.dns_1123_name $current_dict.nodeData | include $configmap_include }}
+-    {{- $values_hash := $cmap | quote | sha256sum }}
++    {{- $values_hash := $cmap | toJson | sha256sum }}
+     {{- $_ := set $context.Values.__daemonset_yaml.spec.template.metadata.annotations "configmap-etc-hash" $values_hash }}
+ 
+     {{/* generate configmap */}}
+diff --git a/helm-toolkit/templates/utils/_hash.tpl b/helm-toolkit/templates/utils/_hash.tpl
+index 1041ec0..e419e3b 100644
+--- a/helm-toolkit/templates/utils/_hash.tpl
++++ b/helm-toolkit/templates/utils/_hash.tpl
+@@ -19,5 +19,5 @@ limitations under the License.
+ {{- $context := index . 1 -}}
+ {{- $last := base $context.Template.Name }}
+ {{- $wtf := $context.Template.Name | replace $last $name -}}
+-{{- include $wtf $context | sha256sum | quote -}}
++{{- include $wtf $context | toJson | sha256sum | quote -}}
+ {{- end -}}
+-- 
+1.8.3.1
+