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

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

{{- if and .Values.exposeManagementConsole (or (eq "NodePort" .Values.service.type) (eq "LoadBalancer" .Values.service.type) .Values.mgmtIngress.enabled) }}
-------------------------------------------------------------------------------
 WARNING

    By specifying "exposeManagementConsole=true" you have most likely exposed
    the WildFly Management console externally.

    Please note this is not recommended for production environments since
    you are exposing your WildFly server to potential attacks.
-------------------------------------------------------------------------------
{{- end }}

{{- if or .Values.ingress.enabled (and .Values.mgmtIngress.enabled .Values.exposeManagementConsole) }}

1. Get the Wildfly URL and associate its hostname to your cluster external IP:

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

{{- else }}

1. Get the WildFly URL by running:
{{- $httpPort:=(coalesce .Values.service.ports.http .Values.service.port) | toString }}
{{- $mgmtPort:=(coalesce .Values.service.ports.mgmt .Values.service.mgmtPort) | toString }}

{{- 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 "WildFly URL: http://$NODE_IP:$NODE_PORT"
  {{- if .Values.exposeManagementConsole }}
  export NODE_MGMT_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[1].nodePort}" services {{ template "common.names.fullname" . }})
  echo "WildFly Management URL: http://$NODE_IP:$NODE_MGMT_PORT"
  {{- end }}

{{- 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 {{ .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 }}" }}")
  echo "WildFly URL: http://$SERVICE_IP{{- if ne $httpPort "80" }}:{{ $httpPort }}{{ end }}/"
  {{- if .Values.exposeManagementConsole }}
  echo "WildFly Management URL: http://$SERVICE_IP{{- if ne $mgmtPort "80" }}:{{ $mgmtPort }}{{ end }}/"
  {{- end }}

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

  kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ template "common.names.fullname" . }} 8080:{{ $httpPort }} &
  kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ template "common.names.fullname" . }} 9990:{{ $mgmtPort }} &
  echo "WildFly URL: http://127.0.0.1:8080/"
  echo "WildFly Management URL: http://127.0.0.1:9990/"

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

2. Login with the following credentials

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

{{- include "wildfly.checkRollingTags" . }}
{{- $passwordValidationErrors := list -}}
{{- $secretName := include "common.names.fullname" . -}}
{{- $requiredWildflyPassword := dict "valueKey" "wildflyPassword" "secret" $secretName "field" "wildfly-password" "context" $ -}}
{{- $requiredWildflyPasswordError := include "common.validations.values.single.empty" $requiredWildflyPassword -}}
{{- $passwordValidationErrors = append $passwordValidationErrors $requiredWildflyPasswordError -}}
{{- include "common.errors.upgrade.passwords.empty" (dict "validationErrors" $passwordValidationErrors "context" $) -}}
{{- include "common.warnings.resources" (dict "sections" (list "" "volumePermissions") "context" $) }}
{{- include "common.warnings.modifiedImages" (dict "images" (list .Values.image .Values.volumePermissions.image) "context" $) }}