apiVersion: apps/v1
kind: Deployment
metadata:
  name: node-compactor
  namespace: kube-system
  labels:
    app.kubernetes.io/name: node-compactor
    app.kubernetes.io/component: controller
spec:
  replicas: 1
  # Only one instance should run (leader election not implemented)
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/name: node-compactor
  template:
    metadata:
      labels:
        app.kubernetes.io/name: node-compactor
        app.kubernetes.io/component: controller
    spec:
      serviceAccountName: node-compactor
      # Allow enough time for SIGTERM handler to clean up taints and
      # reservation annotations across all managed nodes before SIGKILL.
      terminationGracePeriodSeconds: 120
      securityContext:
        seccompProfile:
          type: RuntimeDefault
      # Run on base infrastructure nodes
      tolerations:
        - key: CriticalAddonsOnly
          operator: Equal
          value: "true"
          effect: NoSchedule
      nodeSelector:
        role: base-infrastructure
      containers:
        - name: compactor
          image: NODE_COMPACTOR_IMAGE_PLACEHOLDER
          ports:
            - name: metrics
              containerPort: 8080
              protocol: TCP
          env:
            - name: COMPACTOR_INTERVAL
              value: "COMPACTOR_INTERVAL_PLACEHOLDER"
            - name: COMPACTOR_MAX_UPTIME_HOURS
              value: "COMPACTOR_MAX_UPTIME_HOURS_PLACEHOLDER"
            - name: COMPACTOR_DRY_RUN
              value: "COMPACTOR_DRY_RUN_PLACEHOLDER"
            - name: COMPACTOR_MIN_NODES
              value: "COMPACTOR_MIN_NODES_PLACEHOLDER"
            - name: COMPACTOR_MIN_NODE_AGE
              value: "COMPACTOR_MIN_NODE_AGE_PLACEHOLDER"
            - name: COMPACTOR_CAPACITY_RESERVATION_NODES
              value: "COMPACTOR_CAPACITY_RESERVATION_NODES_PLACEHOLDER"
          resources:
            requests:
              cpu: "2"
              memory: "4Gi"
            limits:
              cpu: "10"
              memory: "10Gi"
          livenessProbe:
            exec:
              command:
                - python
                - -c
                - "import os, time; assert time.time() - os.path.getmtime('/tmp/healthy') < 120"
            initialDelaySeconds: 30
            periodSeconds: 30
            failureThreshold: 3
          readinessProbe:
            exec:
              command:
                - python
                - -c
                - "import os, time; assert time.time() - os.path.getmtime('/tmp/healthy') < 120"
            initialDelaySeconds: 30
            periodSeconds: 30
          volumeMounts:
            - name: tmp
              mountPath: /tmp
          securityContext:
            readOnlyRootFilesystem: true
            runAsNonRoot: true
            runAsUser: 65534
            allowPrivilegeEscalation: false
            capabilities:
              drop: ["ALL"]
      volumes:
        - name: tmp
          emptyDir:
            sizeLimit: 1Mi
