apiVersion: apps/v1
kind: Deployment
metadata:
  name: turbinia-worker
  labels:
    app: turbinia-worker
spec:
  replicas: 3
  selector:
    matchLabels:
      app: turbinia-worker
  template:
    metadata:
      annotations:
        prometheus.io/port: "9200"
        prometheus.io/scrape: "true"
      labels:
        app: turbinia-worker
    spec:
      # The grace period needs to be set to the largest task timeout as
      # set in the turbinia configuration file.
      terminationGracePeriodSeconds: 86400
      initContainers:
        - name: init-filestore
          image: busybox:1.28
          command: ['sh', '-c', 'chmod go+w /mnt/turbiniavolume']
          volumeMounts:
            - mountPath: "/mnt/turbiniavolume"
              name: turbiniavolume
      containers:
        - name: worker
          image: us-docker.pkg.dev/osdfir-registry/turbinia/release/turbinia-worker:latest
          lifecycle:
            preStop:
              exec:
                command:
                  - "/bin/sh"
                  - "-c"
                  - "touch /tmp/turbinia-to-scaledown.lock && sleep 5 && /usr/bin/python3 /home/turbinia/check-lockfile.py"
          securityContext:
            privileged: true
          env:
            - name: TURBINIA_CONF
              valueFrom:
                configMapKeyRef:
                  name: turbinia-config
                  key: TURBINIA_CONF
            - name: TURBINIA_EXTRA_ARGS
              value: "-d"
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          volumeMounts:
            - mountPath: "/dev"
              name: dev
              readOnly: true
            - mountPath: "/var/run/lock"
              name: lockfolder
              readOnly: false
            - mountPath: /mnt/turbiniavolume
              name: turbiniavolume
          ports:
            - containerPort: 9200
          resources: 
            requests:
              memory: "256Mi"
              cpu: "500m"
            limits:
              memory: "8192Mi"
              cpu: "32000m"
      volumes:
        - name: dev
          hostPath:
            path: /dev
        - name: lockfolder
          hostPath:
            path: /var/run/lock
        - name: turbiniavolume
          persistentVolumeClaim:
            claimName: turbiniavolume-claim
            readOnly: false
