#  Copyright (C) 2021 Intel Corporation
#  SPDX-License-Identifier: BSD-3-Clause

---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: ta-rollback
  namespace: isecl
  labels:
    run-once-daemonset: ta-rollback
spec:
  selector:
    matchLabels:
      run-once-daemonset: ta-rollback
  template:
    metadata:
      labels:
        run-once-daemonset: ta-rollback
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
              - matchExpressions:
                  - key: node.type
                    operator: In
                    values:
                      - "TXT-ENABLED"
                      - "SUEFI-ENABLED"
      initContainers:
        - image: busybox:1.32
          imagePullPolicy: Always
          name: restore
          command: ["/bin/sh", "-c"]
          args:
            - >
              cp -r /tmp/trustagent_backup/* /opt/trustagent/
          volumeMounts:
            - name: ta-volume
              mountPath: /opt/trustagent
            - name: ta-backup-volume
              mountPath: /tmp/trustagent_backup
      containers:
        - name: pause
          image: gcr.io/google_containers/pause
      volumes:
        - name: ta-volume
          hostPath:
            path: /opt/trustagent
            type: Directory
        - name: ta-backup-volume
          hostPath:
            path: /tmp/trustagent_backup
            type: DirectoryOrCreate