{{- if .Values.networkPolicy.enabled }}
kind: NetworkPolicy
apiVersion: {{ include "common.capabilities.networkPolicy.apiVersion" . }}
metadata:
  name: {{ printf "%s-server" (include "common.names.fullname" .) }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if .Values.commonAnnotations }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  podSelector:
    matchLabels: {{ include "common.labels.matchLabels" . | nindent 6 }}
      app.kubernetes.io/component: server
  ingress:
    # Allow inbound connections to the Cache server nodes
    - ports:
        - port: {{ .Values.server.containerPorts.server }}
        - port: {{ .Values.server.containerPorts.http }}
        - port: {{ .Values.server.containerPorts.rmi }}
        # Range  of ephemeral ports available for unicast UDP messaging and for TCP failure detection
        # ref: https://geode.apache.org/docs/guide/114/configuring/running/firewalls_ports.html
        - port: 41000
          endPort: 61000
      {{- if not .Values.networkPolicy.allowExternal }}
      from:
        - podSelector:
            matchLabels:
              {{ template "common.names.fullname" . }}-client: "true"
        - podSelector:
            matchLabels: {{- include "common.labels.matchLabels" . | nindent 14 }}
      {{- end }}
    {{- if .Values.metrics.enabled }}
    # Allow prometheus scrapes for metrics
    - ports:
        - port: {{ .Values.server.containerPorts.metrics }}
    {{- end }}
{{- end }}
