apiVersion: apps/v1
kind: Deployment
metadata:
  name: central
  namespace: {{ .Values.namespace }}
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: central-server
  strategy:
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: central-server
    spec:
      containers:
        - env:
            - name: GCP_WORKLOAD_IDENTITY_AUDIENCE
              value: {{ .Values.cloud.gcp.gcpWorkloadIdentityAudience }}
            - name: GCP_IMPERSONATE_SA
              value: {{ .Values.cloud.gcp.gcpCentralSa }}
          image: {{ .Values.image.centralImage }}
          imagePullPolicy: IfNotPresent
          name: central
          readinessProbe:
            failureThreshold: 10
            httpGet:
              path: /healthz
              port: 11000
              scheme: HTTP
            initialDelaySeconds: 5
            periodSeconds: 5
            successThreshold: 1
            timeoutSeconds: 1
          resources:
            requests:
              cpu: {{ .Values.resources.central.cpu }}
              memory: {{ .Values.resources.central.cpu }}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /etc/dbaas
              name: dbaas-central-config
              readOnly: true
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      serviceAccountName: central
      terminationGracePeriodSeconds: 30
      volumes:
        - configMap:
            defaultMode: 420
            name: central-conf
          name: dbaas-central-config

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: billing
  namespace: {{ .Values.namespace }}
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: billing
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: billing
    spec:
      containers:
        - env:
            - name: STRIPE-SECRET-KEY
              valueFrom:
                secretKeyRef:
                  key: stripe-secret-key
                  name: billing
            - name: STRIPE-PUBLIC-KEY
              valueFrom:
                secretKeyRef:
                  key: stripe-public-key
                  name: billing
            - name: AUTH0-DOMAIN
              value: {{ .Values.cloud.Auth0.auth0Domain }}
            - name: AUTH0-AUDIENCE
              value: {{ .Values.cloud.BillingM2M.billingM2MAudience }}
            - name: DBAAS-CENTRAL-AUTH0-CLIENT-ID
              value: {{ .Values.cloud.ManagementPortal.managementPortalM2MServiceClientID }}
            - name: DBAAS-CENTRAL-AUTH0-CLIENT-SECRET
              value: {{ .Values.cloud.ManagementPortal.managementPortalM2MServiceClientSecret }}
            - name: DBAAS-CENTRAL-AUTH0-CLIENT-AUDIENCE
              value: {{ .Values.cloud.ManagementPortal.managementPortalAuth0ClientAudience }}
            - name: DBAAS-CENTRAL-AUTH0-DOMAIN
              value: {{ .Values.cloud.ManagementPortal.managementPortalAuth0Domain }}
            - name: GCP_WORKLOAD_IDENTITY_AUDIENCE
              value: {{ .Values.cloud.gcp.gcpWorkloadIdentityAudience }}
            - name: GCP_IMPERSONATE_SA
              value: {{ .Values.cloud.gcp.gcpBillingSa }}
          image: {{ .Values.image.billingImage }}
          imagePullPolicy: IfNotPresent
          name: billing
          resources:
            requests:
              cpu: {{ .Values.resources.billing.cpu }}
              memory: {{ .Values.resources.billing.cpu }}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /etc/db
              name: mysql-password
              readOnly: true
            - mountPath: /etc/billing
              name: dbaas-billing-config
              readOnly: true
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccountName: billing
      terminationGracePeriodSeconds: 30
      volumes:
        - name: mysql-password
          secret:
            defaultMode: 420
            secretName: billing-db-secret
        - configMap:
            name: billing
          name: dbaas-billing-config
