apiVersion: v1
kind: Service
metadata:
  name: {{ template "wordpress.fullname" . }}
  labels: {{- include "wordpress.labels" . | nindent 4 }}
  {{- if .Values.service.annotations }}
  annotations: {{- include "wordpress.tplValue" (dict "value" .Values.service.annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if (or (eq .Values.service.type "LoadBalancer") (eq .Values.service.type "NodePort")) }}
  externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy | quote }}
  {{- end }}
  {{- if (and (eq .Values.service.type "LoadBalancer") .Values.service.loadBalancerSourceRanges) }}
  loadBalancerSourceRanges:
  {{- with .Values.service.loadBalancerSourceRanges }}
{{ toYaml . | indent 4 }}
  {{- end }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.service.port }}
      targetPort: http
      {{- if (and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.http))) }}
      nodePort: {{ .Values.service.nodePorts.http }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    - name: https
      port: {{ .Values.service.httpsPort }}
      targetPort: {{ .Values.service.httpsTargetPort }}
      {{- if (and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.https))) }}
      nodePort: {{ .Values.service.nodePorts.https }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
      {{- if .Values.metrics.enabled }}
    - name: metrics
      port: {{ .Values.service.metricsPort }}
      targetPort: metrics
      {{- if (and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePorts.metrics))) }}
      nodePort: {{ .Values.service.nodePorts.metrics }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
      {{- end }}
    {{- if .Values.service.extraPorts }}
    {{- include "wordpress.tplValue" (dict "value" .Values.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  selector: {{- include "wordpress.matchLabels" . | nindent 4 }}
