# services/maintenance/node-image-sweeper-daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: node-image-sweeper
  namespace: maintenance
spec:
  selector:
    matchLabels:
      app: node-image-sweeper
  updateStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 100%
  template:
    metadata:
      labels:
        app: node-image-sweeper
    spec:
      serviceAccountName: node-image-sweeper
      tolerations:
        - key: node-role.kubernetes.io/control-plane
          operator: Exists
          effect: NoSchedule
        - key: node-role.kubernetes.io/master
          operator: Exists
          effect: NoSchedule
        - key: veles.bstein.dev/simulation
          operator: Equal
          value: "true"
          effect: NoSchedule
        - key: cassandra.bstein.dev/simulation
          operator: Equal
          value: "true"
          effect: NoSchedule
      nodeSelector:
        kubernetes.io/os: linux
      containers:
        - name: node-image-sweeper
          image: python:3.12.9-alpine3.20
          command: ["/bin/sh", "/scripts/node_image_sweeper.sh"]
          env:
            - name: SWEEP_INTERVAL_SEC
              value: "7200"
            - name: HIGH_USAGE_PERCENT
              value: "70"
            - name: EMERGENCY_USAGE_PERCENT
              value: "80"
            - name: LOG_RETENTION_DAYS
              value: "7"
            - name: ORPHAN_POD_RETENTION_DAYS
              value: "3"
            - name: JOURNAL_MAX_SIZE
              value: "200M"
          securityContext:
            privileged: true
            runAsUser: 0
          resources:
            requests:
              cpu: 10m
              memory: 32Mi
            limits:
              cpu: 100m
              memory: 256Mi
          volumeMounts:
            - name: host-root
              mountPath: /host
            - name: script
              mountPath: /scripts
              readOnly: true
      volumes:
        - name: host-root
          hostPath:
            path: /
        - name: script
          configMap:
            name: node-image-sweeper-script
            defaultMode: 0555
