{{- if empty (include "host" .) -}}
###############################################################################
### ERROR: You did not provide an external host in your 'helm install' call ###
###############################################################################

This deployment will be incomplete until you configure Magento with a resolvable
host. To configure Magento with the URL of your service:

1. Get the Magento URL by running:

  {{- if contains "NodePort" .Values.serviceType }}

  export APP_PORT=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath="{.spec.ports[0].nodePort}")
  export APP_HOST=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")

  {{- else if contains "LoadBalancer" .Values.serviceType }}

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

  export APP_HOST=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
  export APP_PASSWORD=$(printf $(printf '\%o' `kubectl get secret --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath="{.data.magento-password[*]}"`))
  export APP_DATABASE_PASSWORD=$(printf $(printf '\%o' `kubectl get secret --namespace {{ .Release.Namespace }} {{ template "mariadb.fullname" . }} -o jsonpath="{.data.mariadb-root-password[*]}"`))
  {{- end }}

2. Complete your Magento deployment by running:

  helm upgrade {{ .Release.Name }} \
    --set magentoHost=$APP_HOST,magentoPassword=$APP_PASSWORD,mariadb.mariadbRootPassword=$APP_DATABASE_PASSWORD stable/magento

{{- else -}}
1. Get the Magento URL by running:

{{- if eq .Values.serviceType "ClusterIP" }}

  export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "fullname" . }}" -o jsonpath="{.items[0].metadata.name}")
  echo http://127.0.0.1:8080/
  kubectl port-forward $POD_NAME 8080:80
{{- else }}

  echo Store URL : http://{{ include "host" . }}/
  echo Admin URL : http://{{ include "host" . }}/{{ .Values.magentoAdminUri }}
{{- end }}

2. Get your Magento login credentials by running:

  echo Username: {{ .Values.magentoUsername }}
  echo Password: $(printf $(printf '\%o' `kubectl get secret --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath="{.data.magento-password[*]}"`))
{{- end }}
