# =============================================================================
# WOOO TECH - Momo Pro System
# Scheduler Deployment (爬蟲 + 自動匯入)
# =============================================================================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: momo-scheduler
  namespace: momo
  labels:
    app: momo-scheduler
spec:
  replicas: 1
  selector:
    matchLabels:
      app: momo-scheduler
  template:
    metadata:
      labels:
        app: momo-scheduler
    spec:
      initContainers:
        - name: copy-google-credentials
          image: busybox:1.36
          command: ['sh', '-c', 'cp /secrets/* /config/ && chmod 644 /config/*']
          volumeMounts:
            - name: google-drive-secrets
              mountPath: /secrets
              readOnly: true
            - name: google-drive-config
              mountPath: /config
      containers:
        - name: scheduler
          image: registry.wooo.work/wooo/momo-pro-system:latest
          imagePullPolicy: Always
          command: ["python", "run_scheduler.py"]
          envFrom:
            - configMapRef:
                name: momo-config
          env:
            - name: SECRET_KEY
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: SECRET_KEY
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: DATABASE_URL
            - name: TELEGRAM_BOT_TOKEN
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: TELEGRAM_BOT_TOKEN
            - name: LINE_CHANNEL_ACCESS_TOKEN
              valueFrom:
                secretKeyRef:
                  name: momo-secrets
                  key: LINE_CHANNEL_ACCESS_TOKEN
            - name: DISABLE_AUTO_IMPORT
              value: "false"
          volumeMounts:
            - name: momo-data
              mountPath: /app/data
            - name: momo-logs
              mountPath: /app/logs
            - name: google-drive-config
              mountPath: /app/config
          resources:
            requests:
              memory: "256Mi"
              cpu: "100m"
            limits:
              memory: "2Gi"
              cpu: "1000m"
      volumes:
        - name: momo-data
          persistentVolumeClaim:
            claimName: momo-data-pvc
        - name: momo-logs
          emptyDir: {}
        - name: google-drive-secrets
          secret:
            secretName: google-drive-credentials
        - name: google-drive-config
          emptyDir: {}
      imagePullSecrets:
        - name: registry-secret
