apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "airflow.fullname" . }}-git-clone
  labels:
    app: {{ template "airflow.name" . }}
    chart: {{ template "airflow.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  git-clone.sh: |
    #!/bin/sh -e
    REPO=$1
    REF=$2
    DIR=$3
    {{- if .Values.dags.git.secret }}
    mkdir -p ~/.ssh/
    cp -rL /keys/* ~/.ssh/
    chmod 600 ~/.ssh/*
    {{- end }}
    # Init Containers will re-run on Pod restart. Remove the directory's contents
    # and reprovision when this happens.
    if [ -d "$DIR" ]; then
        rm -rf $( find $DIR -mindepth 1 )
    fi
    git clone $REPO $DIR
    cd $DIR
    git reset --hard $REF
