{{- if .Values.sysctlImage.enabled }}
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "elasticsearch.fullname" . }}-initcontainer
  labels: {{- include "elasticsearch.labels" . | nindent 4 }}
data:
  sysctl.sh: |-
    #!/bin/bash
    
    set -o errexit
    set -o pipefail
    set -o nounset

    if ! [ -x "$(command -v sysctl)" ]; then
      echo 'sysctl not installed. Installing it...'
      distro=$(awk -F= '/^ID=/{print $2}' /etc/os-release | tr -d '"')
      case $distro in
        ol | centos)
          yum install -y procps
          rm -rf /var/cache/yum;;
        ubuntu | debian)
          apt-get update -qq && apt-get install -y --no-install-recommends procps
          rm -rf /var/lib/apt/lists /var/cache/apt/archives;;
      esac
    fi
    sysctl -w vm.max_map_count=262144 && sysctl -w fs.file-max=65536
{{- end }}
