apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: playwright
  namespace: rdev
  labels:
    app.kubernetes.io/name: playwright
    app.kubernetes.io/part-of: rdev
spec:
  serviceName: playwright
  replicas: 1
  selector:
    matchLabels:
      app: playwright
  template:
    metadata:
      labels:
        app: playwright
        app.kubernetes.io/name: playwright
        app.kubernetes.io/part-of: rdev
        rdev.orchard9.ai/role: playwright
    spec:
      containers:
        - name: playwright
          image: mcr.microsoft.com/playwright:v1.50.0-noble
          imagePullPolicy: IfNotPresent
          command: ["sleep", "infinity"]

          resources:
            requests:
              cpu: "500m"
              memory: "1Gi"
            limits:
              cpu: "2"
              memory: "4Gi"

          volumeMounts:
            # Captures directory for screenshots and videos
            - name: captures
              mountPath: /captures

            # Scripts ConfigMap mounted as scripts directory
            - name: scripts
              mountPath: /scripts

          # Simple liveness check - container is running
          livenessProbe:
            exec:
              command:
                - test
                - -f
                - /scripts/capture.js
            initialDelaySeconds: 5
            periodSeconds: 60

          # Readiness - node and playwright are available
          readinessProbe:
            exec:
              command:
                - node
                - --version
            initialDelaySeconds: 10
            periodSeconds: 30
            timeoutSeconds: 10

      volumes:
        - name: captures
          emptyDir: {}

        - name: scripts
          configMap:
            name: playwright-scripts
            defaultMode: 0755
---
# Headless service for StatefulSet
apiVersion: v1
kind: Service
metadata:
  name: playwright
  namespace: rdev
  labels:
    app.kubernetes.io/name: playwright
    app.kubernetes.io/part-of: rdev
spec:
  clusterIP: None
  selector:
    app: playwright
  ports:
    - port: 9323
      name: debug
