apiVersion: v1
kind: Service
metadata:
  name: {{ template "wordpress.fullname" . }}
  labels:
    app: "{{ template "wordpress.fullname" . }}"
    chart: "{{ template "wordpress.chart" . }}"
    release: {{ .Release.Name | quote }}
    heritage: {{ .Release.Service | quote }}
  annotations:
{{- if .Values.service.annotations }}
{{ toYaml .Values.service.annotations | indent 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 }}
  ports:
    - name: http
      port: {{ .Values.service.port }}
      targetPort: http
      {{- if (and (eq .Values.service.type "NodePort") (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 (eq .Values.service.type "NodePort") (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 (eq .Values.service.type "NodePort") (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 }}
{{ toYaml .Values.service.extraPorts | indent 4 }}
{{- end }}      
  selector:
    app: "{{ template "wordpress.fullname" . }}"
