Skip to content

Commit

Permalink
[CN-1328] Fix ${serviceName} property which references to empty string (
Browse files Browse the repository at this point in the history
#437)

Fixes #436

Create a new map for the Hazelcast configuration to ensure that
conflicting Kubernetes discovery configuration fields are removed while
preserving the value of `serviceName`.
  • Loading branch information
semihbkgr authored Nov 13, 2024
1 parent ecd1c4f commit e1b0125
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 26 deletions.
21 changes: 10 additions & 11 deletions stable/hazelcast-enterprise/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,18 @@ Create the name of the service to use
{{- end -}}

{{/*
Create the config of the service-name to use
Generate the Hazelcast configuration, ensuring that any conflicting discovery configurations are resolved.
Remove the default value for the 'service-name' field when other discovery mechanisms are explicitly used.
*/}}
{{- define "hazelcast.serviceNameConfig" -}}
{{- if and ((((((.Values.hazelcast).yaml).hazelcast).network).join).kubernetes)
(or
(index .Values.hazelcast.yaml.hazelcast.network.join.kubernetes "service-dns")
(index .Values.hazelcast.yaml.hazelcast.network.join.kubernetes "service-label-name")
(index .Values.hazelcast.yaml.hazelcast.network.join.kubernetes "pod-label-name")
) -}}
{{ default "" }}
{{- else -}}
{{ template "hazelcast.serviceName" .}}
{{- define "hazelcast.config" -}}
{{- $config := .Values.hazelcast.yaml | deepCopy -}}
{{- $k8sJoin := $config.hazelcast.network.join.kubernetes -}}
{{- if and $k8sJoin -}}
{{- if or (index $k8sJoin "service-dns") (index $k8sJoin "service-label-name") (index $k8sJoin "pod-label-name") -}}
{{- $_ := unset $k8sJoin "service-name" -}}
{{- end -}}
{{- end -}}
{{- toYaml $config -}}
{{- end -}}

{{/*
Expand Down
2 changes: 1 addition & 1 deletion stable/hazelcast-enterprise/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ data:
{{ $val | indent 4}}
{{- end }}
hazelcast.yaml: |-
{{ toYaml .Values.hazelcast.yaml | indent 4 }}
{{ include "hazelcast.config" . | indent 4 }}
{{- end -}}
2 changes: 1 addition & 1 deletion stable/hazelcast-enterprise/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
- name: JAVA_OPTS
value: "-Dhazelcast.config=/data/hazelcast/hazelcast.yaml -DserviceName={{ template "hazelcast.serviceNameConfig" . }} -Dnamespace={{ .Release.Namespace }} -Dhazelcast.persistence={{ .Values.persistence.enabled }} {{ if .Values.persistence.enabled }}-Dhazelcast.stale.join.prevention.duration.seconds=5{{ end }} -Dhz.jet.enabled={{ .Values.jet.enabled }} {{ if .Values.gracefulShutdown.enabled }}-Dhazelcast.shutdownhook.policy=GRACEFUL -Dhazelcast.shutdownhook.enabled=true -Dhazelcast.graceful.shutdown.max.wait={{ .Values.gracefulShutdown.maxWaitSeconds }} {{ end }} -Dhazelcast.cluster.version.auto.upgrade.enabled={{ .Values.hazelcast.updateClusterVersionAfterRollingUpgrade }} {{ if .Values.metrics.enabled }}-Dhazelcast.jmx=true{{ end }} {{ .Values.hazelcast.javaOpts }}"
value: "-Dhazelcast.config=/data/hazelcast/hazelcast.yaml -DserviceName={{ template "hazelcast.serviceName" . }} -Dnamespace={{ .Release.Namespace }} -Dhazelcast.persistence={{ .Values.persistence.enabled }} {{ if .Values.persistence.enabled }}-Dhazelcast.stale.join.prevention.duration.seconds=5{{ end }} -Dhz.jet.enabled={{ .Values.jet.enabled }} {{ if .Values.gracefulShutdown.enabled }}-Dhazelcast.shutdownhook.policy=GRACEFUL -Dhazelcast.shutdownhook.enabled=true -Dhazelcast.graceful.shutdown.max.wait={{ .Values.gracefulShutdown.maxWaitSeconds }} {{ end }} -Dhazelcast.cluster.version.auto.upgrade.enabled={{ .Values.hazelcast.updateClusterVersionAfterRollingUpgrade }} {{ if .Values.metrics.enabled }}-Dhazelcast.jmx=true{{ end }} {{ .Values.hazelcast.javaOpts }}"
{{- if .Values.hazelcast.loggingLevel }}
- name: LOGGING_LEVEL
value: {{ .Values.hazelcast.loggingLevel }}
Expand Down
21 changes: 10 additions & 11 deletions stable/hazelcast/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,18 @@ Create the name of the service to use
{{- end -}}

{{/*
Create the config of the service-name to use
Generate the Hazelcast configuration, ensuring that any conflicting discovery configurations are resolved.
Remove the default value for the 'service-name' field when other discovery mechanisms are explicitly used.
*/}}
{{- define "hazelcast.serviceNameConfig" -}}
{{- if and ((((((.Values.hazelcast).yaml).hazelcast).network).join).kubernetes)
(or
(index .Values.hazelcast.yaml.hazelcast.network.join.kubernetes "service-dns")
(index .Values.hazelcast.yaml.hazelcast.network.join.kubernetes "service-label-name")
(index .Values.hazelcast.yaml.hazelcast.network.join.kubernetes "pod-label-name")
) -}}
{{ default "" }}
{{- else -}}
{{ template "hazelcast.serviceName" .}}
{{- define "hazelcast.config" -}}
{{- $config := .Values.hazelcast.yaml | deepCopy -}}
{{- $k8sJoin := $config.hazelcast.network.join.kubernetes -}}
{{- if and $k8sJoin -}}
{{- if or (index $k8sJoin "service-dns") (index $k8sJoin "service-label-name") (index $k8sJoin "pod-label-name") -}}
{{- $_ := unset $k8sJoin "service-name" -}}
{{- end -}}
{{- end -}}
{{- toYaml $config -}}
{{- end -}}

{{/*
Expand Down
2 changes: 1 addition & 1 deletion stable/hazelcast/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ data:
{{ $val | indent 4}}
{{- end }}
hazelcast.yaml: |-
{{ toYaml .Values.hazelcast.yaml | indent 4 }}
{{ include "hazelcast.config" . | indent 4 }}
{{- end -}}
2 changes: 1 addition & 1 deletion stable/hazelcast/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
- name: JAVA_OPTS
value: "-Dhazelcast.config=/data/hazelcast/hazelcast.yaml -DserviceName={{ template "hazelcast.serviceNameConfig" . }} -Dnamespace={{ .Release.Namespace }} -Dhz.jet.enabled={{ .Values.jet.enabled }} {{ if .Values.gracefulShutdown.enabled }}-Dhazelcast.shutdownhook.policy=GRACEFUL -Dhazelcast.shutdownhook.enabled=true -Dhazelcast.graceful.shutdown.max.wait={{ .Values.gracefulShutdown.maxWaitSeconds }} {{ end }} {{ if .Values.metrics.enabled }}-Dhazelcast.jmx=true{{ end }} {{ .Values.hazelcast.javaOpts }}"
value: "-Dhazelcast.config=/data/hazelcast/hazelcast.yaml -DserviceName={{ template "hazelcast.serviceName" . }} -Dnamespace={{ .Release.Namespace }} -Dhz.jet.enabled={{ .Values.jet.enabled }} {{ if .Values.gracefulShutdown.enabled }}-Dhazelcast.shutdownhook.policy=GRACEFUL -Dhazelcast.shutdownhook.enabled=true -Dhazelcast.graceful.shutdown.max.wait={{ .Values.gracefulShutdown.maxWaitSeconds }} {{ end }} {{ if .Values.metrics.enabled }}-Dhazelcast.jmx=true{{ end }} {{ .Values.hazelcast.javaOpts }}"
{{- if .Values.hazelcast.loggingLevel }}
- name: LOGGING_LEVEL
value: {{ .Values.hazelcast.loggingLevel }}
Expand Down

0 comments on commit e1b0125

Please sign in to comment.