# helm_charts_agent-services.yaml
{{- if .Values.clusterAgent.enabled -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "datadog.fullname" . }}-cluster-agent
  labels:
    helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    app.kubernetes.io/name: "{{ template "datadog.fullname" . }}"
    app.kubernetes.io/instance: {{ .Release.Name | quote }}
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
spec:
  type: ClusterIP
  selector:
    app: {{ template "datadog.fullname" . }}-cluster-agent
  ports:
  - port: 5005
    name: agentport
    protocol: TCP
{{ end }}

{{- if and .Values.clusterAgent.enabled .Values.clusterAgent.metricsProvider.enabled -}}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ template "datadog.fullname" . }}-cluster-agent-metrics-api
  labels:
    app: "{{ template "datadog.fullname" . }}"
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    release: {{ .Release.Name | quote }}
    heritage: {{ .Release.Service | quote }}
    helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    app.kubernetes.io/name: "{{ template "datadog.fullname" . }}"
    app.kubernetes.io/instance: {{ .Release.Name | quote }}
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
spec:
  type: {{ .Values.clusterAgent.metricsProvider.service.type }}
  selector:
    app: {{ template "datadog.fullname" . }}-cluster-agent
  ports:
  - port: {{ template "clusterAgent.metricsProvider.port" . }}
    name: metricsapi
    protocol: TCP
{{ end }}

{{- if and .Values.clusterAgent.enabled .Values.clusterAgent.admissionController.enabled -}}
---
apiVersion: v1
kind: Service
metadata:
  name: {{ template "datadog.fullname" . }}-cluster-agent-admission-controller
  labels:
    app: "{{ template "datadog.fullname" . }}"
    chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    release: {{ .Release.Name | quote }}
    heritage: {{ .Release.Service | quote }}
    helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
    app.kubernetes.io/name: "{{ template "datadog.fullname" . }}"
    app.kubernetes.io/instance: {{ .Release.Name | quote }}
    app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
    app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
spec:
  selector:
    app: {{ template "datadog.fullname" . }}-cluster-agent
  ports:
  - port: 443
    targetPort: 8000
{{ end }}