Skip to content

Commit

Permalink
coturn: refactor resource labels, expose ServiceMonitor for metrics e…
Browse files Browse the repository at this point in the history
…ndpoint (#2677)

* charts/coturn: refactor labels.

This adds the labels app, chart, heritage, and release to the coturn chart
(same as the wire-server charts), and removes the boilerplate for overriding
resource names.

* changelog: update.

* charts/coturn: add optional ServiceMonitor

* charts/coturn: add metrics port to Service.

The Service is headless, so this port is not exposed to the outside world; this
is required so that the metrics endpoint is visible to the metrics collection
agent which consumes the ServiceMonitor.

* changelog: update.
  • Loading branch information
sysvinit authored Sep 7, 2022
1 parent 27353e6 commit 1bd1117
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 68 deletions.
6 changes: 6 additions & 0 deletions changelog.d/0-release-notes/coturn-labels
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
For users of the (currently alpha) coturn Helm chart, **manual action is
required** when upgrading to this version. The labels applied to the Kubernetes
manifests in this chart have changed, in order to match the conventions used
in the wire-server charts. However, this may mean that upgrading with Helm can
fail, due to changes to the `StatefulSet` included in this chart -- in this
case, the `StatefulSet` must be deleted before the chart is upgraded.
2 changes: 2 additions & 0 deletions changelog.d/2-features/coturn-metrics
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The coturn chart now has support for exposing its metric endpoint with a
ServiceMonitor, which can be ingested by third-party metrics collection tools.
2 changes: 2 additions & 0 deletions changelog.d/5-internal/coturn-labels
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The labels applied to resources in the coturn chart have been changed to
reflect the conventions in the wire-server charts.
45 changes: 0 additions & 45 deletions charts/coturn/templates/_helpers.yaml

This file was deleted.

4 changes: 1 addition & 3 deletions charts/coturn/templates/configmap-coturn-conf-template.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "coturn.fullname" . }}
labels:
{{- include "coturn.selectorLabels" . | nindent 4 }}
name: coturn

data:
coturn.conf.template: |
Expand Down
5 changes: 3 additions & 2 deletions charts/coturn/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ kind: Secret
metadata:
name: coturn
labels:
app: coturn
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
type: Opaque
stringData:
zrest_secret.txt: |
Expand Down
25 changes: 17 additions & 8 deletions charts/coturn/templates/service-account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "coturn.fullname" . }}
name: coturn
labels:
{{- include "coturn.labels" . | nindent 4 }}
app: coturn
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "coturn.fullname" . }}
name: coturn
labels:
{{- include "coturn.labels" . | nindent 4 }}
app: coturn
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
rules:
- apiGroups: [""]
resources: [nodes]
Expand All @@ -20,14 +26,17 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "coturn.fullname" . }}
name: coturn
labels:
{{- include "coturn.labels" . | nindent 4 }}
app: coturn
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
roleRef:
kind: ClusterRole
apiGroup: rbac.authorization.k8s.io
name: {{ include "coturn.fullname" . }}
name: coturn
subjects:
- kind: ServiceAccount
name: {{ include "coturn.fullname" . }}
name: coturn
namespace: {{ .Release.Namespace }}
13 changes: 10 additions & 3 deletions charts/coturn/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "coturn.fullname" . }}
name: coturn
labels:
{{- include "coturn.labels" . | nindent 4 }}
app: coturn
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
# Needs to be headless
# See: https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/
Expand All @@ -22,5 +25,9 @@ spec:
port: {{ .Values.coturnTurnTlsListenPort }}
targetPort: coturn-tls
{{- end }}
- name: status-http
port: {{ .Values.coturnMetricsListenPort }}
targetPort: status-http
selector:
{{- include "coturn.selectorLabels" . | nindent 4 }}
app: coturn
release: {{ .Release.Name }}
19 changes: 19 additions & 0 deletions charts/coturn/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.metrics.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: coturn
labels:
app: coturn
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
endpoints:
- port: status-http
path: /metrics
selector:
matchLabels:
app: coturn
release: {{ .Release.Name }}
{{- end }}
18 changes: 11 additions & 7 deletions charts/coturn/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "coturn.fullname" . }}
name: coturn
labels:
{{- include "coturn.labels" . | nindent 4 }}
app: coturn
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}

spec:
replicas: {{ .Values.replicaCount }}
Expand All @@ -12,10 +15,10 @@ spec:
# affect upgrades.
podManagementPolicy: Parallel

serviceName: {{ include "coturn.fullname" . }}
serviceName: coturn
selector:
matchLabels:
{{- include "coturn.selectorLabels" . | nindent 6 }}
app: coturn
template:
metadata:
{{- with .Values.podAnnotations }}
Expand All @@ -24,7 +27,8 @@ spec:
{{- end }}

labels:
{{- include "coturn.selectorLabels" . | nindent 8 }}
app: coturn
release: {{ .Release.Name }}
spec:
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
Expand All @@ -33,15 +37,15 @@ spec:
shareProcessNamespace: true
{{- end }}
hostNetwork: true
serviceAccountName: {{ include "coturn.fullname" . }}
serviceAccountName: coturn
volumes:
- name: external-ip
emptyDir: {}
- name: coturn-config
emptyDir: {}
- name: coturn-config-template
configMap:
name: {{ include "coturn.fullname" . }}
name: coturn
- name: secrets
secret:
secretName: coturn
Expand Down
4 changes: 4 additions & 0 deletions charts/coturn/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ tls:
pullPolicy: IfNotPresent
tag: 1aa6cbbf2ce3a5182ec47e3579bbcb8f47e22fdc

metrics:
serviceMonitor:
enabled: false

# This chart optionally supports waiting for traffic to drain from coturn
# before pods are terminated. Warning: coturn does not have any way to steer
# incoming client traffic away from itself on its own, so this functionality
Expand Down

0 comments on commit 1bd1117

Please sign in to comment.