apiVersion: v1
kind: Template
metadata:
  name: apiomat-mongo
  annotations:
    tag: BaaS,Backend,Database
objects:
- apiVersion: v1
  kind: "PersistentVolumeClaim"
  metadata:
    name: "mongodb"
    labels:
      template: apiomat-mongo
  spec:
   accessModes:
     - "ReadWriteMany"
   resources:
     requests:
       storage: ${MONGODB_VOLUME_CAPACITY}
- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    name: ${MONGODB_SERVICE_NAME}
    labels:
      app: ${MONGODB_SERVICE_NAME}
      template: apiomat-mongo
  spec:
    strategy:
      type: Rolling
      rollingParams:
        updatePeriodSeconds: 1
        intervalSeconds: 1
        timeoutSeconds: 600
        maxUnavailable: 25%
        maxSurge: 25%
      resources: {  }
    triggers:
      -
        type: ConfigChange
    replicas: 1
    selector:
      deploymentconfig: ${MONGODB_SERVICE_NAME}
    template:
      metadata:
        labels:
          app: ${MONGODB_SERVICE_NAME}
          deploymentconfig: ${MONGODB_SERVICE_NAME}
      spec:
        volumes:
          - name: mongodb-data
            persistentVolumeClaim:
              claimName: mongodb
        containers:
          - name: mongodb
            image: ${MONGO_IMAGE}
            ports:
              - containerPort: 27017
                protocol: TCP
            env:
              - name: STORAGE_ENGINE
                value: 'mmapv1'
              - name: USE_SMALL_FILES
                value: 'true'
            resources:
              limits:
                memory: ${MONGODB_MEMORY_LIMIT}
            volumeMounts:
              - name: mongodb-data
                mountPath: /var/lib/mongodb/data
            livenessProbe:
              tcpSocket:
                port: 27017
              initialDelaySeconds: 30
              timeoutSeconds: 1
            readinessProbe:
              tcpSocket:
                port: 27017
              initialDelaySeconds: 15
              timeoutSeconds: 1
            terminationMessagePath: /dev/termination-log
            imagePullPolicy: Always
            securityContext:
              capabilities: {  }
              privileged: false
        restartPolicy: Always
        terminationGracePeriodSeconds: 30
        dnsPolicy: ClusterFirst
        securityContext: {  }
  status:
    latestVersion: 1
    details:
      causes:
        -
          type: ConfigChange
- apiVersion: v1
  kind: Service
  metadata:
    labels:
      template: apiomat-mongo
    name: ${MONGODB_SERVICE_NAME}
  spec:
    ports:
    - name: mongo
      port: 27017
      protocol: TCP
      targetPort: 27017
    selector:
      deploymentconfig: ${MONGODB_SERVICE_NAME}
    sessionAffinity: None
    type: ClusterIP
  status:
    loadBalancer: {}
parameters:
- name: MONGODB_SERVICE_NAME
  description: "MongoDB service name (for example: mongodb)"
  value: mongodb
- name: MONGODB_VOLUME_CAPACITY
  description: "Volume space available for data, e.g. 512Mi, 2Gi."
  value: 2Gi
- name: MONGODB_MEMORY_LIMIT
  description: "Memory limit of mongodb (min. 1Gi)"
  value: 2Gi
- name: MONGO_IMAGE
  description: "Url to the docker mongo image"
  value: docker.io/apiomat/mongo-conf:3.4