apiVersion: apps/v1
kind: Deployment
metadata:
  name: cache-server
spec:
  template:
    spec:
      containers:
      - name: server
        env:
          - $patch: replace
          - name: DEFAULT_CACHE_STALENESS
            valueFrom:
              configMapKeyRef:
                name: pipeline-install-config
                key: DEFAULT_CACHE_STALENESS
          - name: MAXIMUM_CACHE_STALENESS
            valueFrom:
              configMapKeyRef:
                name: pipeline-install-config
                key:  MAXIMUM_CACHE_STALENESS
          - name: CACHE_IMAGE
            valueFrom:
              configMapKeyRef:
                name: pipeline-install-config
                key: cacheImage
          - name: CACHE_NODE_RESTRICTIONS
            valueFrom:
              configMapKeyRef:
                name: pipeline-install-config
                key: cacheNodeRestrictions
          - name: DBCONFIG_DRIVER
            value: pgx
          - name: DBCONFIG_DB_NAME
            valueFrom:
              configMapKeyRef:
                name: pipeline-install-config
                key: cacheDb
          - name: DBCONFIG_HOST_NAME
            valueFrom:
              configMapKeyRef:
                name: pipeline-install-config
                key: postgresHost
          - name: DBCONFIG_PORT
            valueFrom:
              configMapKeyRef:
                name: pipeline-install-config
                key: postgresPort
          - name: DBCONFIG_USER
            valueFrom:
              secretKeyRef:
                name: postgres-secret-extended
                key: username
          - name: DBCONFIG_PASSWORD
            valueFrom:
              secretKeyRef:
                name: postgres-secret-extended
                key: password
          - name: NAMESPACE_TO_WATCH
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          # If you update WEBHOOK_PORT, also change the value of the
          # containerPort "webhook-api" to match.
          - name: WEBHOOK_PORT
            value: "8443"
        args: ["--db_driver=$(DBCONFIG_DRIVER)",
               "--db_host=$(DBCONFIG_HOST_NAME)",
               "--db_port=$(DBCONFIG_PORT)",
               "--db_name=$(DBCONFIG_DB_NAME)",
               "--db_user=$(DBCONFIG_USER)",
               "--db_password=$(DBCONFIG_PASSWORD)",
               "--namespace_to_watch=$(NAMESPACE_TO_WATCH)",
               "--listen_port=$(WEBHOOK_PORT)",
              ]
