CHART NAME: {{ .Chart.Name }}
CHART VERSION: {{ .Chart.Version }}
APP VERSION: {{ .Chart.AppVersion }}
{{- if or .Values.mariadb.enabled .Values.externalDatabase.host -}}
** Please be patient while the chart is being deployed **
{{- if and .Values.ingress.enabled (ne .Values.service.type "ClusterIP") }}
** Notice : Usually with ingress the service.type should be set to ClusterIP, which is not the case to this deployment! **
{{- end }}

1. Access your Joomla! instance with:

{{- if .Values.ingress.enabled }}
  {{ if .Values.ingress.tls }}
    {{- range .Values.ingress.hosts }}
    - https://{{ . }}
    {{- end }}
  {{- else }}
    {{- range .Values.ingress.hosts }}
    - http://{{ . }}
    {{- end }}
  {{- end }}
{{- else if contains "NodePort" .Values.service.type }}
  export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "common.names.fullname" . }})
  export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
  echo "Joomla! URL: http://$NODE_IP:$NODE_PORT/"

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

** Please ensure an external IP is associated to the {{ template "common.names.fullname" . }} service before proceeding **
** Watch the status using: kubectl get svc --namespace {{ .Release.Namespace }} -w {{ template "common.names.fullname" . }} **

  export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "common.names.fullname" . }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}")

{{- $port:= (coalesce .Values.service.ports.http .Values.service.port) | toString }}
  echo "Joomla! URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ coalesce .Values.service.ports.http .Values.service.port }}{{ end }}/"

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

  kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ template "common.names.fullname" . }} 8080:{{ coalesce .Values.service.ports.http .Values.service.port }}
  echo "Joomla! URL: http://127.0.0.1:8080/"

{{- end }}

2. Login with the following credentials

  echo Username: {{ .Values.joomlaUsername }}
  echo Password: $(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "joomla.secretName" . }} -o jsonpath="{.data.joomla-password}" | base64 --decode)

{{- else -}}

########################################################################################
### ERROR: You did not provide an external database host in your 'helm install' call ###
########################################################################################

This deployment will be incomplete until you configure Joomla! with a resolvable database
host. To configure Joomla! to use and external database host:

1. Complete your Joomla! deployment by running:

  helm upgrade --namespace {{ .Release.Namespace }} {{ .Release.Name }} --set service.type={{ .Values.service.type }},mariadb.enabled=false,externalDatabase.host=YOUR_EXTERNAL_DATABASE_HOST bitnami/joomla

{{- end }}

{{- include "joomla.checkRollingTags" . }}

{{- $passwordValidationErrors := list -}}
{{- $secretName := include "joomla.secretName" . -}}

{{- if not .Values.existingSecret -}}
  {{- $requiredJoomlaPassword := dict "valueKey" "joomlaPassword" "secret" $secretName "field" "joomla-password" "context" $ -}}
  {{- $requiredJoomlaPasswordError := include "common.validations.values.single.empty" $requiredJoomlaPassword -}}
  {{- $passwordValidationErrors = append $passwordValidationErrors $requiredJoomlaPasswordError -}}
{{- end -}}

{{- $databaseSecretName := include "joomla.databaseSecretName" . -}}

{{- if .Values.mariadb.enabled }}
    {{- $mariadbPasswordValidationErrors := include "common.validations.values.mariadb.passwords" (dict "secret" $databaseSecretName "subchart" true "context" $) -}}
    {{- $passwordValidationErrors = append $passwordValidationErrors $mariadbPasswordValidationErrors -}}
{{- end }}

{{- include "common.errors.upgrade.passwords.empty" (dict "validationErrors" $passwordValidationErrors "context" $) -}}

{{- if and (not .Values.mariadb.enabled) .Release.IsUpgrade -}}
  {{- $requiredExternalPassword := dict "valueKey" "externalDatabase.password"  "secret" $databaseSecretName "field" "mariadb-password" -}}

WARNING: Review values for the following password in the command, if they are correct please ignore this notice.
  {{- include "common.validations.values.multiple.empty" (dict "required" (list $requiredExternalPassword) "context" $) -}}
{{- end -}}
