apiVersion: apps/v1
kind: Deployment
metadata:
  name: dc-backend
  namespace: ai-env
  labels:
    app: dc-backend
spec:
  replicas: 1
  selector:
    matchLabels:
      app: dc-backend
  template:
    metadata:
      labels:
        app: dc-backend
    spec:
      containers:
        - name: dc-backend
          image: registry.express-o.org/frigosped/dc-backend:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8090
          env:
            # ORDS-Verbindung (Service im selben Namespace)
            - name: QUARKUS_REST_CLIENT_ORDS_API_URL
              value: "http://ords:8080/ords/ai_dev"
            # API-Key für eingehende Anfragen (DC_API_KEY)
            - name: DC_API_KEY
              valueFrom:
                secretKeyRef:
                  name: dc-backend-secrets
                  key: api-key
                  optional: true
            # KI-Provider: mistral | ollama
            - name: DC_AI_PROVIDER
              value: "mistral"
            # Mistral API-Key
            - name: MISTRAL_API_KEY
              valueFrom:
                secretKeyRef:
                  name: dc-backend-secrets
                  key: mistral-api-key
                  optional: true
            # Ollama-Fallback (aktiv wenn DC_AI_PROVIDER=ollama)
            - name: DC_AI_OLLAMA_BASE_URL
              value: "https://ollama.aquantico.de"
            - name: DC_AI_OLLAMA_API_KEY
              valueFrom:
                secretKeyRef:
                  name: dc-backend-secrets
                  key: ollama-api-key
                  optional: true
          livenessProbe:
            httpGet:
              path: /check/health
              port: 8090
            initialDelaySeconds: 20
            periodSeconds: 30
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /check/health
              port: 8090
            initialDelaySeconds: 15
            periodSeconds: 10
          resources:
            requests:
              memory: "256Mi"
              cpu: "100m"
            limits:
              memory: "512Mi"
              cpu: "500m"
---
apiVersion: v1
kind: Service
metadata:
  name: dc-backend
  namespace: ai-env
  labels:
    app: dc-backend
spec:
  selector:
    app: dc-backend
  ports:
    - port: 8090
      targetPort: 8090
  type: ClusterIP
---
apiVersion: v1
kind: Secret
metadata:
  name: dc-backend-secrets
  namespace: ai-env
type: Opaque
stringData:
  api-key: ""
  mistral-api-key: "2AkoohJC8MjfjhfLGObQESZs9jxbDnc0"
  ollama-api-key: "324GF44-50AA-4B57-9386-K435DLJ764DFR"
