From 12d47b89683de7aa0228495702bab6410b0f649e Mon Sep 17 00:00:00 2001 From: Pete Birley Date: Thu, 19 Jul 2018 10:10:55 -0500 Subject: [PATCH] ceph-osd: Make hash calculcation deterministic Go returns the keys of a map in arbitrary order, so the name of DaemonSets which includes a hash over all matchExpressions could change when upgrading releases eventhough the node or label selector hasn't changed. Change-Id: I882c7b51d52ba4ace99b8a8830725ae38a1c3b94 Co-authored-by: Lars Fenneberg Signed-off-by: Pete Birley Story: 2002774 --- .../templates/utils/_osd_daemonset_overrides.tpl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ceph-osd/templates/utils/_osd_daemonset_overrides.tpl b/ceph-osd/templates/utils/_osd_daemonset_overrides.tpl index 550b6c25ce..eb9c709862 100644 --- a/ceph-osd/templates/utils/_osd_daemonset_overrides.tpl +++ b/ceph-osd/templates/utils/_osd_daemonset_overrides.tpl @@ -14,6 +14,17 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{- define "ceph.utils.match_exprs_hash" }} + {{- $match_exprs := index . 0 }} + {{- $context := index . 1 }} + {{- $_ := set $context.Values "__match_exprs_hash_content" "" }} + {{- range $match_expr := $match_exprs }} + {{- $_ := set $context.Values "__match_exprs_hash_content" (print $context.Values.__match_exprs_hash_content $match_expr.key $match_expr.operator ($match_expr.values | quote)) }} + {{- end }} + {{- $context.Values.__match_exprs_hash_content | sha256sum | trunc 8 }} + {{- $_ := unset $context.Values "__match_exprs_hash_content" }} +{{- end }} + {{- define "ceph.utils.osd_daemonset_overrides" }} {{- $daemonset := index . 0 }} {{- $daemonset_yaml := index . 1 }} @@ -207,7 +218,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 "-" (list $current_dict.matchExpressions $context | include "ceph.utils.match_exprs_hash"))) }} {{- else }} {{- $_ := set $current_dict "dns_1123_name" $name_format2 }} {{- end }}