---
apiVersion: v1
kind: Service
metadata:
  name: {{ include "stacks-blockchain.fullname" . }}
  labels: {{- include "stacks-blockchain.labels" . | nindent 4 }}
  {{- if .Values.service.annotations }}
  annotations: {{ toYaml .Values.service.annotations | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if and (.Values.service.externalTrafficPolicy) (not (eq .Values.service.type "ClusterIP")) }}
  externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }}
  {{- end }}
  ports:
    - port: {{ .Values.service.rpcPort | default .Values.node.rpcPort }}
      targetPort: rpc
      protocol: TCP
      name: rpc
    - port: {{ .Values.service.p2pPort | default .Values.node.p2pPort }}
      targetPort: p2p
      protocol: TCP
      name: p2p
    {{- if .Values.metrics.enabled }}
    - port: {{ .Values.metrics.port | default 9153 }}
      targetPort: metrics
      protocol: TCP
      name: metrics
    {{- end }}
  selector: {{- include "stacks-blockchain.selectorLabels" . | nindent 4 }}
