Skip to content

Commit afde688

Browse files
Add templating for sonar-properties
1 parent a7cba45 commit afde688

File tree

5 files changed

+62
-12
lines changed

5 files changed

+62
-12
lines changed

charts/sonarqube-dce/templates/_helpers.tpl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,3 +563,41 @@ Remove incompatible user/group values that do not work in Openshift out of the b
563563
{{- end -}}
564564
{{- end -}}
565565
{{- end -}}
566+
567+
{{/*
568+
Generate required Hazelcast cluster properties when custom ports are configured.
569+
This helper automatically sets the sonar.cluster.node properties when any of the
570+
Hazelcast ports (port, webPort, cePort) are configured, ensuring proper cluster communication.
571+
*/}}
572+
{{- define "sonarqube.hazelcastProperties" -}}
573+
{{- $props := dict -}}
574+
{{- if .Values.ApplicationNodes.port -}}
575+
{{- $_ := set $props "sonar.cluster.node.port" (.Values.ApplicationNodes.port | toString) -}}
576+
{{- end -}}
577+
{{- if .Values.ApplicationNodes.webPort -}}
578+
{{- $_ := set $props "sonar.cluster.node.web.port" (.Values.ApplicationNodes.webPort | toString) -}}
579+
{{- end -}}
580+
{{- if .Values.ApplicationNodes.cePort -}}
581+
{{- $_ := set $props "sonar.cluster.node.ce.port" (.Values.ApplicationNodes.cePort | toString) -}}
582+
{{- end -}}
583+
{{- toYaml $props -}}
584+
{{- end -}}
585+
586+
{{/*
587+
Merge user-provided sonarProperties with automatically generated Hazelcast properties.
588+
User-provided properties take precedence over automatically generated ones.
589+
*/}}
590+
{{- define "sonarqube.mergedSonarProperties" -}}
591+
{{- $hazelcastProps := fromYaml (include "sonarqube.hazelcastProperties" .) | default dict -}}
592+
{{- $userProps := .Values.ApplicationNodes.sonarProperties | default dict -}}
593+
{{- $merged := dict -}}
594+
{{- /* Start with automatically generated properties */}}
595+
{{- range $key, $val := $hazelcastProps -}}
596+
{{- $_ := set $merged $key $val -}}
597+
{{- end -}}
598+
{{- /* User properties override automatic ones */}}
599+
{{- range $key, $val := $userProps -}}
600+
{{- $_ := set $merged $key $val -}}
601+
{{- end -}}
602+
{{- toYaml $merged -}}
603+
{{- end -}}

charts/sonarqube-dce/templates/config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ metadata:
1212
heritage: {{ .Release.Service }}
1313
data:
1414
sonar.properties: |
15-
{{- range $key, $val := .Values.ApplicationNodes.sonarProperties }}
15+
{{- $mergedProps := fromYaml (include "sonarqube.mergedSonarProperties" .) | default dict }}
16+
{{- range $key, $val := $mergedProps }}
1617
{{ $key }}={{ $val }}
1718
{{- end }}
1819
{{- if .Values.sonarSecretKey }}

charts/sonarqube-dce/templates/service.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,19 @@ spec:
6868
clusterIP: None
6969
publishNotReadyAddresses: true
7070
ports:
71-
- port: {{ .Values.ApplicationNodes.port }}
71+
- port: {{ .Values.ApplicationNodes.port | default 9003 }}
7272
targetPort: hazelcast
7373
protocol: TCP
7474
appProtocol: tcp
7575
name: hazelcast
76-
{{- if and .Values.ApplicationNodes.webPort (ne .Values.ApplicationNodes.webPort "") }}
76+
{{- if .Values.ApplicationNodes.webPort }}
7777
- port: {{ .Values.ApplicationNodes.webPort }}
7878
targetPort: hazelcast-web
7979
protocol: TCP
8080
appProtocol: tcp
8181
name: hazelcast-web
8282
{{- end }}
83-
{{- if and .Values.ApplicationNodes.cePort (ne .Values.ApplicationNodes.cePort "") }}
83+
{{- if .Values.ApplicationNodes.cePort }}
8484
- port: {{ .Values.ApplicationNodes.cePort }}
8585
targetPort: hazelcast-ce
8686
protocol: TCP

charts/sonarqube-dce/templates/sonarqube-application.yaml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ spec:
102102
{{- . | toYaml | trim | nindent 12 }}
103103
{{- end }}
104104
{{- end }}
105-
{{- if or .Values.ApplicationNodes.sonarProperties .Values.ApplicationNodes.sonarSecretProperties .Values.sonarSecretKey }}
105+
{{- $hasMergedProps := or .Values.ApplicationNodes.sonarProperties .Values.ApplicationNodes.port .Values.ApplicationNodes.webPort .Values.ApplicationNodes.cePort }}
106+
{{- if or $hasMergedProps .Values.ApplicationNodes.sonarSecretProperties .Values.sonarSecretKey }}
106107
- name: concat-properties
107108
image: {{ default (include "sonarqube.image" .) .Values.initContainers.image }}
108109
imagePullPolicy: {{ .Values.ApplicationNodes.image.pullPolicy }}
@@ -121,7 +122,7 @@ spec:
121122
awk 1 /tmp/props/sonar.properties /tmp/props/secret.properties > /tmp/result/sonar.properties
122123
fi
123124
volumeMounts:
124-
{{- if or .Values.ApplicationNodes.sonarProperties .Values.sonarSecretKey }}
125+
{{- if or $hasMergedProps .Values.sonarSecretKey }}
125126
- mountPath: /tmp/props/sonar.properties
126127
name: config
127128
subPath: sonar.properties
@@ -248,8 +249,18 @@ spec:
248249
protocol: TCP
249250
{{- end }}
250251
- name: hazelcast
251-
containerPort: 9003
252+
containerPort: {{ .Values.ApplicationNodes.port | default 9003 }}
252253
protocol: TCP
254+
{{- if .Values.ApplicationNodes.webPort }}
255+
- name: hazelcast-web
256+
containerPort: {{ .Values.ApplicationNodes.webPort }}
257+
protocol: TCP
258+
{{- end }}
259+
{{- if .Values.ApplicationNodes.cePort }}
260+
- name: hazelcast-ce
261+
containerPort: {{ .Values.ApplicationNodes.cePort }}
262+
protocol: TCP
263+
{{- end }}
253264
resources:
254265
{{ toYaml (default .Values.ApplicationNodes.resources .Values.resource) | indent 12 }}
255266
env:
@@ -338,7 +349,7 @@ spec:
338349
securityContext: {{- . | nindent 12 }}
339350
{{- end }}
340351
volumeMounts:
341-
{{- if or .Values.ApplicationNodes.sonarProperties .Values.ApplicationNodes.sonarSecretProperties .Values.sonarSecretKey }}
352+
{{- if or $hasMergedProps .Values.ApplicationNodes.sonarSecretProperties .Values.sonarSecretKey }}
342353
- mountPath: {{ .Values.sonarqubeFolder }}/conf/sonar.properties
343354
subPath: sonar.properties
344355
name: concat-dir
@@ -415,7 +426,7 @@ spec:
415426
{{- end }}
416427
serviceAccountName: {{ template "sonarqube.serviceAccountName" . }}
417428
volumes:
418-
{{- if or .Values.ApplicationNodes.sonarProperties .Values.sonarSecretKey }}
429+
{{- if or $hasMergedProps .Values.sonarSecretKey }}
419430
- name: config
420431
configMap:
421432
name: {{ template "sonarqube.fullname" . }}-app-config
@@ -493,7 +504,7 @@ spec:
493504
emptyDir: {{- toYaml .Values.emptyDir | nindent 10 }}
494505
- name : tmp-dir
495506
emptyDir: {{- toYaml .Values.emptyDir | nindent 10 }}
496-
{{- if or .Values.ApplicationNodes.sonarProperties .Values.ApplicationNodes.sonarSecretProperties .Values.sonarSecretKey }}
507+
{{- if or $hasMergedProps .Values.ApplicationNodes.sonarSecretProperties .Values.sonarSecretKey }}
497508
- name : concat-dir
498509
emptyDir: {{- toYaml .Values.emptyDir | nindent 10 -}}
499510
{{- end }}

charts/sonarqube-dce/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ applicationNodes:
413413
tolerations: []
414414

415415
## The following values are used to set the ports for the Hazelcast cluster communication
416-
# The port used by the application nodes to communicate with each other
417-
port: 9003
416+
# The port used by the application nodes to communicate with each other. (If unset, it will be assigned to 9003)
417+
# port: 9003
418418
# The port used by the web process to communicate with other application nodes (If unset, it will be dynamically allocated)
419419
# webPort: 4023
420420
# The port used by the compute engine process to communicate with other application nodes (If unset, it will be dynamically allocated)

0 commit comments

Comments
 (0)