apiVersion: v1
kind: Service
metadata:
  name: {{ template "metrics-server.fullname" . }}
  labels: {{- include "metrics-server.labels" . | nindent 4 }}
  {{- if .Values.service.annotations }}
  annotations: {{- include "metrics-server.tplValue" (dict "value" .Values.service.annotation "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if and (not (empty .Values.service.loadBalancerIP)) (eq .Values.service.type "LoadBalancer") }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  ports:
    - name: https
      port: {{ .Values.service.port }}
      protocol: TCP
      targetPort: https
      {{- if and (or (eq .Values.service.type "NodePort") (eq .Values.service.type "LoadBalancer")) (not (empty .Values.service.nodePort)) }}
      nodePort: {{ .Values.service.nodePort }}
      {{- else if eq .Values.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
  selector: {{- include "metrics-server.matchLabels" . | nindent 4 }}
