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 you phpBB 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 "phpBB 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 "phpBB 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 "phpBB URL: http://127.0.0.1:8080/"

{{- end }}

2. Login with the following credentials

  echo Username: {{ .Values.phpbbUsername }}
  echo Password: $(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "phpbb.secretName" . }} -o jsonpath="{.data.phpbb-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 phpBB with a resolvable database
host. To configure phpBB to use and external database host:

1. Complete your phpBB 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/phpbb

{{- end }}

{{- include "phpbb.checkRollingTags" . }}

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

{{- if not .Values.existingSecret -}}
  {{- $requiredphpBBPassword := dict "valueKey" "phpbbPassword" "secret" $secretName "field" "phpbb-password" "context" $ -}}
  {{- $requiredphpBBPasswordError := include "common.validations.values.single.empty" $requiredphpBBPassword -}}
  {{- $passwordValidationErrors = append $passwordValidationErrors $requiredphpBBPasswordError -}}
{{- end -}}

{{- $databaseSecretName := include "phpbb.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" "db-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 -}}
