diff --git a/charts/jellyfin/templates/_helpers.tpl b/charts/jellyfin/templates/_helpers.tpl index 8038966..bad69c0 100644 --- a/charts/jellyfin/templates/_helpers.tpl +++ b/charts/jellyfin/templates/_helpers.tpl @@ -1,4 +1,12 @@ {{/* vim: set filetype=mustache: */}} + +{{/* +Fail if command and metrics are set +*/}} +{{- if and .Values.image.command .Values.metrics.enabled }} +{{- fail "Can't use custom command and metrics in combination. They are exclusive features" }} +{{- end }} + {{/* Expand the name of the chart. */}} diff --git a/charts/jellyfin/templates/deployment.yaml b/charts/jellyfin/templates/deployment.yaml index ceb2960..9f05c5a 100644 --- a/charts/jellyfin/templates/deployment.yaml +++ b/charts/jellyfin/templates/deployment.yaml @@ -39,10 +39,14 @@ spec: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} - {{ if .Values.image.command }} + {{ if and .Values.image.command (not .Values.metrics.enabled) }} command: {{- toYaml .Values.image.command | nindent 12 }} {{- end }} + {{ if .Values.metrics.enabled }} + command: + {{- toYaml .Values.metrics.command | nindent 12 }} + {{- end }} {{ if .Values.image.args }} args: {{- toYaml .Values.image.args | nindent 12 }} diff --git a/charts/jellyfin/templates/service.yaml b/charts/jellyfin/templates/service.yaml index ba2b245..c0c07c4 100644 --- a/charts/jellyfin/templates/service.yaml +++ b/charts/jellyfin/templates/service.yaml @@ -40,7 +40,7 @@ spec: externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }} {{- end }} ports: - - name: http + - name: {{ .Values.service.name }} port: {{ .Values.service.port }} protocol: TCP targetPort: http diff --git a/charts/jellyfin/templates/serviceMonitor.yaml b/charts/jellyfin/templates/serviceMonitor.yaml new file mode 100644 index 0000000..0c48709 --- /dev/null +++ b/charts/jellyfin/templates/serviceMonitor.yaml @@ -0,0 +1,51 @@ +{{- if and .Values.metrics.serviceMonitor.enabled .Values.metrics.enabled }} +--- +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "jellyfin.fullname" . }} + {{- if .Values.metrics.serviceMonitor.namespace }} + namespace: {{ tpl .Values.metrics.serviceMonitor.namespace . }} + {{- else }} + labels: + app.kubernetes.io/name: {{ include "jellyfin.name" . }} + helm.sh/chart: {{ include "jellyfin.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.metrics.serviceMonitor.labels }} + {{- tpl (toYaml . | nindent 4) $ }} + {{- end }} +spec: + endpoints: + - port: {{ .Values.service.name }} + {{- with .Values.metrics.serviceMonitor.interval }} + interval: {{ . }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.scrapeTimeout }} + scrapeTimeout: {{ . }} + {{- end }} + honorLabels: true + path: {{ .Values.metrics.serviceMonitor.path }} + scheme: {{ .Values.metrics.serviceMonitor.scheme }} + {{- with .Values.metrics.serviceMonitor.tlsConfig }} + tlsConfig: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.relabelings }} + relabelings: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- with .Values.metrics.serviceMonitor.metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 6 }} + {{- end }} + jobLabel: "{{ .Release.Name }}" + selector: + matchLabels: + app.kubernetes.io/name: {{ include "jellyfin.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + {{- with .Values.metrics.serviceMonitor.targetLabels }} + targetLabels: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/jellyfin/values.yaml b/charts/jellyfin/values.yaml index 4e1d67f..e568ad4 100644 --- a/charts/jellyfin/values.yaml +++ b/charts/jellyfin/values.yaml @@ -18,6 +18,7 @@ fullnameOverride: "" enableDLNA: false service: + name: http type: ClusterIP port: 8096 ## Specify the nodePort value for the LoadBalancer and NodePort service types. @@ -38,6 +39,41 @@ service: ## Set the externalTrafficPolicy in the Service to either Cluster or Local # externalTrafficPolicy: Cluster +# -- Configuration for metrics collection and monitoring +metrics: + # -- Enable or disable metrics collection + enabled: false + command: + - bash + - '-c' + - >- + sed 's,false,true,' -i /config/config/system.xml && + /jellyfin/jellyfin + # -- Configuration for the Prometheus ServiceMonitor + serviceMonitor: + # -- Enable or disable the creation of a ServiceMonitor resource + enabled: false + # -- Namespace where the ServiceMonitor resource should be created. Defaults to Release.Namespace + namespace: '' + # -- Labels to add to the ServiceMonitor resource + labels: {} + # -- Interval at which metrics should be scraped + interval: 30s + # -- Timeout for scraping metrics + scrapeTimeout: 30s + # -- Path to scrape for metrics + path: /metrics + # -- Scheme to use for scraping metrics (http or https) + scheme: http + # -- TLS configuration for scraping metrics + tlsConfig: {} + # -- Relabeling rules for the scraped metrics + relabelings: [] + # -- Relabeling rules for the metrics before ingestion + metricRelabelings: [] + # -- Target labels to add to the scraped metrics + targetLabels: [] + ingress: enabled: false labels: {}