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 TestLink 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 eq .Values.service.type "NodePort" }}
  export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.names.fullname" . }})
  export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
  echo "TestLink URL: http://$NODE_IP:$NODE_PORT/"

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

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

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

{{- $port:=.Values.service.port | toString }}
  echo "TestLink URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ .Values.service.port }}{{ end }}/"

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

  kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ include "common.names.fullname" . }} 8080:{{ .Values.service.port }}
  echo "TestLink URL: http://127.0.0.1:8080/"

{{- end }}

2. Login with the following credentials

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

1. Complete your TestLink 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/testlink

{{- end }}

{{- include "common.warnings.rollingTag" .Values.image }}
{{- include "common.warnings.rollingTag" .Values.metrics.image }}
{{- include "common.warnings.rollingTag" .Values.volumePermissions.image }}
{{- include "common.warnings.rollingTag" .Values.certificates.image }}

{{- $passwordErrors := list -}}
{{- $secretName := include "testlink.secretName" . -}}

{{- if not .Values.existingSecret -}}
  {{- $requiredTestLinkPassword := dict "valueKey" "testlinkPassword" "secret" $secretName "field" "testlink-password" "context" $ -}}
  {{- $requiredTestLinkPasswordError := include "common.validations.values.single.empty" $requiredTestLinkPassword -}}
  {{- $passwordErrors =  append $passwordErrors $requiredTestLinkPasswordError -}}
{{- end -}}

{{- $passwordMysqlErrors := include "common.validations.values.mariadb.passwords" (dict "secretName" (include "testlink.mariadb.fullname" .) "subchart" true "context" $) -}}
{{- $passwordErrors = append $passwordErrors $passwordMysqlErrors -}}

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

{{- if and (not .Values.mariadb.enabled) .Release.IsUpgrade -}}
  {{- $databaseSecretName := printf "%s-%s" .Release.Name "externaldb" -}}
  {{- $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 -}}
