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

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

The following elements have been deployed

{{- if .Values.auth.enabled }}
  - auth
{{- end }}
{{- if .Values.meta.enabled }}
  - meta
{{- end }}
{{- if .Values.realtime.enabled }}
  - realtime
{{- end }}
{{- if .Values.rest.enabled }}
  - rest
{{- end }}
{{- if .Values.storage.enabled }}
  - storage
{{- end }}
{{- if .Values.studio.enabled }}
  - studio
{{- end }}

{{- 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

{{- else }}

Supabase API can be accessed through the following DNS name from within your cluster:

    {{ include "supabase.kong.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }} (port {{ .Values.kong.service.ports.proxyHttp }})

To access the Supabase API from outside the cluster follow the steps below:

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

1. Get the Supabase API URL and associate the Supabase API hostname to your cluster external IP:

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

{{- else }}
{{- $port := .Values.kong.service.ports.proxyHttp | toString }}

1. Get the Supabase URL by running these commands:

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

   export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "supabase.kong.fullname" . }})
   export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
   echo "Supabase Studio URL: http://$NODE_IP:$NODE_PORT/"

{{- else if contains "LoadBalancer" .Values.kong.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 {{ include "supabase.kong.fullname" . }}'

   export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "supabase.kong.fullname" . }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}")
   echo "Supabase Studio URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ .Values.kong.service.ports.proxyHttp }}{{ end }}/"

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

   kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ include "supabase.kong.fullname" . }} {{ .Values.kong.service.ports.proxyHttp }}:{{ .Values.kong.service.ports.proxyHttp }} &
   echo "Supabase Studio URL: http://127.0.0.1{{- if ne $port "80" }}:{{ .Values.kong.service.ports.proxyHttp }}{{ end }}/"

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

2. Obtain the Supabase Service JWT Tokens:

  echo Anon JWT Token: $(kubectl get secret --namespace {{ .Release.Namespace }} {{ include "supabase.jwt.secretName" . }} -o jsonpath="{.data.anon-key}" | base64 -d)
  echo Service JWT Token: $(kubectl get secret --namespace {{ .Release.Namespace }} {{ include "supabase.jwt.secretName" . }} -o jsonpath="{.data.service-key}" | base64 -d)

3. Configure your application code to access the Supabase API.

{{- if .Values.studio.enabled }}

EXTRA: If you want to access Supabase Studio:

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

1. Get the Supabase Studio URL and associate Supabase hostname to your cluster external IP:

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

{{- else }}
{{- $port := .Values.studio.service.ports.http | toString }}

1. Get the Supabase URL by running these commands:

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

   export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "supabase.studio.fullname" . }})
   export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
   echo "Supabase Studio URL: http://$NODE_IP:$NODE_PORT/"

{{- else if contains "LoadBalancer" .Values.studio.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 {{ include "supabase.studio.fullname" . }}'

   export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "supabase.studio.fullname" . }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}")
   echo "Supabase Studio URL: http://$SERVICE_IP{{- if ne $port "80" }}:{{ .Values.studio.service.ports.http }}{{ end }}/"

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

   kubectl port-forward --namespace {{ .Release.Namespace }} svc/{{ include "supabase.studio.fullname" . }} {{ .Values.studio.service.ports.http }}:{{ .Values.studio.service.ports.http }} &
   echo "Supabase Studio URL: http://127.0.0.1{{- if ne $port "80" }}:{{ .Values.studio.service.ports.http }}{{ end }}/"

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

{{- if (or (not .Values.auth.enabled) (not .Values.meta.enabled) (not .Values.rest.enabled) (not .Values.realtime.enabled) (not .Values.storage.enabled))}}

WARNING: Some of the Supabase components are deactivated. This may cause issues in some of the Studio features.
{{- end }}

IMPORTANT: When accessing Studio via browser, it will try to access the API via {{ include "supabase.api.publicURL" . }}. Make sure that this address is accessible or update the release setting the `publicURL` value.

{{- end }}

{{- end }}

{{- include "supabase.validateValues" . }}
{{- include "common.warnings.rollingTag" .Values.auth.image }}
{{- include "common.warnings.rollingTag" .Values.meta.image }}
{{- include "common.warnings.rollingTag" .Values.rest.image }}
{{- include "common.warnings.rollingTag" .Values.storage.image }}
{{- include "common.warnings.rollingTag" .Values.realtime.image }}
{{- include "common.warnings.rollingTag" .Values.psqlImage }}
{{- include "common.warnings.rollingTag" .Values.studio.image }}
{{- include "common.warnings.rollingTag" .Values.jwt.autoGenerate.image }}
{{- include "common.warnings.rollingTag" .Values.jwt.autoGenerate.kubectlImage }}
{{- include "common.warnings.rollingTag" .Values.volumePermissions.image }}
{{- include "common.warnings.resources" (dict "sections" (list "auth" "jwt.autoGenerate" "meta" "realtime" "rest" "storage" "studio" "volumePermissions") "context" $) }}
