# Seed job for PILOT2025 coupon - runs after tenant migration
apiVersion: batch/v1
kind: Job
metadata:
  name: tenant-seed-pilot-coupon
  namespace: bakery-ia
  labels:
    app.kubernetes.io/name: tenant-seed-pilot-coupon
    app.kubernetes.io/component: seed
    app.kubernetes.io/part-of: bakery-ia
spec:
  backoffLimit: 3
  template:
    metadata:
      labels:
        app.kubernetes.io/name: tenant-seed-pilot-coupon
        app.kubernetes.io/component: seed
    spec:
      serviceAccountName: demo-seed-sa
      initContainers:
      - name: wait-for-tenant-migration
        image: busybox:1.36
        command:
        - sh
        - -c
        - |
          echo "Waiting 30 seconds for tenant-migration to complete..."
          sleep 30
        resources:
          requests:
            memory: "64Mi"
            cpu: "50m"
          limits:
            memory: "128Mi"
            cpu: "100m"
      - name: wait-for-tenant-service
        image: curlimages/curl:latest
        command:
        - sh
        - -c
        - |
          echo "Waiting for tenant-service to be ready..."
          until curl -f http://tenant-service.bakery-ia.svc.cluster.local:8000/health/ready > /dev/null 2>&1; do
            echo "tenant-service not ready yet, waiting..."
            sleep 5
          done
          echo "tenant-service is ready!"
        resources:
          requests:
            memory: "64Mi"
            cpu: "50m"
          limits:
            memory: "128Mi"
            cpu: "100m"
      containers:
      - name: seed-coupon
        image: bakery/tenant-service:dev
        command: ["python", "/app/scripts/seed_pilot_coupon.py"]
        env:
        - name: TENANT_DATABASE_URL
          valueFrom:
            secretKeyRef:
              name: database-secrets
              key: TENANT_DATABASE_URL
        - name: LOG_LEVEL
          value: "INFO"
        resources:
          requests:
            memory: "256Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
      restartPolicy: OnFailure
