apiVersion: v1
kind: Service
metadata:
  name: {{ include "apisix-ingress-controller.fullname" . }}-apisix-gateway
  namespace: {{ .Release.Namespace }}
  annotations:
    {{- range $key, $value := .Values.gateway.annotations }}
      {{ $key }}: {{ $value | quote }}
    {{- end }}
  labels:
    {{- include "apisix-ingress-controller.labels" . | nindent 4 }}
spec:
  ports:
    - name: http
      protocol: TCP
      port: 80
      targetPort: 9080
    - name: https
      protocol: TCP
      port: {{ .Values.gateway.tls.servicePort }}
      targetPort: {{ .Values.gateway.tls.containerPort }}
  selector:
    {{- include "apisix-ingress-controller.selectorLabels" . | nindent 4 }}
  type: {{ .Values.gateway.type }} # LoadBalancer or NodePort
  {{- if or (eq .Values.gateway.type "LoadBalancer") (eq .Values.gateway.type "NodePort") }}
  externalTrafficPolicy: {{ .Values.gateway.externalTrafficPolicy }}
  {{- end }}
  {{- if eq .Values.gateway.type "LoadBalancer" }}
  {{- if .Values.gateway.loadBalancerIP }}
  loadBalancerIP: {{ .Values.gateway.loadBalancerIP }} # specify load balancer ip by user
  {{- end }}
  {{- if .Values.gateway.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
  {{- range $cidr := .Values.gateway.loadBalancerSourceRanges }}
  - {{ $cidr }}
  {{- end }}
  {{- end }}
  {{- end }}
  {{- if gt (len .Values.gateway.externalIPs) 0 }}
  externalIPs:
  {{- range $ip := .Values.gateway.externalIPs }}
  - {{ $ip }}
  {{- end }}
  {{- end }}