apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    k8s-app: cms-xcache
  name: cms-xcache-bcache-1-ucsd
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: cms-xcache
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 1
    type: RollingUpdate
  template:
    metadata:
      labels:
        k8s-app: cms-xcache
    spec:
      hostname: bcache-1
      tolerations:
      - effect: NoSchedule
        key: nautilus.io/stashcache
        operator: Exists
      initContainers:
      - command: ["sh", "-c", "chown -R 10940:10940 /xcache-root /xcache-meta /data*"]
        image: busybox
        imagePullPolicy: Always
        name: chowndata
        volumeMounts:
        - mountPath: /data1
          name: data1
        - mountPath: /data2
          name: data2
        - mountPath: /data3
          name: data3
        - mountPath: /data4
          name: data4
        - mountPath: /xcache-root
          name: localroot
        - mountPath: /xcache-meta
          name: localmeta
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: kubernetes.io/hostname
                operator: In
                values:
                - bcache-1.t2.ucsd.edu
      containers:
      - env:
        - name: XC_SITE
          value: UCSD-XCACHE
        - name: XC_RAMSIZE
          value: 25g
        - name: XC_RESOURCENAME
          value: UCSD-XCACHE
        - name: XC_SPACE_LOW_WM
          value: '0.96'
        - name: XC_SPACE_HIGH_WM
          value: '0.98'
        image: opensciencegrid/cms-xcache:fresh
        ports:
         - containerPort: 1094
           hostPort: 1094
         - containerPort: 1095
           hostPort: 1095
        imagePullPolicy: Always
        imagePullPolicy: Always
        name: cms-xcache-bcache-1-ucsd
        resources:
           limits:
              memory: 65Gi
              cpu: 25
           requests:
              memory: 56Gi
              cpu: 20
        volumeMounts:
        - mountPath: /etc/xrootd/config.d/90-node-disks.cfg
          name: config90
          subPath: 90-node-disks.cfg
        - mountPath: /etc/xrootd/config.d/95-local-ucsd.cfg
          name: config95
          subPath: 95-local-ucsd.cfg
        - mountPath: /etc/supervisord.d/10-cms-xcache.conf
          name: supervisor10
          subPath: 10-cms-xcache.conf 
        - mountPath: /etc/grid-security/hostcert.pem
          name: hostcert
          readOnly: true
          subPath: hostcert.pem
        - mountPath: /etc/grid-security/hostkey.pem
          name: hostkey
          readOnly: true
          subPath: hostkey.pem
        - mountPath: /data1
          name: data1
        - mountPath: /data2
          name: data2
        - mountPath: /data3
          name: data3
        - mountPath: /data4
          name: data4
        - mountPath: /xcache-root
          name: localroot
        - mountPath: /xcache-meta
          name: localmeta
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      terminationGracePeriodSeconds: 30
      volumes:
      - configMap:
          defaultMode: 420
          items:
          - key: 90-node-disks.cfg
            path: 90-node-disks.cfg
          name: cms-xcache-bcache-1-ucsd
        name: config90
      - configMap:
          defaultMode: 420
          items:
          - key: 95-local-ucsd.cfg
            path: 95-local-ucsd.cfg
          name: cms-xcache-bcache-1-ucsd
        name: config95
      - configMap:
          defaultMode: 420
          items:
          - key: Authfile-cms-xcache
            path: Authfile-cms-xcache
          name: cms-xcache-bcache-1-ucsd
        name: authfile
      - configMap:
          defaultMode: 420
          items:
          - key: 10-cms-xcache-ipv4-cmsd.conf
            path: 10-cms-xcache.conf
          name: cms-xcache-bcache-1-ucsd
        name: supervisor10
      - name: hostcert
        secret:
          secretName: bcache1-certs
          items:
          - key: hostcert
            path: hostcert.pem
          defaultMode: 0600
      - name: hostkey
        secret:
          secretName: bcache1-certs
          items:
          - key: hostkey
            path: hostkey.pem
          defaultMode: 0600
      - name: localroot
        persistentVolumeClaim:
          claimName: pvc-bcache-1-ucsd-root
      - name: localmeta
        persistentVolumeClaim:
          claimName: pvc-bcache-1-ucsd-meta
      - name: data1
        persistentVolumeClaim:
          claimName: pvc-bcache-1-ucsd-s1
      - name: data2
        persistentVolumeClaim:
          claimName: pvc-bcache-1-ucsd-s2
      - name: data3
        persistentVolumeClaim:
          claimName: pvc-bcache-1-ucsd-s3
      - name: data4
        persistentVolumeClaim:
          claimName: pvc-bcache-1-ucsd-s4
