From f39e186fcbb54bc696b2d01dbd21ee14090831a5 Mon Sep 17 00:00:00 2001 From: qoeveleie21 Date: Wed, 13 Nov 2024 08:59:47 +0100 Subject: [PATCH] Add service and servicemonitor objects. Add port to connector to deployment --- .../templates/connector/deployment.yaml | 6 ++++ .../opencti/templates/connector/service.yaml | 28 ++++++++++++++++ .../templates/connector/servicemonitor.yaml | 32 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 charts/opencti/templates/connector/service.yaml create mode 100644 charts/opencti/templates/connector/servicemonitor.yaml diff --git a/charts/opencti/templates/connector/deployment.yaml b/charts/opencti/templates/connector/deployment.yaml index 2b3bedb..586f975 100644 --- a/charts/opencti/templates/connector/deployment.yaml +++ b/charts/opencti/templates/connector/deployment.yaml @@ -75,6 +75,12 @@ spec: {{- toYaml .securityContext | nindent 12 }} image: "{{- if and .image (hasKey .image "repository") }}{{ .image.repository }}{{- else if $.Values.global.imageRegistry }}{{ printf "%s/opencti/%s" $.Values.global.imageRegistry .name }}{{- else }}{{ printf "opencti/%s" .name }}{{- end }}:{{ if and .image (hasKey .image "tag") }}{{ .image.tag | default $.Chart.AppVersion }}{{ else }}{{ $.Chart.AppVersion }}{{ end }}" imagePullPolicy: {{ if and .image (hasKey .image "pullPolicy") }}{{ .image.pullPolicy }}{{ else }}IfNotPresent{{ end }} + ports: + {{- if ((.serviceMonitor).enabled) }} + - name: metrics + containerPort: {{ .env.CONNECTOR_METRICS_PORT | default 9095 }} + protocol: TCP + {{- end }} lifecycle: {{- with .lifecycle }} {{- toYaml . | nindent 12 }} diff --git a/charts/opencti/templates/connector/service.yaml b/charts/opencti/templates/connector/service.yaml new file mode 100644 index 0000000..341aa32 --- /dev/null +++ b/charts/opencti/templates/connector/service.yaml @@ -0,0 +1,28 @@ +{{- $connectorsGlobal := .Values.connectorsGlobal }} +{{- $serviceType := .Values.service.type }} + +{{- range .Values.connectors }} +{{- $connectorName := .name }} +{{- if and .enabled .env.CONNECTOR_EXPOSE_METRICS }} +--- +apiVersion: v1 +kind: Service +metadata: + name: {{ $connectorName }}-service-{{ include "opencti.fullname" $ }} + labels: + opencti.connector: {{ $connectorName }} + {{- include "opencti.labels" $ | nindent 4 }} +spec: + type: {{ $serviceType }} + ports: + {{- if .env.CONNECTOR_EXPOSE_METRICS }} + - name: metrics + port: {{ .env.CONNECTOR_METRICS_PORT | default 9095 }} + targetPort: {{ .env.CONNECTOR_METRICS_PORT | default 9095 }} + protocol: TCP + {{- end }} + selector: + opencti.connector: {{ $connectorName }} + {{- include "opencti.selectorLabels" $ | nindent 4 }} +{{- end }} +{{- end }} diff --git a/charts/opencti/templates/connector/servicemonitor.yaml b/charts/opencti/templates/connector/servicemonitor.yaml new file mode 100644 index 0000000..7b61dfe --- /dev/null +++ b/charts/opencti/templates/connector/servicemonitor.yaml @@ -0,0 +1,32 @@ +{{- $connectorsGlobal := .Values.connectorsGlobal }} +{{- range .Values.connectors }} +{{- $connectorName := .name }} + +{{- if and ((.serviceMonitor).enabled) .env.CONNECTOR_EXPOSE_METRICS }} +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ $connectorName }} + labels: + opencti.connector: {{ $connectorName }} + {{- include "opencti.labels" $ | nindent 4 }} +spec: + selector: + matchLabels: + opencti.connector: {{ $connectorName }} + {{- include "opencti.selectorLabels" $ | nindent 6 }} + endpoints: + - port: metrics + interval: {{ default "30s" .serviceMonitor.interval | quote }} + scrapeTimeout: {{ default "10s" .serviceMonitor.scrapeTimeout | quote }} + {{- if .serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml .serviceMonitor.metricRelabelings | nindent 4 }} + {{- end }} + {{- if .serviceMonitor.relabelings }} + relabelings: + {{- toYaml .serviceMonitor.relabelings | nindent 4 }} + {{- end }} +{{- end -}} +{{- end }}