Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cleanup and linting of metric resources #481

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/nextcloud/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: v2
name: nextcloud
version: 4.5.10
version: 4.5.11
appVersion: 28.0.1
description: A file sharing server that puts the control and security of your own data back into your hands.
keywords:
Expand Down
4 changes: 4 additions & 0 deletions charts/nextcloud/ci/ct-all-enabled-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
metrics:
enabled: true
serviceMonitor:
enabled: true
29 changes: 29 additions & 0 deletions charts/nextcloud/ci/ct-specials-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
metrics:
enabled: true
image:
pullSecrets:
- "registry-pull"
podAnnotations:
fakeVersion: unreleased
podLabels:
team: cool
resources:
requests:
memory: 100Mi
service:
type: LoadBalancer
loadBalancerIP: 100.64.0.1
annotations:
fakeVersion: unreleased
labels:
team: cool
serviceMonitor:
enabled: true
namespace: "somewhere-else"
labels:
prometheus: default
namespaceSelector:
matchNames:
- "blub"
interval: "20s"
scrapeTimeout: "15s"
75 changes: 0 additions & 75 deletions charts/nextcloud/templates/metrics-deployment.yaml

This file was deleted.

78 changes: 78 additions & 0 deletions charts/nextcloud/templates/metrics/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{{- if .Values.metrics.enabled }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "nextcloud.fullname" . }}-metrics
labels:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
helm.sh/chart: {{ include "nextcloud.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/component: metrics
spec:
replicas: {{ .Values.metrics.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: metrics
template:
metadata:
annotations:
{{- toYaml .Values.metrics.podAnnotations | nindent 8 }}
labels:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: metrics
{{- with .Values.metrics.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.metrics.image.pullSecrets }}
imagePullSecrets:
{{- range . }}
- name: {{ . }}
{{- end}}
{{- end }}
containers:
- name: metrics-exporter
image: "{{ .Values.metrics.image.repository }}:{{ .Values.metrics.image.tag }}"
imagePullPolicy: {{ .Values.metrics.image.pullPolicy }}
env:
{{- if .Values.metrics.token }}
- name: NEXTCLOUD_AUTH_TOKEN
valueFrom:
secretKeyRef:
name: {{ .Values.nextcloud.existingSecret.secretName | default (include "nextcloud.fullname" .) }}
key: {{ .Values.nextcloud.existingSecret.tokenKey }}
{{- else }}
- name: NEXTCLOUD_USERNAME
valueFrom:
secretKeyRef:
name: {{ .Values.nextcloud.existingSecret.secretName | default (include "nextcloud.fullname" .) }}
key: {{ .Values.nextcloud.existingSecret.usernameKey }}
- name: NEXTCLOUD_PASSWORD
valueFrom:
secretKeyRef:
name: {{ .Values.nextcloud.existingSecret.secretName | default (include "nextcloud.fullname" .) }}
key: {{ .Values.nextcloud.existingSecret.passwordKey }}
{{- end }}
- name: NEXTCLOUD_SERVER
# NEXTCLOUD_SERVER is used by metrics-exporter to reach the Nextcloud (K8s-)Service to grab the serverinfo api endpoint
value: http{{ if .Values.metrics.https }}s{{ end }}://{{ template "nextcloud.fullname" . }}:{{ .Values.service.port }}
- name: NEXTCLOUD_TIMEOUT
value: {{ .Values.metrics.timeout }}
- name: NEXTCLOUD_TLS_SKIP_VERIFY
value: {{ .Values.metrics.tlsSkipVerify | quote }}
ports:
- name: metrics
containerPort: 9205
{{- with .Values.metrics.resources }}
resources:
{{- toYaml . | nindent 10 }}
{{- end }}
securityContext:
runAsUser: 1000
runAsNonRoot: true
{{- end }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- if .Values.metrics.enabled }}
---
apiVersion: v1
kind: Service
metadata:
Expand All @@ -9,22 +10,22 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/component: metrics
{{- if .Values.metrics.service.labels -}}
{{ toYaml .Values.metrics.service.labels | nindent 4 }}
{{- end -}}
{{- if .Values.metrics.service.annotations }}
annotations: {{ toYaml .Values.metrics.service.annotations | nindent 4 }}
{{- with .Values.metrics.service.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.metrics.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.metrics.service.type }}
{{ if eq .Values.metrics.service.type "LoadBalancer" -}} {{ if .Values.metrics.service.loadBalancerIP }}
{{- if and (eq .Values.metrics.service.type "LoadBalancer") .Values.metrics.service.loadBalancerIP }}
loadBalancerIP: {{ .Values.metrics.service.loadBalancerIP }}
{{ end -}}
{{- end -}}
{{- end }}
ports:
- name: metrics
port: 9205
targetPort: metrics
- name: metrics
port: 9205
targetPort: metrics
selector:
app.kubernetes.io/name: {{ include "nextcloud.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{{- if and .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }}
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "nextcloud.fullname" . }}
{{- if .Values.metrics.serviceMonitor.namespace }}
namespace: {{ .Values.metrics.serviceMonitor.namespace | quote }}
{{- with .Values.metrics.serviceMonitor.namespace }}
namespace: {{ . | quote }}
{{- else }}
namespace: {{ .Release.Namespace | quote }}
{{- end }}
Expand All @@ -14,8 +15,8 @@ metadata:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/component: metrics
{{- if .Values.metrics.serviceMonitor.labels -}}
{{ toYaml .Values.metrics.serviceMonitor.labels | nindent 4 }}
{{- with .Values.metrics.serviceMonitor.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
jobLabel: {{ .Values.metrics.serviceMonitor.jobLabel | quote }}
Expand All @@ -25,15 +26,19 @@ spec:
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/component: metrics
namespaceSelector:
{{- with .Values.metrics.serviceMonitor.namespaceSelector }}
{{- toYaml . | nindent 4 }}
{{- else }}
matchNames:
- {{ .Release.Namespace | quote }}
{{- end }}
endpoints:
- port: metrics
path: "/"
{{- if .Values.metrics.serviceMonitor.interval }}
interval: {{ .Values.metrics.serviceMonitor.interval }}
{{- with .Values.metrics.serviceMonitor.interval }}
interval: {{ . }}
{{- end }}
{{- if .Values.metrics.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ .Values.metrics.serviceMonitor.scrapeTimeout }}
{{- with .Values.metrics.serviceMonitor.scrapeTimeout }}
scrapeTimeout: {{ . }}
{{- end }}
{{- end }}
3 changes: 3 additions & 0 deletions charts/nextcloud/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ metrics:
##
namespace: ""

## @param metrics.serviceMonitor.namespaceSelector where service are to discoverd (default release namespace)
namespaceSelector:

## @param metrics.serviceMonitor.jobLabel The name of the label on the target service to use as the job name in prometheus.
##
jobLabel: ""
Expand Down