---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mayastor-init-scripts
  namespace: mayastor
data:
  initialize-pool.sh: |
    if [ -f /data/microk8s.img ]; then
      return 0
    fi

    # create image
    truncate -s 20G /data/microk8s.img

    # create mayastorpool
    export CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
    export TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
    export BODY='{
      "apiVersion": "openebs.io/v1alpha1",
      "kind":"MayastorPool",
      "metadata": {
        "name": "microk8s-'"$(hostname)"'-pool",
        "namespace": "mayastor"
      },
      "spec": {
        "node": "'"$(hostname)"'",
        "disks": ["/data/microk8s.img"]
      }
    }'
    echo 'Creating mayastor pool'
    curl --cacert "$CACERT" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -XPOST -d "$BODY" 'https://kubernetes.default/apis/openebs.io/v1alpha1/namespaces/mayastor/mayastorpools?fieldManager=kubectl-create'
