# =============================================================================
# ArgoCD Metrics Network Policy - 允許外部 Prometheus 抓取
# =============================================================================
# 建立者: Claude Code (首席架構師)
# 日期: 2026-03-29 (台北時間)
# 用途: 覆蓋 ArgoCD 預設 NetworkPolicy，允許 192.168.0.188 (Prometheus) 抓取指標
# =============================================================================

---
# Application Controller Metrics - 允許 Prometheus 抓取
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: argocd-application-controller-network-policy
  namespace: argocd
  labels:
    app.kubernetes.io/component: application-controller
    app.kubernetes.io/name: argocd-application-controller
    app.kubernetes.io/part-of: argocd
spec:
  podSelector:
    matchLabels:
      app.kubernetes.io/name: argocd-application-controller
  policyTypes:
    - Ingress
  ingress:
    # 允許叢集內部存取
    - from:
        - namespaceSelector: {}
      ports:
        - port: 8082
          protocol: TCP
    # 允許外部 Prometheus (188) 抓取指標
    - from:
        - ipBlock:
            cidr: 192.168.0.188/32
      ports:
        - port: 8082
          protocol: TCP

---
# ArgoCD Server Metrics - 允許 Prometheus 抓取
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: argocd-server-network-policy
  namespace: argocd
  labels:
    app.kubernetes.io/component: server
    app.kubernetes.io/name: argocd-server
    app.kubernetes.io/part-of: argocd
spec:
  podSelector:
    matchLabels:
      app.kubernetes.io/name: argocd-server
  policyTypes:
    - Ingress
  ingress:
    # 允許叢集內部存取
    - from:
        - namespaceSelector: {}
      ports:
        - port: 8080
          protocol: TCP
        - port: 8083
          protocol: TCP
    # 允許外部 Prometheus (188) 抓取指標
    - from:
        - ipBlock:
            cidr: 192.168.0.188/32
      ports:
        - port: 8083
          protocol: TCP
    # 允許外部使用者訪問 UI (NodePort 30443)
    - from:
        - ipBlock:
            cidr: 192.168.0.0/24
      ports:
        - port: 8080
          protocol: TCP
