CHART NAME: {{ .Chart.Name }}
CHART VERSION: {{ .Chart.Version }}
APP VERSION: {{ .Chart.AppVersion }}

Did you know there are enterprise versions of the Bitnami catalog? For enhanced secure software supply chain features, unlimited pulls from Docker, LTS support, or application customization, see Bitnami Premium or Tanzu Application Catalog. See https://www.arrow.com/globalecs/na/vendors/bitnami for more information.

** Please be patient while the chart is being deployed **

{{- if .Values.diagnosticMode.enabled }}
The chart has been deployed in diagnostic mode. All probes have been disabled and the command has been overwritten with:

  command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 4 }}
  args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 4 }}

Get the list of pods by executing:

  kubectl get pods --namespace {{ include "common.names.namespace" . }} -l app.kubernetes.io/instance={{ .Release.Name }}

Access the pod you want to debug by executing

  kubectl exec --namespace {{ include "common.names.namespace" . }} -ti <NAME OF THE POD> -- bash

In order to replicate the container startup scripts execute this command:

    /opt/bitnami/scripts/sonarqube/entrypoint.sh /opt/bitnami/scripts/sonarqube/run.sh

{{- else }}
{{- $port := .Values.service.ports.http | toString }}

Your SonarQube(TM) site can be accessed through the following DNS name from within your cluster:

    {{ include "common.names.fullname" . }}.{{ include "common.names.namespace" . }}.svc.{{ .Values.clusterDomain }} (port {{ $port }})

To access your SonarQube(TM) site from outside the cluster follow the steps below:

{{- if .Values.ingress.enabled }}

1. Get the SonarQube(TM) URL and associate SonarQube(TM) hostname to your cluster external IP:

   export CLUSTER_IP=$(minikube ip) # On Minikube. Use: `kubectl cluster-info` on others K8s clusters
   echo "SonarQube(TM) URL: http{{ if .Values.ingress.tls }}s{{ end }}://{{ .Values.ingress.hostname }}/"
   echo "$CLUSTER_IP  {{ .Values.ingress.hostname }}" | sudo tee -a /etc/hosts

{{- else }}

1. Get the SonarQube(TM) URL by running these commands:

{{- if contains "NodePort" .Values.service.type }}

   export NODE_PORT=$(kubectl get --namespace {{ include "common.names.namespace" . }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "common.names.fullname" . }})
   export NODE_IP=$(kubectl get nodes --namespace {{ include "common.names.namespace" . }} -o jsonpath="{.items[0].status.addresses[0].address}")
   echo "SonarQube(TM) URL: http://$NODE_IP:$NODE_PORT/"

{{- else if contains "LoadBalancer" .Values.service.type }}

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace {{ include "common.names.namespace" . }} -w {{ template "common.names.fullname" . }}'

   export SERVICE_IP=$(kubectl get svc --namespace {{ include "common.names.namespace" . }} {{ template "common.names.fullname" . }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}")
   echo "SonarQube(TM) URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ $port }}{{ end }}/"

{{- else if contains "ClusterIP"  .Values.service.type }}

   kubectl port-forward --namespace {{ include "common.names.namespace" . }} svc/{{ template "common.names.fullname" . }} {{ $port }}:{{ $port }} &
   echo "SonarQube(TM) URL: http://127.0.0.1{{- if ne $port "80" }}:{{ $port }}{{ end }}/"

{{- end }}
{{- end }}

2. Open a browser and access SonarQube(TM) using the obtained URL.

3. Login with the following credentials below:

  echo Username: {{ .Values.sonarqubeUsername }}
  echo Password: $(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ template "common.names.fullname" . }} -o jsonpath="{.data.sonarqube-password}" | base64 -d)

{{- if .Values.metrics.jmx.enabled }}

You can access the JMX Prometheus metrics following the steps below:

1. Get the JMX Prometheus metrics URL by running:

    kubectl port-forward --namespace {{ include "common.names.namespace" . }} svc/{{ printf "%s-jmx-metrics" (include "common.names.fullname" .) }} {{ .Values.metrics.jmx.service.ports.metrics }}:{{ .Values.metrics.jmx.service.ports.metrics }} &
    echo "JMX Prometheus metrics URL: http://127.0.0.1:{{ .Values.metrics.jmx.service.ports.metrics }}/"

2. Open a browser and access JMX Prometheus metrics using the obtained URL.

{{- end }}
{{- end }}

{{- include "common.warnings.rollingTag" .Values.image }}
{{- include "common.warnings.rollingTag" .Values.volumePermissions.image }}
{{- include "common.warnings.rollingTag" .Values.sysctl.image }}
{{- include "sonarqube.validateValues" . }}
{{- $passwordValidationErrors := list -}}
{{- if not .Values.existingSecret -}}
    {{- $secretName := include "sonarqube.secretName" . -}}
    {{- $requiredSonarQubePassword := dict "valueKey" "sonarqubePassword" "secret" $secretName "field" "sonarqube-password" "context" $ -}}
    {{- $requiredSonarQubePasswordError := include "common.validations.values.single.empty" $requiredSonarQubePassword -}}
    {{- $passwordValidationErrors = append $passwordValidationErrors $requiredSonarQubePasswordError -}}
{{- end }}
{{- include "common.errors.upgrade.passwords.empty" (dict "validationErrors" $passwordValidationErrors "context" $) -}}
{{- include "common.warnings.resources" (dict "sections" (list "caCerts" "metrics.jmx" "plugins" "" "sysctl" "volumePermissions") "context" $) }}
{{- include "common.warnings.modifiedImages" (dict "images" (list .Values.image .Values.caCerts.image .Values.plugins.image .Values.volumePermissions.image .Values.sysctl.image .Values.metrics.jmx.image) "context" $) }}
{{- include "common.errors.insecureImages" (dict "images" (list .Values.image .Values.caCerts.image .Values.plugins.image .Values.volumePermissions.image .Values.sysctl.image .Values.metrics.jmx.image) "context" $) }}
