apiVersion: apps/v1
kind: Deployment
metadata:
  name: s3-proxy
  namespace: django
  labels:
    app: s3-proxy

spec:
  replicas: 1

  selector:
    matchLabels:
      app: s3-proxy

  template:
    metadata:
      labels:
        app: s3-proxy
      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: django

        vault.hashicorp.com/agent-inject-secret-s3: secrets/data/minio/apps/django

        vault.hashicorp.com/agent-inject-template-s3: |
          {{- with secret "secrets/data/minio/apps/django" }}
          AWS_API_ENDPOINT=https://minio.contour.infra.sarex.tech
          {{- $buckets := index .Data.data "buckets" }}
          AWS_S3_BUCKET={{ if gt (len $buckets) 0 }}{{ index (index $buckets 0) "name" }}{{ else }}django{{ end }}
          AWS_ACCESS_KEY_ID={{ index .Data.data "access_key" }}
          AWS_SECRET_ACCESS_KEY={{ index .Data.data "secret_key" }}
          {{- end }}

    spec:
      serviceAccountName: django-vault

      containers:
        - name: s3-proxy
          image: cr.yandex/crp3ccidau046kdj8g9q/s3-proxy:vault_6e586217
          imagePullPolicy: Always

          command:
            - /bin/sh
            - -ec

          args:
            - |
              set -a
              [ -f /vault/secrets/s3 ] && . /vault/secrets/s3
              set +a

              exec /s3-proxy

          ports:
            - name: http
              containerPort: 80

          env:
            - name: ACCESS_LOG
              value: "true"

            - name: CORS_ALLOW_HEADERS
              value: "Content-Type, Accept-Ranges, Content-Range, Content-Encoding"