# services/veles/generator-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: veles-generator-worker
  namespace: veles
  labels:
    app: veles-generator-worker
spec:
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: veles-generator-worker
  template:
    metadata:
      labels:
        app: veles-generator-worker
      annotations:
        veles.bstein.dev/redeploy: "2026-07-24-0.7.65-hygiene-generator-worker"
        vault.hashicorp.com/agent-inject: "true"
        vault.hashicorp.com/agent-init-first: "true"
        vault.hashicorp.com/agent-pre-populate-only: "true"
        vault.hashicorp.com/role: "veles"
        vault.hashicorp.com/agent-inject-secret-veles-env.sh: "kv/data/atlas/veles/veles-db"
        vault.hashicorp.com/agent-inject-template-veles-env.sh: |
          {{- with secret "kv/data/atlas/veles/veles-db" }}
          unset DATABASE_URL
          export VELES_DATABASE_HOST="{{ .Data.data.POSTGRES_HOST }}"
          export VELES_DATABASE_PORT="{{ .Data.data.POSTGRES_PORT }}"
          export VELES_DATABASE_NAME="{{ .Data.data.POSTGRES_DB }}"
          export VELES_DATABASE_USER="{{ .Data.data.POSTGRES_USER }}"
          export VELES_DATABASE_PASSWORD="{{ .Data.data.POSTGRES_PASSWORD }}"
          export VELES_DATABASE_SSLMODE="disable"
          {{- end }}
          {{- with secret "kv/data/atlas/veles/app-secrets" }}
          export VELES_SESSION_SECRET="{{ .Data.data.VELES_SESSION_SECRET }}"
          export VELES_BYOK_ENCRYPTION_KEY="{{ .Data.data.VELES_BYOK_ENCRYPTION_KEY }}"
          {{- end }}
    spec:
      serviceAccountName: veles-generator
      priorityClassName: veles-core
      nodeSelector:
        veles.bstein.dev/node-pool: oceanus
        kubernetes.io/arch: amd64
      tolerations:
        - key: veles.bstein.dev/simulation
          operator: Equal
          value: "true"
          effect: NoSchedule
      securityContext:
        fsGroup: 10001
        fsGroupChangePolicy: OnRootMismatch
        seccompProfile:
          type: RuntimeDefault
      containers:
        - name: generator
          image: registry.bstein.dev/veles/veles-generator-worker:0.7.65 # {"$imagepolicy": "veles:veles-generator-worker"}
          imagePullPolicy: Always
          command: ["/bin/sh", "-c"]
          args:
            - |
              set -eu
              if [ -f /vault/secrets/veles-env.sh ]; then
                . /vault/secrets/veles-env.sh
              fi
              exec veles-generation-worker --loop --idle-sleep-seconds 5
          envFrom:
            - configMapRef:
                name: veles-config
          resources:
            requests:
              cpu: 100m
              memory: 512Mi
            limits:
              cpu: "1"
              memory: 2Gi
          securityContext:
            runAsNonRoot: true
            runAsUser: 10001
            runAsGroup: 10001
            allowPrivilegeEscalation: false
            capabilities:
              drop: ["ALL"]
