apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/component: search
    app.kubernetes.io/part-of: talkyard
    app.kubernetes.io/version: v0.2021.10-e846283fa
  name: search
  namespace: talkyard
spec:
  minReadySeconds: 10
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      name: search
  template:
    metadata:
      annotations:
        search-log4j2-properties-override-hash: 30daa6103e309fe599cd75569f9d1a3a
      labels:
        name: search
    spec:
      containers:
      - envFrom:
        - configMapRef:
            name: search-environment-vars
        image: debiki/talkyard-search:v0.2021.10-e846283fa
        imagePullPolicy: IfNotPresent
        name: search
        ports:
        - containerPort: 9300
          name: default
        readinessProbe:
          exec:
            command:
            - /bin/sh
            - -c
            - |
              #!/usr/bin/env bash -e
              # If the node is starting up wait for the cluster to be green
              # Once it has started only check that the node itself is responding
              START_FILE=/tmp/.es_start_file

              http () {
                  local path="${1}"
                  if [ -n "${ELASTIC_USERNAME}" ] && [ -n "${ELASTIC_PASSWORD}" ]; then
                  BASIC_AUTH="-u ${ELASTIC_USERNAME}:${ELASTIC_PASSWORD}"
                  else
                  BASIC_AUTH=''
                  fi
                  curl -XGET -s -k --fail ${BASIC_AUTH} http://127.0.0.1:9200${path}
              }

              if [ -f "${START_FILE}" ]; then
                  echo 'Elasticsearch is already running, lets check the node is healthy'
                  http "/"
              else
                  echo 'Waiting for elasticsearch cluster to become green'
                  if http "/_cluster/health?wait_for_status=green&timeout=1s" ; then
                      touch ${START_FILE}
                      exit 0
                  else
                      echo 'Cluster is not yet green'
                      exit 1
                  fi
              fi
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 3
          timeoutSeconds: 5
        volumeMounts:
        - mountPath: /usr/share/elasticsearch/config/log4j2.properties
          name: search-log4j2-properties-override
          subPath: log4j2.properties
      volumes:
      - configMap:
          name: search-log4j2-properties-override
        name: search-log4j2-properties-override
