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/influxdb/entrypoint.sh /opt/bitnami/scripts/influxdb/run.sh

{{- else }}

InfluxDB&trade; can be accessed through following DNS names from within your cluster:

    {{- if eq .Values.architecture "high-availability" }}
    InfluxDB Relay&trade; (write operations): {{ include "common.names.fullname" . }}-relay.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }} (port {{ coalesce .Values.relay.service.ports.http .Values.relay.service.port }})
    InfluxDB&trade; servers (read operations):  {{ include "common.names.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }} (port {{ coalesce .Values.influxdb.service.ports.http .Values.influxdb.service.port }})
    {{- else }}
    InfluxDB&trade;: {{ include "common.names.fullname" . }}.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }} (port {{ coalesce .Values.influxdb.service.ports.http .Values.influxdb.service.port }})
    {{- end }}
    {{- if .Values.metrics.enabled }}
    InfluxDB&trade; Prometheus Metrics: {{ include "common.names.fullname" . }}-metrics.{{ .Release.Namespace }}.svc.{{ .Values.clusterDomain }} (port {{ .Values.metrics.service.port }})
    {{- end }}

{{- if .Values.authEnabled }}

To get the password for the {{ .Values.auth.admin.username }} user, run:

    export ADMIN_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ include "influxdb.secretName" . }} -o jsonpath="{.data.admin-user-password}" | base64 --decode)

{{- if .Values.auth.user.username }}

To get the password for the {{ .Values.auth.user.username }} user, run:

    export USER_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ include "influxdb.secretName" . }} -o jsonpath="{.data.user-password}" | base64 --decode)

{{- end }}
{{- if .Values.readUser.name }}

To get the password for the {{ .Values.readUser.name }} user, run:

    export READ_USER_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ include "influxdb.secretName" . }} -o jsonpath="{.data.read-user-password}" | base64 --decode)

{{- end }}
{{- if .Values.writeUser.name }}

To get the password for the {{ .Values.writeUser.name }} user, run:

    export WRITE_USER_PASSWORD=$(kubectl get secret --namespace {{ .Release.Namespace }} {{ include "influxdb.secretName" . }} -o jsonpath="{.data.write-user-password}" | base64 --decode)

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

To connect to your database run the following commands:

    {{- if eq .Values.architecture "high-availability" }}

    (write operations):

    kubectl run {{ include "common.names.fullname" . }}-client --rm --tty -i --restart='Never' --namespace {{ .Release.Namespace }} {{ if .Values.authEnabled }}--env="INFLUX_USERNAME={{ .Values.auth.admin.username }}" --env="INFLUX_PASSWORD=$ADMIN_PASSWORD"{{ end }} \
        {{ if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }}--labels="{{ include "common.names.fullname" . }}-client=true" {{ end }}--image {{ include "influxdb.image" . }} \
        --command -- influx -host {{ include "common.names.fullname" . }}-relay -port {{ coalesce .Values.relay.service.ports.http .Values.relay.service.port }}

    (read operations):

    {{- end }}

    kubectl run {{ include "common.names.fullname" . }}-client --rm --tty -i --restart='Never' --namespace {{ .Release.Namespace }} {{ if .Values.authEnabled }}--env="INFLUX_USERNAME={{ .Values.auth.admin.username }}" --env="INFLUX_PASSWORD=$ADMIN_PASSWORD"{{ end }} \
        {{ if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }}--labels="{{ include "common.names.fullname" . }}-client=true" {{ end }}--image {{ include "influxdb.image" . }} \
        --command -- influx -host {{ include "common.names.fullname" . }} -port {{ coalesce .Values.influxdb.service.ports.http .Values.influxdb.service.port }}

{{- if and (.Values.networkPolicy.enabled) (not .Values.networkPolicy.allowExternal) }}

Note: Since NetworkPolicy is enabled, only pods with label "{{ include "common.names.fullname" . }}-client=true" will be able to connect to InfluxDB&trade; server(s).

{{- end }}

To connect to your database from outside the cluster execute the following commands:

{{- if .Values.ingress.enabled }}
{{- $ingressHost := .Values.ingress.hostname }}
  {{- if .Values.ingress.extraHosts }}
  You should be able to access your new InfluxDB&trade; server(s) through:
  {{- end }}
    {{- range .Values.ingress.extraHosts }}
    {{ if .tls }}https{{- else }}http{{ end }}://{{ .name }}
    {{- end }}

  e.g.:

    {{ if .Values.authEnabled }}INFLUX_USERNAME="{{ .Values.auth.admin.username }}" INFLUX_PASSWORD="$ADMIN_PASSWORD"{{ end }} influx -host {{ $ingressHost }} -port 80

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

  {{- if eq .Values.architecture "high-availability" }}

  (write operations):

    export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "common.names.fullname" . }}-relay)
    export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
    {{- if .Values.authEnabled }}INFLUX_USERNAME="{{ .Values.auth.admin.username }}" INFLUX_PASSWORD="$ADMIN_PASSWORD"{{- end }} influx -host $NODE_IP -port $NODE_PORT

  (read operations):

    {{- end }}

    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}")
    {{- if .Values.authEnabled }}INFLUX_USERNAME="{{ .Values.auth.admin.username }}" INFLUX_PASSWORD="$ADMIN_PASSWORD"{{- end }} influx -host $NODE_IP -port $NODE_PORT

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

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

  {{- if eq .Values.architecture "high-availability" }}

  (write operations):

    export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "common.names.fullname" . }}-relay -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    {{- if .Values.authEnabled }}INFLUX_USERNAME="{{ .Values.auth.admin.username }}" INFLUX_PASSWORD="$ADMIN_PASSWORD"{{- end }} influx -host $SERVICE_IP -port {{ coalesce .Values.relay.service.ports.http .Values.relay.service.port }}

  (read operations):

  {{- end }}

    export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "common.names.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
    {{- if .Values.authEnabled }}INFLUX_USERNAME="{{ .Values.auth.admin.username }}" INFLUX_PASSWORD="$ADMIN_PASSWORD"{{- end }} influx -host $SERVICE_IP -port {{ coalesce .Values.influxdb.service.ports.http .Values.influxdb.service.port }}

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

  {{- if eq .Values.architecture "high-availability" }}

  (write operations):

    kubectl port-forward svc/{{ include "common.names.fullname" . }}-relay 9096:{{ coalesce .Values.relay.service.ports.http .Values.relay.service.port }} &
    {{- if .Values.authEnabled }}INFLUX_USERNAME="{{ .Values.auth.admin.username }}" INFLUX_PASSWORD="$ADMIN_PASSWORD"{{- end }} influx -host 127.0.0.1 -port 9096

  (read operations):

  {{- end }}

    kubectl port-forward svc/{{ include "common.names.fullname" . }} 8086:{{ coalesce .Values.influxdb.service.ports.http .Values.influxdb.service.port }} &
    {{- if .Values.authEnabled }}INFLUX_USERNAME="{{ .Values.auth.admin.username }}" INFLUX_PASSWORD="$ADMIN_PASSWORD"{{- end }} influx -host 127.0.0.1 -port 8086

{{- end }}

{{- if and (eq .Values.architecture "high-availability") (not .Values.influxdb.service.sessionAffinity) (not .Values.ingress.enabled) }}

NOTE: When using "high-availability" it is recommended to configure 'influxdb.service.sessionAffinity' to prevent client connections from switching pods when connecting to InfluxDB UI.
{{- end }}

{{- include "influxdb.validateValues" . }}

{{- include "common.warnings.rollingTag" .Values.image }}
{{- include "common.warnings.rollingTag" .Values.relay.image  }}
{{- include "common.warnings.rollingTag" .Values.backup.uploadProviders.google.image }}
{{- include "common.warnings.rollingTag" .Values.backup.uploadProviders.azure.image }}
{{- include "common.warnings.rollingTag" .Values.volumePermissions.image }}

{{- $passwordValueConfigs := list -}}
{{- if not .Values.auth.existingSecret -}}
    {{- $secretName := include "influxdb.secretName" . -}}

    {{- $adminPasswordConfig := dict "valueKey" "auth.admin.password" "secret" $secretName "field" "admin-user-password" "context" $ -}}
    {{- $passwordValueConfigs = append $passwordValueConfigs $adminPasswordConfig -}}
    {{- $adminTokenConfig := dict "valueKey" "auth.admin.token" "secret" $secretName "field" "admin-user-token" "context" $ -}}
    {{- $passwordValueConfigs = append $passwordValueConfigs $adminTokenConfig -}}

    {{- if .Values.auth.user.username }}
      {{- $userPasswordConfig := dict "valueKey" "auth.user.password" "secret" $secretName "field" "user-password" "context" $ -}}
      {{- $passwordValueConfigs = append $passwordValueConfigs $userPasswordConfig -}}
    {{- end }}
    {{- if .Values.auth.readUser.username }}
      {{- $readUserPasswordConfig := dict "valueKey" "auth.readUser.password" "secret" $secretName "field" "read-user-password" "context" $ -}}
      {{- $passwordValueConfigs = append $passwordValueConfigs $readUserPasswordConfig -}}
    {{- end }}
    {{- if .Values.auth.writeUser.username }}
      {{- $writeUserPasswordConfig := dict "valueKey" "auth.writeUser.password" "secret" $secretName "field" "write-user-password" "context" $ -}}
      {{- $passwordValueConfigs = append $passwordValueConfigs $writeUserPasswordConfig -}}
    {{- end }}
{{- end -}}

{{- $passwordValidationErrors := include "common.validations.values.multiple.empty" (dict "required" $passwordValueConfigs "context" $) -}}
{{- include "common.errors.upgrade.passwords.empty" (dict "validationErrors" $passwordValidationErrors "context" $) -}}

{{- end }}
