{{- $nacos := .Values -}}
{{- $ncs   := .Values.nacos }}
apiVersion: v1
kind: Service
metadata:
  name: nacos
  namespace: {{ .Release.Namespace }}
  labels:
    app: nacos
    dubbo.io/rev: {{ default "default" | quote }}
    install.operator.dubbo.io/owning-resource: {{ default "unknown" }}
    operator.dubbo.io/component: "Nacos"
    dubbo: nacos
    release: {{ .Release.Name }}
    app.kubernetes.io/name: "register"
spec:
  ports:
  - name: http
    port: 8848
    targetPort: http
    protocol: TCP
  - name: clientgen-rpc
    port: {{ add 8848 1000 }}
    targetPort: clientgen-rpc
    protocol: TCP
  - name: raft-rpc
    port: {{ add 8848 1001 }}
    targetPort: raft-rpc
    protocol: TCP
  selector:
    app: nacos
---
{{- if and (eq $nacos.mode "cluster" | default $ncs.mode) }}
apiVersion: v1
kind: Service
metadata:
  name: nacos-headless
  namespace: {{ .Release.Namespace }}
  labels:
    app: nacos
    dubbo.io/rev: {{ default "default" | quote }}
    install.operator.dubbo.io/owning-resource: {{ default "unknown" }}
    operator.dubbo.io/component: "Nacos"
    dubbo: nacos
    release: {{ .Release.Name }}
    app.kubernetes.io/name: "register"
spec:
  clusterIP: None
  ports:
  - name: http
    port: 8848
    targetPort: http
    protocol: TCP
  - name: clientgen-rpc
    port: {{ add 8848 1000 }}
    targetPort: clientgen-rpc
    protocol: TCP
  - name: raft-rpc
    port: {{ add 8848 1001 }}
    targetPort: raft-rpc
    protocol: TCP
  selector:
    app: nacos
{{- end -}}