---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: spot-termination-notice
spec:
  revisionHistoryLimit: 1
  selector:
    matchLabels:
      app: spot-termination-notice
  template:
    metadata:
      labels:
        app: spot-termination-notice
    spec:
      serviceAccountName: spot-termination-notice
      affinity:
        nodeAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
            - preference:
                matchExpressions:
                  - key: "kubernetes.io/arch"
                    operator: "In"
                    values:
                      - "amd64"
              weight: 1
      restartPolicy: Always
      terminationGracePeriodSeconds: 60
      containers:
      - name: spot-termination-notice
        image: docker.io/saidsef/k8s-spot-termination-notice:latest
        imagePullPolicy: Always
        env:
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: SPOT_POD_IP
          valueFrom:
            fieldRef:
              fieldPath: status.podIP
        - name: NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: SLACK_API_TOKEN
          valueFrom:
            secretKeyRef:
              name: slack
              key: SLACK_API_TOKEN
        - name: SLACK_CHANNEL
          valueFrom:
            secretKeyRef:
              name: slack
              key: SLACK_CHANNEL
        resources:
          requests:
            cpu: 30m
            memory: 50Mi
          limits:
            cpu: 50m
            memory: 100Mi
        livenessProbe:
          exec:
            command:
              - pgrep
              - python
          initialDelaySeconds: 5
          periodSeconds: 5
          failureThreshold: 3
          successThreshold: 1
          timeoutSeconds: 3
        securityContext:
          allowPrivilegeEscalation: false
          # user/group: nobody
          runAsGroup: 65534
          runAsUser: 65534
          runAsNonRoot: false
          readOnlyRootFilesystem: false
          capabilities:
            drop:
              - ALL
            add:
              - NET_BIND_SERVICE
              - SYS_TIME
