architecture: replicaset
replicaCount: ${ replicas }

commonAnnotations:
  mongodb.com/timeouts: "true"

mongodb:
  extraFlags:
    - "--oplogSizeMB=10240"
    - "--setParameter=electionTimeoutMillis=10000"
    - "--setParameter=heartbeatIntervalMillis=2000"
    - "--setParameter=catchUpTimeoutMillis=30000"
    - "--setParameter=catchUpTakeoverDelayMillis=30000"

# More forgiving probe settings
readinessProbe:
  initialDelaySeconds: 30
  periodSeconds: 10
  timeoutSeconds: 15
  failureThreshold: 3
  successThreshold: 1

livenessProbe:
  initialDelaySeconds: 60
  periodSeconds: 20
  timeoutSeconds: 15
  failureThreshold: 6

# Proper shutdown handling
terminationGracePeriodSeconds: 300

# Ensure pods are distributed across nodes
affinity:
  podAntiAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchLabels:
            app.kubernetes.io/component: mongodb
        topologyKey: kubernetes.io/hostname

auth:
  enabled: true
  existingSecret: mongodb-auth

  %{ if length(usernames) > 0 }
  usernames:
  %{ for username in usernames ~}
  - ${ username }
  %{ endfor ~}
  %{ endif }

  %{ if length(databases) > 0 }
  databases:
  %{ for database in databases ~}
  - ${ database }
  %{ endfor ~}
  %{ endif }

resources:
  limits:
    cpu: 1000m
    memory: 1.5Gi
  requests:
    cpu: 500m
    memory: 1Gi
