apiVersion: apps/v1
kind: Deployment
metadata:
  name: mattermost-cloud
  namespace: mattermost-cloud
  labels:
    app.kubernetes.io/name: mattermost-cloud
    app.kubernetes.io/component: provisioner
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app.kubernetes.io/name: mattermost-cloud
      app.kubernetes.io/component: provisioner
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mattermost-cloud
        app.kubernetes.io/component: provisioner
    spec:
      initContainers:
      - name: init-database
        image: mattermost/mattermost-cloud:latest
        imagePullPolicy: Always
        args: ["schema", "migrate", "--database", "$(DATABASE)"]
        env:
        - name: DATABASE
          valueFrom:
            secretKeyRef:
              name: mattermost-cloud-secret
              key: DATABASE
      containers:
      - name: mattermost-cloud
        image: mattermost/mattermost-cloud:latest
        imagePullPolicy: Always
        terminationMessagePolicy: "FallbackToLogsOnError"
        args: ["server", "--debug", "--state-store", "mattermost-kops-state-test", "--database", "$(DATABASE)"]
        ports:
        - containerPort: 8075
          name: api
        resources:
          {}
        env:
        - name: AWS_SECRET_ACCESS_KEY
          valueFrom:
            secretKeyRef:
              name: mattermost-cloud-secret
              key: AWS_SECRET_ACCESS_KEY
        - name: AWS_ACCESS_KEY_ID
          valueFrom:
            secretKeyRef:
              name: mattermost-cloud-secret
              key: AWS_ACCESS_KEY_ID
        - name: AWS_DEFAULT_REGION
          valueFrom:
            secretKeyRef:
              name: mattermost-cloud-secret
              key: AWS_REGION
        - name: AWS_REGION
          valueFrom:
            secretKeyRef:
              name: mattermost-cloud-secret
              key: AWS_REGION
        - name: DATABASE
          valueFrom:
            secretKeyRef:
              name: mattermost-cloud-secret
              key: DATABASE
        volumeMounts:
        - name: mattermost-cloud-ssh-volume
          mountPath: /.ssh
        - name: mattermost-cloud-tmp-volume
          mountPath: /tmp
        - name: mattermost-cloud-helm-volume
          mountPath: /.helm
      volumes:
      - name: mattermost-cloud-ssh-volume
        secret:
          secretName: mattermost-cloud-ssh-secret
      - name: mattermost-cloud-tmp-volume
        emptyDir: {}
      - name: mattermost-cloud-helm-volume
        emptyDir: {}
