---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: worker
  namespace: system-log
  labels:
    app: worker
    service: worker
spec:
  replicas: 1
  selector:
    matchLabels:
      app: worker
  template:
    metadata:
      labels:
        app: worker
        service: worker
      annotations:
        traffic.sidecar.istio.io/excludeOutboundPorts: "8200"
        vault.hashicorp.com/agent-init-first: "true"
        vault.hashicorp.com/agent-inject: "true"
        vault.hashicorp.com/agent-pre-populate-only: "true"
        vault.hashicorp.com/auth-path: auth/kubernetes
        vault.hashicorp.com/role: system-log
        vault.hashicorp.com/agent-inject-secret-system-log-postgresql: secrets/data/postgresql/apps/system-log
        vault.hashicorp.com/agent-inject-template-system-log-postgresql: |-
          {{- with secret "secrets/data/postgresql/apps/system-log" -}}
          POSTGRES_ADDRESS=postgresql.system-log.svc.cluster.local
          POSTGRES_PORT=5432
          POSTGRES_DB=system_log_db
          POSTGRES_USER={{ index .Data.data "username" }}
          POSTGRES_PASSWORD={{ index .Data.data "password" }}
          {{- end -}}
        vault.hashicorp.com/agent-inject-secret-system-log-django-auth: secrets/data/vault/common/django_auth
        vault.hashicorp.com/agent-inject-template-system-log-django-auth: |-
          {{- with secret "secrets/data/vault/common/django_auth" -}}
          SUPER_USERNAME={{ index .Data.data "username" }}
          SUPER_PASSWORD={{ index .Data.data "password" }}
          {{- end -}}
    spec:
      serviceAccountName: system-log-vault
      containers:
        - name: worker
          image: cr.yandex/crp3ccidau046kdj8g9q/system-log-worker_prod:075fc0
          imagePullPolicy: IfNotPresent
          command: ["/bin/bash", "-ec"]
          args:
            - |
              set -a
              [ -f /vault/secrets/system-log-postgresql ] && . /vault/secrets/system-log-postgresql
              [ -f /vault/secrets/system-log-django-auth ] && . /vault/secrets/system-log-django-auth
              set +a
              exec /app
          ports:
            - name: http
              containerPort: 8000
              protocol: TCP
          env:
            - name: APP_NAME
              value: system_log
            - name: APP_VERSION
              value: 0.0.1
            - name: LOG_LEVEL
              value: INFO
            - name: HTTP_HOST
              value: 0.0.0.0
            - name: HTTP_PORT
              value: "8000"
            - name: NAMESPACE
              value: sarex-system-log
            - name: DOCUMENTATIONS_URL
              value: http://documentations-api.documentations.svc.cluster.local:8080
            - name: POSTGRES_POOL_SIZE
              value: "3"
            - name: ENABLE_SSL
              value: "0"
            - name: DJANGO_HOST
              value: http://backend.django.svc.cluster.local:8000

          resources:
            requests:
              cpu: "25m"
              memory: 128Mi
      imagePullSecrets:
        - name: regcred
