{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
  name: {{ include "common.names.fullname" . }}
  namespace: {{ include "common.names.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 }}
      automountServiceAccountToken: {{ .Values.automountServiceAccountToken }}
      {{- 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: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.podSecurityContext "context" $) | nindent 8 }}
      {{- end }}
      initContainers:
        - name: prepare-base-dir
          image: {{ include "sonarqube.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
          {{- if .Values.resources }}
          resources: {{- toYaml .Values.resources | nindent 12 }}
          {{- else if ne .Values.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.resourcesPreset) | nindent 12 }}
          {{- end }}
          {{- if .Values.containerSecurityContext.enabled }}
          securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.containerSecurityContext "context" $) | nindent 12 }}
          {{- end }}
          command:
            - /bin/bash
          args:
            - -ec
            - |
              #!/bin/bash

              . /opt/bitnami/scripts/liblog.sh

              info "Copying base dir to empty dir"
              # In order to not break the application functionality (such as upgrades or plugins) we need
              # to make the base directory writable, so we need to copy it to an empty dir volume
              cp -r --preserve=mode /opt/bitnami/sonarqube /emptydir/app-base-dir

              info "Copy operation completed"
          volumeMounts:
            - name: empty-dir
              mountPath: /emptydir
        {{- 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
            - name: empty-dir
              mountPath: /tmp
              subPath: tmp-dir
          {{- if .Values.plugins.resources }}
          resources: {{- toYaml .Values.plugins.resources | nindent 12 }}
          {{- else if ne .Values.plugins.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.plugins.resourcesPreset) | nindent 12 }}
          {{- end }}
          {{- if .Values.plugins.containerSecurityContext.enabled }}
          securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.plugins.containerSecurityContext "context" $) | nindent 12 }}
          {{- end }}
        {{- 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
            - name: empty-dir
              mountPath: /tmp
              subPath: tmp-dir
          {{- if .Values.caCerts.resources }}
          resources: {{- toYaml .Values.caCerts.resources | nindent 12 }}
          {{- else if ne .Values.caCerts.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.caCerts.resourcesPreset) | nindent 12 }}
          {{- end }}
          {{- if .Values.caCerts.containerSecurityContext.enabled }}
          securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.caCerts.containerSecurityContext "context" $) | nindent 12 }}
          {{- end }}
        {{- 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 }}
          {{- if .Values.sysctl.containerSecurityContext.enabled }}
          securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.sysctl.containerSecurityContext "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.sysctl.resources }}
          resources: {{- toYaml .Values.sysctl.resources | nindent 12 }}
          {{- else if ne .Values.sysctl.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.sysctl.resourcesPreset) | 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: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.volumePermissions.containerSecurityContext "context" $) | nindent 12 }}
          {{- end }}
          {{- if .Values.volumePermissions.resources }}
          resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }}
          {{- else if ne .Values.volumePermissions.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.volumePermissions.resourcesPreset) | nindent 12 }}
          {{- end }}
          volumeMounts:
            - name: sonarqube
              mountPath: /bitnami/sonarqube
            - name: empty-dir
              mountPath: /tmp
              subPath: tmp-dir
        {{- end }}
        {{- if .Values.initContainers }}
          {{- include "common.tplvalues.render" (dict "value" .Values.initContainers "context" $) | nindent 8 }}
        {{- end }}
      containers:
        - name: sonarqube
          image: {{ include "sonarqube.image" . }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          {{- if .Values.containerSecurityContext.enabled }}
          securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.containerSecurityContext "context" $) | 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 }}
            {{- if .Values.usePasswordFiles }}
            - name: SONARQUBE_PASSWORD_FILE
              value: "/opt/bitnami/sonarqube/secrets/sonarqube-password"
            {{- else }}
            - name: SONARQUBE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ include "sonarqube.secretName" . }}
                  key: sonarqube-password
            {{- end }}
            - 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 }}
            {{- if .Values.usePasswordFiles }}
            - name: SONARQUBE_DATABASE_PASSWORD_FILE
              value: "/opt/bitnami/sonarqube/secrets/password"
            {{- else }}
            - name: SONARQUBE_DATABASE_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ include "sonarqube.database.secretName" . }}
                  key: password
            {{- end }}
            {{- 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 }}
            {{- if .Values.usePasswordFiles }}
            - name: SONARQUBE_SMTP_PASSWORD_FILE
              value: "/opt/bitnami/sonarqube/secrets/smtp-password"
            {{- else }}
            - name: SONARQUBE_SMTP_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: {{ include "sonarqube.smtpSecretName" . }}
                  key: smtp-password
            {{- end }}
            {{- 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: SONARQUBE_CE_JAVA_ADD_OPTS
              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 }}
          {{- else if ne .Values.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.resourcesPreset) | 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 }}
            tcpSocket:
              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:
            - name: empty-dir
              mountPath: /opt/bitnami/sonarqube
              subPath: app-base-dir
            - name: empty-dir
              mountPath: /tmp
              subPath: tmp-dir
            - name: sonarqube
              mountPath: /bitnami/sonarqube
            {{- if  .Values.usePasswordFiles }}
            - name: sonarqube-secrets
              mountPath: /opt/bitnami/sonarqube/secrets
            {{- end }}
            {{- 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: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.metrics.jmx.containerSecurityContext "context" $) | 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_standalone.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 }}
          {{- else if ne .Values.metrics.jmx.resourcesPreset "none" }}
          resources: {{- include "common.resources.preset" (dict "type" .Values.metrics.jmx.resourcesPreset) | nindent 12 }}
          {{- end }}
          {{- if .Values.metrics.jmx.livenessProbe.enabled }}
          livenessProbe: {{- omit .Values.metrics.jmx.livenessProbe "enabled" | toYaml | nindent 12 }}
            tcpSocket:
              port: metrics
          {{- end }}
          {{- if .Values.metrics.jmx.readinessProbe.enabled }}
          readinessProbe: {{- omit .Values.metrics.jmx.readinessProbe "enabled" | toYaml | nindent 12 }}
            httpGet:
              path: /
              port: metrics
          {{- end }}
          volumeMounts:
            - name: empty-dir
              mountPath: /tmp
              subPath: tmp-dir
            - name: jmx-config
              mountPath: /etc/jmx
        {{- end }}
        {{- if .Values.sidecars }}
        {{- include "common.tplvalues.render" ( dict "value" .Values.sidecars "context" $) | nindent 8 }}
        {{- end }}
      volumes:
        - name: empty-dir
          emptyDir: {}
        {{- if .Values.usePasswordFiles }}
        - name: sonarqube-secrets
          projected:
            sources:
              - secret:
                  name: {{ include "sonarqube.secretName" . }}
              - secret:
                  name: {{ include "sonarqube.database.secretName" . }}
              {{- if or .Values.smtpPassword .Values.smtpExistingSecret }}
              - secret:
                  name: {{ include "sonarqube.smtpSecretName" . }}
              {{- end }}
        {{- end }}
        {{- 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 }}
