##
## Network Policies — Restrict traffic within fogbreak-ai namespace.
## Only the proxy can reach vLLM. Only ingress can reach the proxy.
##
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: vllm-access
  namespace: fogbreak-ai
spec:
  podSelector:
    matchLabels:
      component: vllm
  policyTypes:
    - Ingress
  ingress:
    # Only allow traffic from the AI proxy
    - from:
        - podSelector:
            matchLabels:
              component: ai-proxy
      ports:
        - protocol: TCP
          port: 8000
        - protocol: TCP
          port: 8001
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: proxy-access
  namespace: fogbreak-ai
spec:
  podSelector:
    matchLabels:
      component: ai-proxy
  policyTypes:
    - Ingress
  ingress:
    # Allow from ingress controller
    - from:
        - namespaceSelector:
            matchLabels:
              kubernetes.io/metadata.name: ingress-nginx
      ports:
        - protocol: TCP
          port: 8080
    # Allow from monitoring (Prometheus scrape)
    - from:
        - podSelector:
            matchLabels:
              component: prometheus
      ports:
        - protocol: TCP
          port: 8080
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: monitoring-access
  namespace: fogbreak-ai
spec:
  podSelector:
    matchLabels:
      component: prometheus
  policyTypes:
    - Ingress
    - Egress
  ingress:
    - from:
        - podSelector:
            matchLabels:
              component: grafana
      ports:
        - protocol: TCP
          port: 9090
  egress:
    # Prometheus needs to scrape all pods
    - to:
        - podSelector: {}
      ports:
        - protocol: TCP
          port: 8000
        - protocol: TCP
          port: 8001
        - protocol: TCP
          port: 8080
