# infrastructure/descheduler/helmrelease.yaml
apiVersion: helm.toolkit.fluxcd.io/v2
kind: HelmRelease
metadata:
  name: descheduler
  namespace: kube-system
spec:
  interval: 30m
  install:
    remediation:
      retries: 3
  upgrade:
    remediation:
      retries: 3
  chart:
    spec:
      chart: descheduler
      version: 0.33.0
      sourceRef:
        kind: HelmRepository
        name: descheduler
        namespace: flux-system
  values:
    kind: CronJob
    schedule: "*/20 * * * *"
    successfulJobsHistoryLimit: 1
    failedJobsHistoryLimit: 3
    resources:
      requests:
        cpu: 50m
        memory: 96Mi
      limits:
        cpu: 200m
        memory: 256Mi
    deschedulerPolicyAPIVersion: descheduler/v1alpha2
    deschedulerPolicy:
      maxNoOfPodsToEvictPerNode: 2
      maxNoOfPodsToEvictPerNamespace: 2
      profiles:
        - name: atlas-rpi-balance
          pluginConfig:
            - name: DefaultEvictor
              args:
                nodeFit: true
                minPodAge: 10m
                ignorePvcPods: true
                evictLocalStoragePods: false
            - name: RemovePodsHavingTooManyRestarts
              args:
                podRestartThreshold: 12
                includingInitContainers: true
            - name: RemovePodsViolatingNodeAffinity
              args:
                nodeAffinityType:
                  - requiredDuringSchedulingIgnoredDuringExecution
            - name: RemovePodsViolatingTopologySpreadConstraint
            - name: RemovePodsViolatingNodeTaints
            - name: LowNodeUtilization
              args:
                thresholds:
                  cpu: 45
                  memory: 45
                  pods: 45
                targetThresholds:
                  cpu: 75
                  memory: 75
                  pods: 75
          plugins:
            balance:
              enabled:
                - RemovePodsViolatingTopologySpreadConstraint
                - LowNodeUtilization
            deschedule:
              enabled:
                - RemovePodsHavingTooManyRestarts
                - RemovePodsViolatingNodeTaints
                - RemovePodsViolatingNodeAffinity
    priorityClassName: system-cluster-critical
    nodeSelector:
      node-role.kubernetes.io/control-plane: "true"
    affinity:
      nodeAffinity:
        preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            preference:
              matchExpressions:
                - key: kubernetes.io/hostname
                  operator: NotIn
                  values:
                    - titan-0a
    tolerations:
      - key: node-role.kubernetes.io/control-plane
        operator: Exists
        effect: NoSchedule
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
