# services/game-stream/wolf-statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: wolf
  namespace: game-stream
  labels:
    app: wolf
spec:
  serviceName: wolf
  replicas: 1
  selector:
    matchLabels:
      app: wolf
  template:
    metadata:
      labels:
        app: wolf
        atlas.bstein.dev/game-mode: wolf
      annotations:
        game-stream.bstein.dev/wolf-config-revision: "2026-07-13-meccha-chameleon"
    spec:
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      securityContext:
        fsGroup: 1000
      initContainers:
        - name: wolfmanager-data-permissions
          image: busybox:1.36
          command:
            - sh
            - -c
            - |
              mkdir -p /app/config /wolf-runtime /wolf-socket
              chown -R 1000:1000 /app/config
              chmod 0777 /wolf-runtime /wolf-socket
          volumeMounts:
            - name: wolfmanager-data
              mountPath: /app/config
            - name: wolf-runtime
              mountPath: /wolf-runtime
            - name: wolf-socket
              mountPath: /wolf-socket
        - name: wolf-config-ensure
          image: ghcr.io/games-on-whales/wolf:stable
          imagePullPolicy: IfNotPresent
          command: ["/usr/bin/python3", "/opt/wolf-config-ensure/wolf_config_ensure.py"]
          env:
            - name: WOLF_CFG_FILE
              value: /etc/wolf/cfg/config.toml
          volumeMounts:
            - name: wolf-state
              mountPath: /etc/wolf
            - name: wolf-config-ensure
              mountPath: /opt/wolf-config-ensure
              readOnly: true
      nodeSelector:
        kubernetes.io/hostname: titan-24
      tolerations:
        - key: nvidia.com/gpu
          operator: Exists
          effect: NoSchedule
      containers:
        - name: wolf
          image: ghcr.io/games-on-whales/wolf:stable
          imagePullPolicy: IfNotPresent
          env:
            - name: WOLF_LOG_LEVEL
              value: INFO
            - name: WOLF_DOCKER_SOCKET
              value: /var/run/docker.sock
            - name: WOLF_SOCKET_PATH
              value: /var/run/wolf/wolf.sock
            - name: XDG_RUNTIME_DIR
              value: /var/lib/wolf/runtime
            - name: NVIDIA_DRIVER_CAPABILITIES
              value: all
            - name: NVIDIA_VISIBLE_DEVICES
              value: all
            - name: NVIDIA_DRIVER_VOLUME_NAME
              value: nvidia-driver-vol
            - name: WOLF_STOP_CONTAINER_ON_EXIT
              value: "FALSE"
          securityContext:
            privileged: true
          resources:
            requests:
              cpu: "2"
              memory: 4Gi
            limits:
              cpu: "12"
              memory: 32Gi
          volumeMounts:
            - name: wolf-state
              mountPath: /etc/wolf
            - name: wolf-runtime
              mountPath: /var/lib/wolf/runtime
            - name: wolf-socket
              mountPath: /var/run/wolf
            - name: docker-socket
              mountPath: /var/run/docker.sock
            - name: dev
              mountPath: /dev
            - name: udev
              mountPath: /run/udev
            - name: nvidia-driver-volume
              mountPath: /usr/nvidia
        - name: wolf-api-proxy
          image: ghcr.io/games-on-whales/wolf:stable
          imagePullPolicy: IfNotPresent
          command: ["/usr/bin/python3", "/opt/wolf-api-proxy/wolf_api_proxy.py"]
          ports:
            - name: api-proxy
              containerPort: 8088
          env:
            - name: WOLF_SOCKET_PATH
              value: /var/run/wolf/wolf.sock
          resources:
            requests:
              cpu: 25m
              memory: 64Mi
            limits:
              cpu: 250m
              memory: 256Mi
          volumeMounts:
            - name: wolf-socket
              mountPath: /var/run/wolf
            - name: wolf-api-proxy
              mountPath: /opt/wolf-api-proxy
              readOnly: true
        - name: wolfmanager
          image: ghcr.io/games-on-whales/wolfmanager/wolfmanager:latest
          imagePullPolicy: IfNotPresent
          env:
            - name: NODE_ENV
              value: production
            - name: NEXTAUTH_URL
              value: https://wolf.bstein.dev
            - name: WOLF_SOCKET_PATH
              value: /var/run/wolf/wolf.sock
            - name: WOLF_DOCKER_SOCKET
              value: /var/run/docker.sock
            - name: HOSTNAME
              value: 0.0.0.0
            - name: PORT
              value: "3000"
            - name: SCHEDULED_TASK_ENABLED
              value: "true"
          ports:
            - name: wolfmanager
              containerPort: 3000
          readinessProbe:
            tcpSocket:
              port: 3000
            initialDelaySeconds: 10
            periodSeconds: 10
          livenessProbe:
            tcpSocket:
              port: 3000
            initialDelaySeconds: 30
            periodSeconds: 20
          resources:
            requests:
              cpu: 100m
              memory: 256Mi
            limits:
              cpu: "1"
              memory: 1Gi
          volumeMounts:
            - name: wolf-socket
              mountPath: /var/run/wolf
            - name: docker-socket
              mountPath: /var/run/docker.sock
            - name: wolfmanager-data
              mountPath: /app/config
      volumes:
        - name: wolf-state
          hostPath:
            path: /etc/wolf
            type: DirectoryOrCreate
        - name: wolf-runtime
          hostPath:
            path: /var/lib/wolf/runtime
            type: DirectoryOrCreate
        - name: wolf-socket
          hostPath:
            path: /var/run/wolf
            type: DirectoryOrCreate
        - name: wolf-api-proxy
          configMap:
            name: wolf-api-proxy
            defaultMode: 0555
        - name: wolf-config-ensure
          configMap:
            name: wolf-config-ensure
            defaultMode: 0555
        - name: wolfmanager-data
          hostPath:
            path: /etc/wolfmanager
            type: DirectoryOrCreate
        - name: docker-socket
          hostPath:
            path: /var/run/docker.sock
            type: Socket
        - name: dev
          hostPath:
            path: /dev
            type: Directory
        - name: udev
          hostPath:
            path: /run/udev
            type: Directory
        - name: nvidia-driver-volume
          hostPath:
            path: /var/lib/docker/volumes/nvidia-driver-vol/_data
            type: Directory
