apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  labels:
    app: "{{ app_name }}"
  name: "{{ pair_name }}"
  namespace: "{{ _amlen_namespace }}"
spec:
  egress:
  - {}
  ingress:
{% if client_service_type != "None" %}
  - ports:
{% for key, value in amlen_messaging_ports.items() %}
      - port: {{value.internal if value.__class__.__name__ == "dict" else value}}
        protocol: TCP
{% endfor %}
{% endif %}
  - from:
    - podSelector:
        matchLabels:
          app: "{{ app_name }}"
  - from:
    - podSelector:
        matchLabels:
          amlen-user: "true"
    ports:
{% for key, value in amlen_messaging_ports.items() %}
    - port: {{value.internal if value.__class__.__name__ == "dict" else value}}
      protocol: TCP
{% endfor %}
  - from:
    - podSelector:
        matchLabels:
          app: amlen-operator
    - podSelector:
        matchLabels:
          app: "{{ app_name }}"
    ports:
{% for key, value in amlen_service_ports.items() %}
    - port: {{value}}
      protocol: TCP
{% endfor %}
  - from:
    - podSelector:
        matchLabels:
          app: "{{ app_name }}"
    ports:
{% for key, value in amlen_ha_ports.items() %}
    - port: {{value}}
      protocol: TCP
{% endfor %}
  podSelector:
    matchLabels:
      app: "{{app_name}}"
  policyTypes:
  - Ingress
  - Egress
