apiVersion: apps/v1
kind: Deployment
metadata:
  name: cache-server
  labels:
    app: cache-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: cache-server
  template:
    metadata:
      labels:
        app: cache-server
    spec:
      containers:
      - name: server
        image: $(IMAGE_PREFIX)/cache-server:$(IMAGE_TAG)
        env:
          - name: DBCONFIG_DRIVER
            value: mysql
          - name: DBCONFIG_DB_NAME
            valueFrom:
              configMapKeyRef:
                name: mysql-configmap
                key: cache_db
          - name: DBCONFIG_HOST_NAME
            valueFrom:
              configMapKeyRef:
                name: mysql-configmap
                key: host
          - name: DBCONFIG_PORT
            valueFrom:
              configMapKeyRef:
                name: mysql-configmap
                key: port
          - name: DBCONFIG_USER
            valueFrom:
              secretKeyRef:
                name: mysql-secret
                key: username
          - name: DBCONFIG_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mysql-secret
                key: password
          - name: NAMESPACE_TO_WATCH
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
        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)",
              ]
        imagePullPolicy: Always
        ports:
        - containerPort: 8443
          name: webhook-api
        volumeMounts:
        - name: webhook-tls-certs
          mountPath: /etc/webhook/certs
          readOnly: true
      volumes:
      - name: webhook-tls-certs
        secret:
          secretName: webhook-server-tls
      serviceAccountName: kubeflow-pipelines-cache
