apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: bestie
  name: bestie-app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: bestie
  strategy:
    #This means the Deployment will roll one pod at a time, while ensuring no 
    #pods are unavailable. So, for example, if there are ten pods, 
    #the Deployment will ensure at least ten pods are available at one time.
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels:
        app: bestie
    spec:
      initContainers:
      - name: check-db-ready
        image: postgres:9.6.5
        env:
        - name: DB_ADDR
          valueFrom: { secretKeyRef: { name: bestie-pgo-pguser-bestie-pgo, key: host } }
        command: ['sh', '-c',
          'until pg_isready -h $(DB_ADDR) -p 5432;
          do echo waiting for database; sleep 2; done;']
      containers:
      - image: quay.io/opdev/bestie:1.3
        name: bestie
        env:
        - name: GUNICORN_CMD_ARGS
          value: "--bind=0.0.0.0 --workers=3"
        - name: FLASK_APP
          value: app
        - name: FLASK_ENV
          value: development
          #todo fixme
        - name: SECRET_KEY
          value: lkasjdf09ajsdkfljalsiorj12n3490re9485309irefvn,u90818734902139489230
        - name: DB_ADDR
          valueFrom: { secretKeyRef: { name: bestie-pgo-pguser-bestie-pgo, key: host } }
        - name: DB_PORT
          valueFrom: { secretKeyRef: { name: bestie-pgo-pguser-bestie-pgo, key: port } }
        - name: DB_DATABASE
          valueFrom: { secretKeyRef: { name: bestie-pgo-pguser-bestie-pgo, key: dbname } }
        - name: DB_USER
          valueFrom: { secretKeyRef: { name: bestie-pgo-pguser-bestie-pgo, key: user } }
        - name: DB_PASSWORD
          valueFrom: { secretKeyRef: { name: bestie-pgo-pguser-bestie-pgo, key: password } }
        - name: DATABASE_URL
          value: postgresql://$(DB_USER):$(DB_PASSWORD)@$(DB_ADDR):$(DB_PORT)/$(DB_DATABASE)
        ports:
        - name: http
          containerPort: 8000
        readinessProbe:
          httpGet:
            path: /foster
            port: 8000
          initialDelaySeconds: 15
          timeoutSeconds: 1
          periodSeconds: 15
        livenessProbe:
          httpGet:
            path: /foster
            port: 8000
          initialDelaySeconds: 15
          timeoutSeconds: 1
          periodSeconds: 15
        resources:
          limits:
            cpu: 500m
          requests:
            cpu: 200m
