apiVersion: apps/v1
kind: Deployment
metadata:
  name: xcache-deployment
  labels:
    app: xcache
spec:
  replicas: 1
  selector:
    matchLabels:
      app: xcache
  template:
    metadata:
      labels:
        app: xcache
    spec:
      nodeSelector:
        xcache-capable: "true"

      tolerations:
      - key: "xcache"
        operator: "Equal"
        value: "true"
        effect: "PreferNoSchedule"

      volumes:
        - name: x509-data
          emptyDir:
            medium: Memory
            sizeLimit: "10Mi"
        - name: x509-certs-volume
          secret:
            secretName: xcache-cert-secret
            items:
              - key: userkey
                path: userkey.pem
                mode: 256
              - key: usercert
                path: usercert.pem
        - name: xcache-data-0
          hostPath:
            path: /scratch
        - name: xcache-meta
          hostPath:
            path: /scratch

      containers:
        - name: xcache
          image: slateci/xcache:latest
          env:
            - name: XC_SPACE_HIGH_WM
              value: "0.95"
            - name: XC_SPACE_LOW_WM
              value: "0.90"
            - name: XC_PORT
              value: "1094"
            - name: XC_RAMSIZE
              value: "16g"
            - name: XC_BLOCKSIZE
              value: "1M"
            - name: XC_PREFETCH
              value: "0"
            - name: AGIS_PROTOCOL_ID
              value: "433"
          volumeMounts:
            - name: x509-data
              mountPath: "/etc/grid-security/"
              readOnly: false
            - name: x509-certs-volume
              mountPath: "/etc/grid-certs/"
              readOnly: true
            - name: xcache-data-0
              mountPath: "/xcache-data_1"
            - name: xcache-meta
              mountPath: "/xcache-meta"
          livenessProbe:
            tcpSocket:
              port: 1094
            initialDelaySeconds: 180
            periodSeconds: 60
          lifecycle:
            preStop:
              exec:
                command: ["./updateAGISstatus.sh", "433", "DISABLED"]
          ports:
            - containerPort: 1094
          resources:
            requests:
              ephemeral-storage: "5Gi"
            limits:
              ephemeral-storage: "10Gi"

        - name: x509
          image: slateci/xcache:latest
          command: ["/run_x509_updater.sh"]
          volumeMounts:
            - name: x509-data
              mountPath: "/etc/grid-security/"
              readOnly: false
            - name: x509-certs-volume
              mountPath: "/etc/grid-certs/"
              readOnly: true

        - name: reporter
          image: slateci/xcache:latest
          command: ["/run_cache_reporter.sh"]
          env:
            - name: XC_SITE
              value: "MWT2"
            - name: XC_REPORT_COLLECTOR
              value: "http://uct2-collectd.mwt2.org:8080"
          volumeMounts:
            - name: xcache-meta
              mountPath: "/xcache-meta"
              readOnly: true
