apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "common.names.fullname" . }}-scripts
  namespace: {{ .Release.Namespace }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: server
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
data:
  kong-container-health.sh: |-
    #!/bin/bash

    set -o errexit
    set -o nounset
    set -o pipefail

    # Load libraries
    . /opt/bitnami/scripts/libos.sh
    . /opt/bitnami/scripts/libkong.sh

    # Load Kong environment variables
    . /opt/bitnami/scripts/kong-env.sh

    is_kong_running

  ingress-container-wait-for-kong.sh: |-
    #!/bin/bash

    echo "Waiting for the Kong container to be ready"
    if wait-for-port --timeout={{ .Values.ingressController.proxyReadyTimeout }} --host=127.0.0.1 --state=inuse {{ .Values.kong.containerPorts.proxyHttp }}; then
      echo "Kong container ready"
    else
      echo "Kong not ready after {{ .Values.ingressController.proxyReadyTimeout }} seconds"
      exit 1
    fi

  ingress-container-start.sh: |-
    #!/bin/bash

    . /health/ingress-container-wait-for-kong.sh

    kong-ingress-controller
