Files
charts/bitnami/sonarqube/templates/deployment.yaml
2023-09-07 11:58:27 +02:00

426 lines
21 KiB
YAML

{{- /*
Copyright VMware, Inc.
SPDX-License-Identifier: APACHE-2.0
*/}}
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
name: {{ include "common.names.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
replicas: {{ .Values.replicaCount }}
{{- if .Values.updateStrategy }}
strategy: {{- toYaml .Values.updateStrategy | nindent 4 }}
{{- end }}
{{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.podLabels .Values.commonLabels ) "context" . ) }}
selector:
matchLabels: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 6 }}
template:
metadata:
annotations:
{{- if (include "sonarqube.createSecret" .) }}
checksum/secret: {{ include (print $.Template.BasePath "/secret.yaml") . | sha256sum }}
{{- end }}
{{- if .Values.metrics.jmx.enabled }}
checksum/jmx-configuration: {{ include (print $.Template.BasePath "/jmx-configmap.yaml") . | sha256sum }}
{{- end }}
{{- if .Values.podAnnotations }}
{{- include "common.tplvalues.render" (dict "value" .Values.podAnnotations "context" $) | nindent 8 }}
{{- end }}
labels: {{- include "common.labels.standard" ( dict "customLabels" $podLabels "context" $ ) | nindent 8 }}
spec:
serviceAccountName: {{ include "sonarqube.serviceAccountName" . }}
{{- include "sonarqube.imagePullSecrets" . | nindent 6 }}
{{- if .Values.hostAliases }}
hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.hostAliases "context" $) | nindent 8 }}
{{- end }}
{{- if .Values.affinity }}
affinity: {{- include "common.tplvalues.render" ( dict "value" .Values.affinity "context" $) | nindent 8 }}
{{- else }}
affinity:
podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }}
podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.podAntiAffinityPreset "customLabels" $podLabels "context" $) | nindent 10 }}
nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.nodeAffinityPreset.type "key" .Values.nodeAffinityPreset.key "values" .Values.nodeAffinityPreset.values) | nindent 10 }}
{{- end }}
{{- if .Values.nodeSelector }}
nodeSelector: {{- include "common.tplvalues.render" ( dict "value" .Values.nodeSelector "context" $) | nindent 8 }}
{{- end }}
{{- if .Values.tolerations }}
tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.tolerations "context" .) | nindent 8 }}
{{- end }}
{{- if .Values.priorityClassName }}
priorityClassName: {{ .Values.priorityClassName | quote }}
{{- end }}
{{- if .Values.schedulerName }}
schedulerName: {{ .Values.schedulerName | quote }}
{{- end }}
{{- if .Values.podSecurityContext.enabled }}
securityContext: {{- omit .Values.podSecurityContext "enabled" | toYaml | nindent 8 }}
{{- end }}
{{- if or .Values.initContainers .Values.caCerts.enabled .Values.plugins.install .Values.sysctl.enabled (and .Values.volumePermissions.enabled .Values.persistence.enabled) }}
initContainers:
{{- if .Values.plugins.install }}
- name: {{ printf "%s-install-plugins-initcontainer" (include "common.names.fullname" .) }}
image: {{ include "sonarqube.plugins.image" . }}
imagePullPolicy: {{ .Values.plugins.image.pullPolicy }}
command: [ "sh",
"-e",
"/tmp/scripts/install_plugins.sh" ]
volumeMounts:
- name: install-plugins
mountPath: /tmp/scripts/
- name: provisioning
mountPath: {{ .Values.provisioningFolder }}/extensions/plugins/
subPath: extensions/plugins
resources: {{- toYaml .Values.plugins.resources | nindent 12 }}
securityContext: {{- .Values.plugins.containerSecurityContext | toYaml | nindent 12 }}
{{- end }}
{{- if .Values.caCerts.enabled }}
- name: {{ printf "%s-ca-certs-initcontainer" (include "common.names.fullname" .) }}
image: {{ include "sonarqube.image" . }}
imagePullPolicy: {{ .Values.caCerts.image.pullPolicy }}
command: [ "sh" ]
args: [ "-c", "cp -f \"${JAVA_HOME}/lib/security/cacerts\" {{ .Values.provisioningFolder }}/certs/cacerts; if [ \"$(ls /tmp/secrets/ca-certs)\" ]; then for f in /tmp/secrets/ca-certs/*; do keytool -importcert -file \"${f}\" -alias \"$(basename \"${f}\")\" -keystore {{ .Values.provisioningFolder }}/certs/cacerts -storepass changeit -trustcacerts -noprompt; done; fi;" ]
volumeMounts:
- name: provisioning
mountPath: {{ .Values.provisioningFolder }}/certs
subPath: certs
- mountPath: /tmp/secrets/ca-certs
name: ca-certs
resources: {{- toYaml .Values.caCerts.resources | nindent 12 }}
securityContext: {{- .Values.caCerts.containerSecurityContext | toYaml | nindent 12 }}
{{- end }}
{{- if .Values.sysctl.enabled }}
## Image that performs the sysctl operation to modify Kernel settings (needed sometimes to avoid boot errors)
- name: sysctl
image: {{ include "sonarqube.sysctl.image" . }}
imagePullPolicy: {{ .Values.sysctl.image.pullPolicy | quote }}
command:
- /bin/bash
- -ec
- |
{{- include "sonarqube.sysctl.ifLess" (dict "key" "vm.max_map_count" "value" "262144") | nindent 14 }}
{{- include "sonarqube.sysctl.ifLess" (dict "key" "fs.file-max" "value" "65536") | nindent 14 }}
securityContext:
privileged: true
runAsUser: 0
{{- if .Values.sysctl.resources }}
resources: {{- toYaml .Values.sysctl.resources | nindent 12 }}
{{- end }}
{{- end }}
{{- if and .Values.volumePermissions.enabled .Values.persistence.enabled }}
- name: volume-permissions
image: {{ include "sonarqube.volumePermissions.image" . }}
imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }}
command:
- /bin/bash
args:
- -ec
- |
find /bitnami/sonarqube -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | xargs -r chown -R {{ .Values.containerSecurityContext.runAsUser }}:{{ .Values.podSecurityContext.fsGroup }}
{{- if .Values.volumePermissions.containerSecurityContext.enabled }}
securityContext: {{- omit .Values.volumePermissions.containerSecurityContext "enabled" | toYaml | nindent 12 }}
{{- end }}
{{- if .Values.volumePermissions.resources }}
resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }}
{{- end }}
volumeMounts:
- name: sonarqube
mountPath: /bitnami/sonarqube
subPath: data
{{- end }}
{{- if .Values.initContainers }}
{{- include "common.tplvalues.render" (dict "value" .Values.initContainers "context" $) | nindent 8 }}
{{- end }}
{{- end }}
containers:
- name: sonarqube
image: {{ include "sonarqube.image" . }}
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- if .Values.containerSecurityContext.enabled }}
securityContext: {{- omit .Values.containerSecurityContext "enabled" | toYaml | nindent 12 }}
{{- end }}
{{- if .Values.diagnosticMode.enabled }}
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
{{- else if .Values.command }}
command: {{- include "common.tplvalues.render" (dict "value" .Values.command "context" $) | nindent 12 }}
{{- end }}
{{- if .Values.diagnosticMode.enabled }}
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
{{- else if .Values.args }}
args: {{- include "common.tplvalues.render" (dict "value" .Values.args "context" $) | nindent 12 }}
{{- end }}
env:
- name: BITNAMI_DEBUG
value: {{ ternary "true" "false" (or .Values.image.debug .Values.diagnosticMode.enabled) | quote }}
- name: SONARQUBE_SKIP_BOOTSTRAP
value: {{ ternary "yes" "no" .Values.sonarqubeSkipInstall | quote }}
- name: SONARQUBE_USERNAME
value: {{ .Values.sonarqubeUsername | quote }}
- name: SONARQUBE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "sonarqube.secretName" . }}
key: sonarqube-password
- name: SONARQUBE_EMAIL
value: {{ .Values.sonarqubeEmail | quote }}
{{- if or .Values.plugins.install .Values.caCerts.enabled}}
- name: SONARQUBE_MOUNTED_PROVISIONING_DIR
value: {{ .Values.provisioningFolder }}
{{- end }}
{{- if .Values.minHeapSize }}
- name: SONARQUBE_MIN_HEAP_SIZE
value: {{ .Values.minHeapSize | quote }}
{{- end }}
{{- if .Values.maxHeapSize }}
- name: SONARQUBE_MAX_HEAP_SIZE
value: {{ .Values.maxHeapSize | quote }}
{{- end }}
{{- if .Values.sonarSecurityRealm }}
- name: SONAR_SECURITY_REALM
value: {{ .Values.sonarSecurityRealm | quote }}
{{- end }}
{{- if .Values.sonarAuthenticatorDowncase }}
- name: SONAR_AUTHENTICATOR_DOWNCASE
value: {{ .Values.sonarAuthenticatorDowncase | quote }}
{{- end }}
{{- if .Values.ldap.url }}
- name: LDAP_URL
value: {{ .Values.ldap.url | quote }}
{{- end }}
{{- if .Values.ldap.bindDn }}
- name: LDAP_BINDDN
value: {{ .Values.ldap.bindDn | quote }}
{{- end }}
{{- if .Values.ldap.bindPassword }}
- name: LDAP_BINDPASSWORD
value: {{ .Values.ldap.bindPassword | quote }}
{{- end }}
{{- if .Values.ldap.authentication }}
- name: LDAP_AUTHENTICATION
value: {{ .Values.ldap.authentication | quote }}
{{- end }}
{{- if .Values.ldap.realm }}
- name: LDAP_REALM
value: {{ .Values.ldap.realm | quote }}
{{- end }}
{{- if .Values.ldap.contextFactoryClass }}
- name: LDAP_CONTEXTFACTORYCLASS
value: {{ .Values.ldap.contextFactoryClass | quote }}
{{- end }}
{{- if .Values.ldap.StartTLS }}
- name: LDAP_STARTTLS
value: {{ .Values.ldap.StartTLS | quote }}
{{- end }}
{{- if .Values.ldap.followReferrals }}
- name: LDAP_FOLLOWREFERRALS
value: {{ .Values.ldap.followReferrals | quote }}
{{- end }}
{{- if .Values.ldap.user.baseDn }}
- name: LDAP_USER_BASEDN
value: {{ .Values.ldap.user.baseDn | quote }}
{{- end }}
{{- if .Values.ldap.user.request }}
- name: LDAP_USER_REQUEST
value: {{ .Values.ldap.user.request | quote }}
{{- end }}
{{- if .Values.ldap.user.realNameAttribute }}
- name: LDAP_USER_REALNAMEATTRIBUTE
value: {{ .Values.ldap.user.realNameAttribute | quote }}
{{- end }}
{{- if .Values.ldap.user.emailAttribute }}
- name: LDAP_USER_EMAILATTRIBUTE
value: {{ .Values.ldap.user.emailAttribute | quote }}
{{- end }}
{{- if .Values.ldap.group.baseDn }}
- name: LDAP_GROUP_BASEDN
value: {{ .Values.ldap.group.baseDn | quote }}
{{- end }}
{{- if .Values.ldap.group.request }}
- name: LDAP_GROUP_REQUEST
value: {{ .Values.ldap.group.request | quote }}
{{- end }}
{{- if .Values.ldap.group.idAttribute }}
- name: LDAP_GROUP_IDATTRIBUTE
value: {{ .Values.ldap.group.idAttribute | quote }}
{{- end }}
- name: SONARQUBE_START_TIMEOUT
value: {{ .Values.startTimeout | quote }}
- name: SONARQUBE_DATABASE_HOST
value: {{ include "sonarqube.database.host" . | quote }}
- name: SONARQUBE_DATABASE_PORT_NUMBER
value: {{ include "sonarqube.database.port" . | quote }}
- name: SONARQUBE_DATABASE_NAME
value: {{ include "sonarqube.database.name" . | quote }}
- name: SONARQUBE_DATABASE_USER
value: {{ include "sonarqube.database.username" . | quote }}
- name: SONARQUBE_DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "sonarqube.database.secretName" . }}
key: password
{{- if .Values.smtpHost }}
- name: SONARQUBE_SMTP_HOST
value: {{ .Values.smtpHost | quote }}
{{- end }}
{{- if .Values.smtpPort }}
- name: SONARQUBE_SMTP_PORT
value: {{ .Values.smtpPort | quote }}
{{- end }}
{{- if .Values.smtpUser }}
- name: SONARQUBE_SMTP_USER
value: {{ .Values.smtpUser | quote }}
{{- end }}
{{- if or .Values.smtpPassword .Values.smtpExistingSecret }}
- name: SONARQUBE_SMTP_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "sonarqube.smtpSecretName" . }}
key: smtp-password
{{- end }}
{{- if .Values.smtpProtocol }}
- name: SONARQUBE_SMTP_PROTOCOL
value: {{ .Values.smtpProtocol | quote }}
{{- end }}
- name: SONARQUBE_PORT_NUMBER
value: {{ .Values.containerPorts.http | quote }}
- name: SONARQUBE_ELASTICSEARCH_PORT_NUMBER
value: {{ .Values.containerPorts.elastic | quote }}
{{- if .Values.extraProperties }}
- name: SONARQUBE_EXTRA_PROPERTIES
value: {{ join "," .Values.extraProperties | quote }}
{{- end }}
- name: SONARQUBE_WEB_JAVA_ADD_OPTS
value: {{ template "sonarqube.jvmOpts" . }}
- name: SONAR_CE_JAVAADDITIONALOPTS
value: {{ template "sonarqube.jvmCEOpts" . }}
{{- if .Values.extraEnvVars }}
{{- include "common.tplvalues.render" (dict "value" .Values.extraEnvVars "context" $) | nindent 12 }}
{{- end }}
envFrom:
{{- if .Values.extraEnvVarsCM }}
- configMapRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.extraEnvVarsCM "context" $) }}
{{- end }}
{{- if .Values.extraEnvVarsSecret }}
- secretRef:
name: {{ include "common.tplvalues.render" (dict "value" .Values.extraEnvVarsSecret "context" $) }}
{{- end }}
{{- if .Values.resources }}
resources: {{- toYaml .Values.resources | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.containerPorts.http }}
- name: elastic
containerPort: {{ .Values.containerPorts.elastic }}
{{- if not .Values.diagnosticMode.enabled }}
{{- if .Values.customLivenessProbe }}
livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.customLivenessProbe "context" $) | nindent 12 }}
{{- else if .Values.livenessProbe.enabled }}
livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.livenessProbe "enabled") "context" $) | nindent 12 }}
httpGet:
path: /
port: http
{{- end }}
{{- if .Values.customReadinessProbe }}
readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.customReadinessProbe "context" $) | nindent 12 }}
{{- else if .Values.readinessProbe.enabled }}
readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.readinessProbe "enabled") "context" $) | nindent 12 }}
httpGet:
path: /
port: http
{{- end }}
{{- if .Values.customStartupProbe }}
startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.customStartupProbe "context" $) | nindent 12 }}
{{- else if .Values.startupProbe.enabled }}
startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.startupProbe "enabled") "context" $) | nindent 12 }}
tcpSocket:
port: http
{{- end }}
{{- end }}
{{- if .Values.lifecycleHooks }}
lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.lifecycleHooks "context" $) | nindent 12 }}
{{- end }}
volumeMounts:
- mountPath: /bitnami/sonarqube
name: sonarqube
{{- if or .Values.plugins.install .Values.caCerts.enabled }}
- name: provisioning
mountPath: {{ .Values.provisioningFolder }}
{{- end }}
{{- if .Values.extraVolumeMounts }}
{{- include "common.tplvalues.render" (dict "value" .Values.extraVolumeMounts "context" $) | nindent 12 }}
{{- end }}
{{- if .Values.metrics.jmx.enabled }}
- name: jmx-exporter
image: {{ include "sonarqube.metrics.jmx.image" . }}
imagePullPolicy: {{ .Values.metrics.jmx.image.pullPolicy | quote }}
{{- if .Values.metrics.jmx.containerSecurityContext.enabled }}
securityContext: {{- omit .Values.metrics.jmx.containerSecurityContext "enabled" | toYaml | nindent 12 }}
{{- end }}
{{- if .Values.diagnosticMode.enabled }}
command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
{{- else }}
command:
- java
- -XX:MaxRAMPercentage=100
- -XshowSettings:vm
- -jar
- jmx_prometheus_httpserver.jar
- {{ .Values.metrics.jmx.containerPorts.metrics | quote }}
- /etc/jmx/sonarqube-prometheus.yml
{{- end }}
ports:
- name: metrics
containerPort: {{ .Values.metrics.jmx.containerPorts.metrics }}
{{- if .Values.metrics.jmx.resources }}
resources: {{- toYaml .Values.metrics.jmx.resources | nindent 12 }}
{{- end }}
volumeMounts:
- name: jmx-config
mountPath: /etc/jmx
{{- end }}
{{- if .Values.sidecars }}
{{- include "common.tplvalues.render" ( dict "value" .Values.sidecars "context" $) | nindent 8 }}
{{- end }}
volumes:
{{- if or .Values.plugins.install .Values.caCerts.enabled }}
- name: provisioning
emptyDir: {}
{{- end }}
{{- if .Values.caCerts.enabled }}
- name: ca-certs
secret:
secretName: {{ .Values.caCerts.secret }}
{{- end }}
- name: sonarqube
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ (tpl .Values.persistence.existingClaim .) | default (include "common.names.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end }}
{{- if .Values.metrics.jmx.enabled }}
- name: jmx-config
configMap:
name: {{ printf "%s-jmx-conf" (include "common.names.fullname" .) }}
{{- end }}
{{- if .Values.plugins.install }}
- name: install-plugins
configMap:
name: {{ printf "%s-install-plugins-configmap" (include "common.names.fullname" .) }}
items:
- key: install_plugins.sh
path: install_plugins.sh
{{- end }}
{{- if .Values.extraVolumes }}
{{- include "common.tplvalues.render" (dict "value" .Values.extraVolumes "context" $) | nindent 8 }}
{{- end }}