{{- with .Values.networkPolicy }}
{{- if .enabled }}
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: {{ include "woodpecker-agent.fullname" $ }}
  labels:
    {{- include "woodpecker-agent.labels" $ | nindent 4 }}
spec:
  podSelector:
    matchLabels:
      {{- include "woodpecker-agent.selectorLabels" $ | nindent 6 }}
  policyTypes:
    - Ingress
    {{- if .egress.enabled }}
    - Egress
    {{- end }}
  ingress:
    {{- with .ingress.http }}
    - ports:
        - port: 3000
          protocol: TCP
      from:
        {{- toYaml . | nindent 8 }}
    {{- end }}{{/* end-with .ingress.http */}}

  {{- with .egress }}
  {{- if .enabled }}
  egress:
    {{- with .dns }}
    - ports:
        - port: 53
          protocol: UDP
      to:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .server }}
    - {{- toYaml . | nindent 6 }}
    {{- end }}
    {{- with .apiserver }}
    - {{- toYaml . | nindent 6 }}
    {{- end }}
    {{- with .extra }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- end }}{{/* end-if egress.enabled */}}
  {{- end }}{{/* end-with .egress */}}
{{- end }}
{{- end }}
