# MongoDB StatefulSet for EDDI
# Provides persistent data storage with a headless service for DNS-based discovery.
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongodb
  labels:
    app.kubernetes.io/name: mongodb
    app.kubernetes.io/component: database
    app.kubernetes.io/part-of: eddi
spec:
  serviceName: mongodb
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: mongodb
      app.kubernetes.io/component: database
  template:
    metadata:
      labels:
        app.kubernetes.io/name: mongodb
        app.kubernetes.io/component: database
        app.kubernetes.io/part-of: eddi
    spec:
      securityContext:
        fsGroup: 999
      containers:
        - name: mongodb
          image: mongo:7.0
          ports:
            - containerPort: 27017
              name: mongo
          volumeMounts:
            - name: mongodb-data
              mountPath: /data/db
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: "1"
              memory: 1Gi
          livenessProbe:
            exec:
              command:
                - mongosh
                - --eval
                - "db.adminCommand('ping')"
            initialDelaySeconds: 15
            periodSeconds: 20
            timeoutSeconds: 5
          readinessProbe:
            exec:
              command:
                - mongosh
                - --eval
                - "db.adminCommand('ping')"
            initialDelaySeconds: 5
            periodSeconds: 10
            timeoutSeconds: 5
  volumeClaimTemplates:
    - metadata:
        name: mongodb-data
        labels:
          app.kubernetes.io/name: mongodb
          app.kubernetes.io/component: database
      spec:
        accessModes: ["ReadWriteOnce"]
        resources:
          requests:
            storage: 10Gi
        # Uncomment and set your storage class:
        # storageClassName: standard
