apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: chroma-pvc
  namespace: contoso-hypermarket
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: chroma-config
  namespace: contoso-hypermarket
data:
  CHROMA_SERVER_HTTP_PORT: "8040"
  CHROMA_SERVER_HOST: "0.0.0.0"
  CHROMA_SERVER_CORS_ALLOW_ORIGINS: '["*"]'  # Fixed JSON format
  CHROMA_SERVER_AUTH_CREDENTIALS: "false"
  PERSIST_DIRECTORY: "/chroma/data"
  CHROMA_SERVER_AUTH_BASIC_ENABLE: "false"
  CHROMA_SERVER_AUTH_DISABLE: "true"
  ALLOW_RESET: "true"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: chroma-db
  namespace: contoso-hypermarket
  labels:
    app: chroma-db
spec:
  replicas: 1
  selector:
    matchLabels:
      app: chroma-db
  template:
    metadata:
      labels:
        app: chroma-db
    spec:
      containers:
      - name: chroma-db
        image: chromadb/chroma:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8040
          name: http
        command: ["uvicorn"]
        args: ["chromadb.app:app", "--host", "0.0.0.0", "--port", "8040", "--proxy-headers", "--timeout-keep-alive", "30"]
        env:
        - name: CHROMA_SERVER_HTTP_PORT
          valueFrom:
            configMapKeyRef:
              name: chroma-config
              key: CHROMA_SERVER_HTTP_PORT
        - name: CHROMA_SERVER_HOST
          valueFrom:
            configMapKeyRef:
              name: chroma-config
              key: CHROMA_SERVER_HOST
        - name: CHROMA_SERVER_CORS_ALLOW_ORIGINS
          valueFrom:
            configMapKeyRef:
              name: chroma-config
              key: CHROMA_SERVER_CORS_ALLOW_ORIGINS
        - name: CHROMA_SERVER_AUTH_CREDENTIALS
          valueFrom:
            configMapKeyRef:
              name: chroma-config
              key: CHROMA_SERVER_AUTH_CREDENTIALS
        - name: PERSIST_DIRECTORY
          valueFrom:
            configMapKeyRef:
              name: chroma-config
              key: PERSIST_DIRECTORY
        - name: CHROMA_SERVER_AUTH_BASIC_ENABLE
          valueFrom:
            configMapKeyRef:
              name: chroma-config
              key: CHROMA_SERVER_AUTH_BASIC_ENABLE
        - name: CHROMA_SERVER_AUTH_DISABLE
          valueFrom:
            configMapKeyRef:
              name: chroma-config
              key: CHROMA_SERVER_AUTH_DISABLE
        - name: ALLOW_RESET
          valueFrom:
            configMapKeyRef:
              name: chroma-config
              key: ALLOW_RESET
        resources:
          requests:
            cpu: "500m"
            memory: "512Mi"
          limits:
            cpu: "2000m"
            memory: "2Gi"
        volumeMounts:
        - name: chroma-data
          mountPath: /chroma/data
        readinessProbe:
          httpGet:
            path: /api/v1/heartbeat
            port: 8040
          initialDelaySeconds: 15
          periodSeconds: 10
        livenessProbe:
          httpGet:
            path: /api/v1/heartbeat
            port: 8040
          initialDelaySeconds: 15
          periodSeconds: 20
      volumes:
      - name: chroma-data
        persistentVolumeClaim:
          claimName: chroma-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: chroma-db-service
  namespace: contoso-hypermarket
  labels:
    app: chroma-db
spec:
  type: LoadBalancer
  ports:
    - port: 8040
      targetPort: 8040
      nodePort: 30040
      protocol: TCP
      name: http
  selector:
    app: chroma-db