# see:
# https://kubernetes.io/docs/tutorials/services/
# https://kubernetes.io/docs/concepts/services-networking/service/
# headless service for rpc
apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.app }}-rpc
spec:
  ports:
  - port: 9933
    name: http-rpc
  - port: 9944
    name: websocket-rpc
  selector:
    app: {{ .Values.GitlabEnvSlug | default .Values.app }}
  sessionAffinity: None
  type: ClusterIP
  clusterIP: None
---
{{- if .Values.listen_node_port }}
apiVersion: v1
kind: Service
metadata:
  name: {{ .Values.app }}
spec:
  ports:
  - port: 30333
    name: p2p
    nodePort: 30333
    protocol: TCP
  selector:
    app: {{ .Values.GitlabEnvSlug | default .Values.app }}
  sessionAffinity: None
  type: NodePort
  # don't route exteral traffic to non-local pods
  externalTrafficPolicy: Local
{{- else if .Values.validator.keys }}
{{- $root := . -}}
{{- range until (int .Values.nodes.replicas) }}
---
kind: Service
apiVersion: v1
metadata:
  name: {{ $root.Values.app }}-{{ . }}
spec:
  selector:
    statefulset.kubernetes.io/pod-name: {{ $root.Values.app }}-{{ . }}
  ports:
    - port: 30333
      targetPort: 30333
      protocol: TCP
{{- end }}
{{- end }}
