# Karpenter Controller - Base Values
# Install with: helm install karpenter oci://public.ecr.aws/karpenter/karpenter

# Service Account (IRSA)
serviceAccount:
  create: true
  name: karpenter
  annotations: {}
  # eks.amazonaws.com/role-arn: arn:aws:iam::ACCOUNT:role/cluster-karpenter-controller
  # Set via --set in justfile from terraform output

# Controller settings
replicas: 2

# Controller resources
resources:
  limits:
    cpu: 1000m
    memory: 1Gi
  requests:
    cpu: 500m
    memory: 512Mi

# Settings (set via --set in justfile from terraform outputs)
settings:
  clusterName: ""
  clusterEndpoint: ""
  interruptionQueue: ""
  # Accumulate pending pods into a single provisioning decision to reduce
  # node churn from back-to-back launches. Chart renders BATCH_MAX_DURATION
  # and BATCH_IDLE_DURATION from these keys AND also appends controller.env
  # to the same list, so setting them in both places produces duplicate
  # env entries that break `helm upgrade` strategic-merge patches.
  batchMaxDuration: 45s
  batchIdleDuration: 45s
  # Memory overhead subtracted from each instance type's advertised RAM during
  # scheduling simulation. The chart default (0.075) overshoots the real overhead
  # measured across this fleet (1.7-5.3%, worst case g6/L4 at 5.3%), modeling
  # large-memory nodes (g5/r7a .48xlarge) as too small for full-node runners and
  # provisioning zero capacity for them. 0.06 stays above the g6 worst case (never
  # overcommits) while leaving modeled headroom for full-node runners to fit.
  vmMemoryOverheadPercent: 0.06
  # Feature gates
  featureGates:
    spotToSpotConsolidation: true

# Controller configuration
controller:
  # Environment variables
  env:
    # Use global STS endpoint instead of regional (more reliable)
    - name: AWS_STS_REGIONAL_ENDPOINTS
      value: "legacy"
  # Metrics
  metrics:
    port: 8000
  # Health probes (increased timeouts for slow AWS API responses)
  healthProbe:
    port: 8081
  livenessProbe:
    initialDelaySeconds: 30
    periodSeconds: 10
    timeoutSeconds: 30
    failureThreshold: 3
  readinessProbe:
    initialDelaySeconds: 30
    periodSeconds: 10
    timeoutSeconds: 30
    failureThreshold: 3

# CRITICAL: Tolerations to run on base infrastructure nodes
# The base nodes are tainted with CriticalAddonsOnly=true:NoSchedule
tolerations:
  - key: CriticalAddonsOnly
    operator: Equal
    value: "true"
    effect: NoSchedule

# Affinity to prefer base nodes
affinity:
  nodeAffinity:
    preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100
        preference:
          matchExpressions:
            - key: role
              operator: In
              values:
                - base-infrastructure

# Pod disruption budget
# For staging: Allow aggressive node updates by permitting all pods to be disrupted
# Karpenter can reschedule quickly, so no need for conservative PDBs
podDisruptionBudget:
  enabled: true
  minAvailable: 0 # Allow all pods to be disrupted simultaneously

# Logging
logLevel: info
logEncoding: console
