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

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

{{- if .Values.diagnosticMode.enabled }}

The chart has been deployed in diagnostic mode. All probes have been disabled and the command has been overwritten with:

  command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 4 }}
  args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 4 }}

Get the list of pods by executing:

  kubectl get pods --namespace {{ .Release.Namespace }} -l app.kubernetes.io/instance={{ .Release.Name }}

Access the pod you want to debug by executing

  kubectl exec --namespace {{ .Release.Namespace }} -ti <NAME OF THE POD> -- bash

In order to replicate the container startup scripts execute this command:

    /opt/bitnami/scripts/geode/entrypoint.sh /opt/bitnami/scripts/geode/run.sh

{{- else }}

{{- $replicaCount := int .Values.server.replicaCount }}
{{- $releaseNamespace := .Release.Namespace }}
{{- $clusterDomain := .Values.clusterDomain }}
{{- $fullname := include "common.names.fullname" . }}
{{- $locatorPort := int .Values.locator.service.ports.locator }}
{{- $serverPort := int .Values.server.service.ports.server }}

{{- if and (eq .Values.locator.service.type "LoadBalancer") (and (not .Values.auth.enabled) (not .Values.auth.tls.enabled)) }}
---------------------------------------------------------------------------------------------
 WARNING

    By specifying "locator.service.type=LoadBalancer" and not enabling Apache Geode
    security, you have most likely exposed the Apache Geode service externally without
    any authentication/authorization mechanism.

    For security reasons, we strongly suggest that you switch to "ClusterIP" or
    "NodePort". As alternative, you can also enable Apache Geode security.

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

{{- if .Values.auth.enabled }}

To obtain the credentials to access Apache Geode locators, run:

    export GEODE_SECURITY_USERNAME=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "geode.secretName" . }} -o jsonpath="{.data.username}" | base64 --decode)
    export GEODE_SECURITY_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ template "geode.secretName" . }} -o jsonpath="{.data.password}" | base64 --decode)

{{- end }}

Apache Geode locators can be accessed by clients via port {{ $locatorPort }} on the following DNS name from within your cluster:

    {{ printf "%s-locator.%s.svc.%s" $fullname $releaseNamespace $clusterDomain }}

Each Apache Geode Cache server can be accessed by clients via port {{ $serverPort }} on the following DNS name(s) from within your cluster:

{{- $servers := list }}
{{- range $e, $i := until $replicaCount }}
{{- $servers = append $servers (printf "%s-server-%d.%s-server-hl.%s.svc.%s" $fullname $i $fullname $releaseNamespace $clusterDomain) }}
{{- end }}
{{ join "\n" $servers | nindent 4 }}

To create a pod that you can use as a Apache Geode client run the following commands:

{{- if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }}
Note: Since NetworkPolicy is enabled, only pods with label "{{ template "common.names.fullname" . }}-client=true" will be able to connect to Apache Geode nodes.
{{- end }}

    kubectl run {{ $fullname }}-client --restart='Never' --image {{ include "geode.image" . }}{{ if .Values.auth.enabled }} --env GEODE_SECURITY_USERNAME=$GEODE_SECURITY_USERNAME --env GEODE_SECURITY_PASSWORD=$GEODE_SECURITY_PASSWORD{{ end }}{{ if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }} --labels='{{ template "common.names.fullname" . }}-client=true'{{ end }} --namespace {{ $releaseNamespace }} --command -- sleep infinity

Then, you can use it to interact with the Apache Geode cluster:

    kubectl exec --tty -i {{ $fullname }}-client --namespace {{ $releaseNamespace }} -- bash
    gfsh -e "connect --locator={{ printf "%s-locator.%s.svc.%s[%d]" $fullname $releaseNamespace $clusterDomain $locatorPort }}{{ if .Values.auth.enabled }} --user=$GEODE_SECURITY_USERNAME --password=$GEODE_SECURITY_PASSWORD{{ end }}" -e "list members"

To connect to your Apache Geode cluster from outside the cluster, perform the following steps:

{{- if .Values.ingress.enabled }}

To access the Locator multicast port:

{{- if contains "NodePort" .Values.locator.service.type }}

1. Obtain the NodePort IP and ports:

    export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
    export LOCATOR_NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ printf "%s-locator" (include "common.names.fullname" .) }})
    echo "Locator URL: ${NODE_IP}[${LOCATOR_NODE_PORT}]"

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

1. Obtain the LoadBalancer IP:

  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 {{ printf "%s-locator" (include "common.names.fullname" .) }}'

    export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ printf "%s-locator" (include "common.names.fullname" .) }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}")
    echo "Locator URL: ${SERVICE_IP}[{{ .Values.locator.service.ports.locator }}]"

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

1. Create a port-forward to the Locator multicast port:

    kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ printf "%s-locator" (include "common.names.fullname" .) }} {{ .Values.locator.service.ports.locator }}:{{ .Values.locator.service.ports.locator }} &
    echo "Locator URL: 127.0.0.1[{{ .Values.locator.service.ports.locator }}]"

{{- end }}

2. Access the Locator using using the obtained URL.

To Access the Pulse dashboard:

1. Get the Pulse dashboard 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
    echo "Pulse URL: http{{ if .Values.ingress.tls }}s{{ end }}://{{ .Values.ingress.hostname }}/pulse"
    echo "$CLUSTER_IP  {{ .Values.ingress.hostname }}" | sudo tee -a /etc/hosts

2. Open a browser and access the Pulse dashboard using the obtained URL.

{{- else }}
{{- if contains "NodePort" .Values.locator.service.type }}

1. Obtain the NodePort IP and ports:

    export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
    export LOCATOR_NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ printf "%s-locator" (include "common.names.fullname" .) }})
    export HTTP_NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[1].nodePort}" services {{ printf "%s-locator" (include "common.names.fullname" .) }})

2. Access the Locator and Pulse dashboard:

    echo "Locator URL: ${NODE_IP}[${LOCATOR_NODE_PORT}]"
    echo "Pulse URL: http://${NODE_IP}:${HTTP_NODE_PORT}/pulse"

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

1. Obtain the LoadBalancer IP:

  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 {{ printf "%s-locator" (include "common.names.fullname" .) }}'

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

2. Access the Locator and Pulse dashboard:

    echo "Locator URL: ${SERVICE_IP}[{{ .Values.locator.service.ports.locator }}]"
    echo "Pulse URL: http://${SERVICE_IP}:{{ .Values.locator.service.ports.http }}/pulse"

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

1.  Create a port-forward to the ports:

    kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ printf "%s-locator" (include "common.names.fullname" .) }} {{ .Values.locator.service.ports.locator }}:{{ .Values.locator.service.ports.locator }} &
    kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ printf "%s-locator" (include "common.names.fullname" .) }} {{ .Values.locator.service.ports.http }}:{{ .Values.locator.service.ports.http }} &

2. Access the Locator and Pulse dashboard:

    echo "Locator URL: 127.0.0.1[{{ .Values.locator.service.ports.locator }}]"
    echo "Pulse URL: http://127.0.0.1:{{ .Values.locator.service.ports.http }}/pulse"

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

{{- if .Values.metrics.enabled }}

You can access the Prometheus metrics following the steps below:

1. Get the Apache Geode Prometheus metrics URL by running:

    kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ printf "%s-metrics" (include "common.names.fullname" .) }} {{ .Values.metrics.service.port }}:{{ .Values.metrics.service.port }} &
    echo "Apache Geode Prometheus metrics URL: http://127.0.0.1:{{ .Values.metrics.service.port }}/"

2. Open a browser and access Apache Geode Prometheus metrics using the obtained URL.

{{- end }}

{{- end }}

{{- include "common.warnings.rollingTag" .Values.image }}
{{- include "common.warnings.rollingTag" .Values.metrics.image }}
{{- include "common.warnings.rollingTag" .Values.volumePermissions.image }}
{{- include "geode.validateValues" . }}
{{- if and .Values.auth.enabled (not .Values.auth.existingSecret) -}}
    {{- $passwordValidationErrors := list -}}
    {{- $secretName := include "geode.secretName" . -}}
    {{- $requiredUsername := dict "valueKey" "auth.username" "secret" $secretName "field" "username" "context" $ -}}
    {{- $requiredPassword := dict "valueKey" "auth.password" "secret" $secretName "field" "password" "context" $ -}}
    {{- $requiredUsernameError := include "common.validations.values.single.empty" $requiredUsername -}}
    {{- $requiredPasswordError := include "common.validations.values.single.empty" $requiredPassword -}}
    {{- $passwordValidationErrors = append $passwordValidationErrors $requiredUsernameError -}}
    {{- $passwordValidationErrors = append $passwordValidationErrors $requiredPasswordError -}}
    {{- include "common.errors.upgrade.passwords.empty" (dict "validationErrors" $passwordValidationErrors "context" $) -}}
{{- end }}
