---
kind: Template
apiVersion: v1
metadata:
  name: heketi
  labels:
    glusterfs: heketi-template
    heketi: template
  annotations:
    description: Heketi service deployment template
    tags: glusterfs,heketi
objects:
- kind: Service
  apiVersion: v1
  metadata:
    name: heketi-${CLUSTER_NAME}
    labels:
      glusterfs: heketi-${CLUSTER_NAME}-service
      heketi: ${CLUSTER_NAME}-service
    annotations:
      description: Exposes Heketi service
  spec:
    ports:
    - name: heketi
      port: 8080
      targetPort: 8080
    selector:
      glusterfs: heketi-${CLUSTER_NAME}-pod
- kind: Route
  apiVersion: v1
  metadata:
    name: ${HEKETI_ROUTE}
    labels:
      glusterfs: heketi-${CLUSTER_NAME}-route
      heketi: ${CLUSTER_NAME}-route
  spec:
    to:
      kind: Service
      name: heketi-${CLUSTER_NAME}
- kind: DeploymentConfig
  apiVersion: v1
  metadata:
    name: heketi-${CLUSTER_NAME}
    labels:
      glusterfs: heketi-${CLUSTER_NAME}-dc
      heketi: ${CLUSTER_NAME}-dc
    annotations:
      description: Defines how to deploy Heketi
  spec:
    replicas: 1
    selector:
      glusterfs: heketi-${CLUSTER_NAME}-pod
    triggers:
    - type: ConfigChange
    strategy:
      type: Recreate
    template:
      metadata:
        name: heketi-${CLUSTER_NAME}
        labels:
          glusterfs: heketi-${CLUSTER_NAME}-pod
          heketi: ${CLUSTER_NAME}-pod
      spec:
        serviceAccountName: heketi-${CLUSTER_NAME}-service-account
        containers:
        - name: heketi
          image: ${IMAGE_NAME}
          imagePullPolicy: IfNotPresent
          env:
          - name: HEKETI_USER_KEY
            value: ${HEKETI_USER_KEY}
          - name: HEKETI_ADMIN_KEY
            value: ${HEKETI_ADMIN_KEY}
          - name: HEKETI_CLI_USER
            value: 'admin'
          - name: HEKETI_CLI_KEY
            value: ${HEKETI_ADMIN_KEY}
          - name: HEKETI_EXECUTOR
            value: ${HEKETI_EXECUTOR}
          - name: HEKETI_FSTAB
            value: ${HEKETI_FSTAB}
          - name: HEKETI_SNAPSHOT_LIMIT
            value: '14'
          - name: HEKETI_KUBE_GLUSTER_DAEMONSET
            value: '1'
          - name: HEKETI_IGNORE_STALE_OPERATIONS
            value: "true"
          - name: HEKETI_DEBUG_UMOUNT_FAILURES
            value: "true"
          - name: HEKETI_LVM_WRAPPER
            value: ${HEKETI_LVM_WRAPPER}
          ports:
          - containerPort: 8080
          volumeMounts:
          - name: db
            mountPath: /var/lib/heketi
          - name: config
            mountPath: /etc/heketi
          readinessProbe:
            timeoutSeconds: 3
            initialDelaySeconds: 3
            httpGet:
              path: /hello
              port: 8080
          livenessProbe:
            timeoutSeconds: 3
            initialDelaySeconds: 30
            httpGet:
              path: /hello
              port: 8080
        volumes:
        - name: db
          glusterfs:
            endpoints: heketi-db-${CLUSTER_NAME}-endpoints
            path: heketidbstorage
        - name: config
          secret:
            secretName: heketi-${CLUSTER_NAME}-config-secret
parameters:
- name: HEKETI_USER_KEY
  displayName: Heketi User Secret
  description: Set secret for those creating volumes as type _user_
- name: HEKETI_ADMIN_KEY
  displayName: Heketi Administrator Secret
  description: Set secret for administration of the Heketi service as user _admin_
- name: HEKETI_EXECUTOR
  displayName: heketi executor type
  description: Set the executor type, kubernetes or ssh
  value: kubernetes
- name: HEKETI_FSTAB
  displayName: heketi fstab path
  description: Set the fstab path, file that is populated with bricks that heketi creates
  value: /var/lib/heketi/fstab
- name: HEKETI_DEBUG_UMOUNT_FAILURES
  displayName: Capture more details in case brick unmounting fails
  description: When unmounting a brick fails, Heketi will not be able to cleanup the Gluster volume completely. The main causes for preventing to unmount a brick, seem to originate from Gluster processes. By enabling this option, the heketi.log will contain the output of 'lsof' to aid with debugging of the Gluster processes and help with identifying any files that may be left open.
- name: HEKETI_ROUTE
  displayName: heketi route name
  description: Set the hostname for the route URL
  value: "heketi-glusterfs"
- name: IMAGE_NAME
  displayName: heketi container image name
  required: True
- name: CLUSTER_NAME
  displayName: GlusterFS cluster name
  description: A unique name to identify this heketi service, useful for running multiple heketi instances
  value: glusterfs
- name: HEKETI_LVM_WRAPPER
  displayName: Wrapper for executing LVM commands
  description: Heketi can use a wrapper to execute LVM commands, i.e. run commands in the host namespace instead of in the Gluster container.
  value: "/usr/sbin/exec-on-host"
