Skip to content

Commit 08c49f6

Browse files
committed
fix helm servicemonitor and custom labels
Signed-off-by: Artem Torubarov <torubarov.a.a@gmail.com>
1 parent 790f531 commit 08c49f6

26 files changed

Lines changed: 292 additions & 73 deletions

‎deploy/chorus/Chart.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ description: Helm chart for Chorus S3 management software.
44
keywords: ["S3", "Backup", "Replication", "Migration"]
55
home: https://github.com/clyso/chorus
66
type: application
7-
version: 0.2.0
8-
appVersion: "v0.6.1"
7+
version: 0.3.0
8+
appVersion: "v0.7.7"
99
dependencies:
1010
- name: redis
1111
version: 23.1.3

‎deploy/chorus/README.md‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,37 @@ externalRedis:
7777
existingSecret: "my-redis-secret"
7878
```
7979
80+
### Metrics
81+
82+
`metrics.enabled` exposes a Prometheus `/metrics` endpoint on proxy and worker
83+
(port 9090) and creates a `ClusterIP` metrics Service for each.
84+
85+
To scrape via the Prometheus Operator, also enable `serviceMonitor` and set the
86+
discovery label your Prometheus selects on (check your operator's
87+
`serviceMonitorSelector`):
88+
89+
```yaml
90+
metrics:
91+
enabled: true
92+
serviceMonitor:
93+
enabled: true
94+
labels:
95+
release: kube-prometheus-stack # match your Prometheus release
96+
interval: 30s # optional
97+
scrapeTimeout: 10s # optional
98+
```
99+
100+
Enable `metrics` without `serviceMonitor` when scraping via pod annotations or a
101+
ServiceMonitor managed elsewhere (e.g. on a cluster without the operator CRDs).
102+
103+
### Images
104+
105+
Each component's image is set via `<component>.image` (`repository`, `tag`,
106+
`pullPolicy`). `tag` defaults to the chart's `appVersion`, and `pullPolicy`
107+
defaults to `IfNotPresent`. If you override `tag` with a mutable tag (e.g.
108+
`latest` or a dev tag), set `pullPolicy: Always` so nodes don't keep a stale
109+
cached image.
110+
80111
## Components
81112

82113
| Component | Description | Default |

‎deploy/chorus/templates/_helpers.tpl‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Create chart name and version as used by the chart label.
2929
{{- end }}
3030

3131
{{/*
32-
Common labels
32+
Common labels (metadata only, never selectors)
3333
*/}}
3434
{{- define "chorus.labels" -}}
3535
helm.sh/chart: {{ include "chorus.chart" . }}
@@ -38,6 +38,35 @@ helm.sh/chart: {{ include "chorus.chart" . }}
3838
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
3939
{{- end }}
4040
app.kubernetes.io/managed-by: {{ .Release.Service }}
41+
{{- with .Values.commonLabels }}
42+
{{ toYaml . }}
43+
{{- end }}
44+
{{- end }}
45+
46+
{{/*
47+
Common annotations merged with a resource's own annotations (resource wins).
48+
Usage: {{- with (include "chorus.annotations" (list .Values.x.annotations .)) }}
49+
*/}}
50+
{{- define "chorus.annotations" -}}
51+
{{- $local := index . 0 | default dict -}}
52+
{{- $root := index . 1 -}}
53+
{{- $merged := merge (deepCopy $local) ($root.Values.commonAnnotations | default dict) -}}
54+
{{- with $merged -}}
55+
{{- toYaml . -}}
56+
{{- end -}}
57+
{{- end }}
58+
59+
{{/*
60+
Pod-level user labels: podLabels merged over commonLabels (podLabels win).
61+
Emitted alongside the structural selector/component labels in pod templates.
62+
*/}}
63+
{{- define "chorus.podLabels" -}}
64+
{{- $local := index . 0 | default dict -}}
65+
{{- $root := index . 1 -}}
66+
{{- $merged := merge (deepCopy $local) ($root.Values.commonLabels | default dict) -}}
67+
{{- with $merged -}}
68+
{{- toYaml . -}}
69+
{{- end -}}
4170
{{- end }}
4271

4372
{{/*
@@ -48,6 +77,14 @@ app.kubernetes.io/name: {{ include "chorus.name" . }}
4877
app.kubernetes.io/instance: {{ .Release.Name }}
4978
{{- end }}
5079

80+
{{/*
81+
Metrics port. Single source for the app (via CFG_METRICS_PORT), container port
82+
and metrics Service; matches the app default (pkg/config/config.yaml: metrics.port).
83+
*/}}
84+
{{- define "chorus.metricsPort" -}}
85+
9090
86+
{{- end }}
87+
5188
{{/*
5289
Create the name of the service account to use
5390
*/}}

‎deploy/chorus/templates/pdb.yaml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ metadata:
66
labels:
77
{{- include "chorus.labels" . | nindent 4 }}
88
app.kubernetes.io/component: proxy
9+
{{- with (include "chorus.annotations" (list dict .)) }}
10+
annotations:
11+
{{- . | nindent 4 }}
12+
{{- end }}
913
spec:
1014
{{- if .Values.proxy.podDisruptionBudget.minAvailable }}
1115
minAvailable: {{ .Values.proxy.podDisruptionBudget.minAvailable }}
@@ -27,6 +31,10 @@ metadata:
2731
labels:
2832
{{- include "chorus.labels" . | nindent 4 }}
2933
app.kubernetes.io/component: worker
34+
{{- with (include "chorus.annotations" (list dict .)) }}
35+
annotations:
36+
{{- . | nindent 4 }}
37+
{{- end }}
3038
spec:
3139
{{- if .Values.worker.podDisruptionBudget.minAvailable }}
3240
minAvailable: {{ .Values.worker.podDisruptionBudget.minAvailable }}

‎deploy/chorus/templates/proxy/config.yaml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ metadata:
66
labels:
77
{{- include "chorus.labels" . | nindent 4 }}
88
app.kubernetes.io/component: proxy
9+
{{- with (include "chorus.annotations" (list dict .)) }}
10+
annotations:
11+
{{- . | nindent 4 }}
12+
{{- end }}
913
data:
1014
config.yaml: |
1115
{{- /* Proxy-specific config */}}

‎deploy/chorus/templates/proxy/deployment-proxy.yaml‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ metadata:
66
labels:
77
{{- include "chorus.labels" . | nindent 4 }}
88
app.kubernetes.io/component: proxy
9+
{{- with (include "chorus.annotations" (list dict .)) }}
10+
annotations:
11+
{{- . | nindent 4 }}
12+
{{- end }}
913
spec:
1014
replicas: {{ .Values.proxy.replicas }}
1115
selector:
@@ -17,18 +21,21 @@ spec:
1721
labels:
1822
{{- include "chorus.selectorLabels" . | nindent 8 }}
1923
app.kubernetes.io/component: proxy
24+
{{- with (include "chorus.podLabels" (list .Values.proxy.podLabels .)) }}
25+
{{- . | nindent 8 }}
26+
{{- end }}
2027
annotations:
2128
checksum/config: {{ include (print $.Template.BasePath "/proxy/config.yaml") . | sha256sum }}
2229
{{- if include "chorus.createCredentialsSecret" . }}
2330
checksum/secret: {{ include (print $.Template.BasePath "/secrets/secret.yaml") . | sha256sum }}
2431
{{- end }}
25-
{{- if .Values.proxy.config.metrics.enabled }}
32+
{{- if .Values.metrics.enabled }}
2633
prometheus.io/scrape: "true"
2734
prometheus.io/path: "/metrics"
28-
prometheus.io/port: "9090"
35+
prometheus.io/port: {{ include "chorus.metricsPort" . | quote }}
2936
{{- end }}
30-
{{- with .Values.proxy.podAnnotations }}
31-
{{- toYaml . | nindent 8 }}
37+
{{- with (include "chorus.annotations" (list .Values.proxy.podAnnotations .)) }}
38+
{{- . | nindent 8 }}
3239
{{- end }}
3340
spec:
3441
{{- with .Values.imagePullSecrets }}
@@ -61,6 +68,12 @@ spec:
6168
- name: CFG_REDIS_SENTINEL_MASTERNAME
6269
value: {{ .Values.externalRedis.sentinel.masterName | quote }}
6370
{{- end }}
71+
{{- if .Values.metrics.enabled }}
72+
- name: CFG_METRICS_ENABLED
73+
value: "true"
74+
- name: CFG_METRICS_PORT
75+
value: {{ include "chorus.metricsPort" . | quote }}
76+
{{- end }}
6477
{{- if .Values.dynamicCredentials.enabled }}
6578
- name: CFG_STORAGE_DYNAMICCREDENTIALS_MASTERPASSWORD
6679
valueFrom:
@@ -72,9 +85,9 @@ spec:
7285
- name: http
7386
containerPort: {{ .Values.proxy.config.port }}
7487
protocol: TCP
75-
{{- if .Values.proxy.config.metrics.enabled }}
88+
{{- if .Values.metrics.enabled }}
7689
- name: metrics
77-
containerPort: 9090
90+
containerPort: {{ include "chorus.metricsPort" . }}
7891
protocol: TCP
7992
{{- end }}
8093
livenessProbe:

‎deploy/chorus/templates/proxy/ingress.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ metadata:
66
labels:
77
{{- include "chorus.labels" . | nindent 4 }}
88
app.kubernetes.io/component: proxy
9-
{{- with .Values.ingress.proxy.annotations }}
9+
{{- with (include "chorus.annotations" (list .Values.ingress.proxy.annotations .)) }}
1010
annotations:
11-
{{- toYaml . | nindent 4 }}
11+
{{- . | nindent 4 }}
1212
{{- end }}
1313
spec:
1414
{{- if .Values.ingress.proxy.className }}
Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
1-
{{- if and .Values.proxy.enabled .Values.proxy.config.metrics.enabled }}
1+
{{- if and .Values.proxy.enabled .Values.metrics.enabled .Values.metrics.serviceMonitor.enabled }}
22
apiVersion: monitoring.coreos.com/v1
33
kind: ServiceMonitor
44
metadata:
5-
name: proxy-monitor
5+
name: {{ include "chorus.fullname" . }}-proxy
66
labels:
7-
release: kube-prometheus-stack
7+
{{- include "chorus.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: proxy
9+
{{- with .Values.metrics.serviceMonitor.labels }}
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
{{- with (include "chorus.annotations" (list dict .)) }}
13+
annotations:
14+
{{- . | nindent 4 }}
15+
{{- end }}
816
spec:
17+
jobLabel: app.kubernetes.io/component
918
selector:
1019
matchLabels:
11-
app: proxy
20+
{{- include "chorus.selectorLabels" . | nindent 6 }}
21+
app.kubernetes.io/component: proxy
22+
chorus.clyso.com/metrics: "true"
1223
namespaceSelector:
1324
matchNames:
1425
- {{ .Release.Namespace }}
1526
endpoints:
1627
- port: metrics
17-
jobLabel: app
18-
{{- end }}
28+
path: /metrics
29+
{{- with .Values.metrics.serviceMonitor.interval }}
30+
interval: {{ . }}
31+
{{- end }}
32+
{{- with .Values.metrics.serviceMonitor.scrapeTimeout }}
33+
scrapeTimeout: {{ . }}
34+
{{- end }}
35+
{{- if .Values.metrics.serviceMonitor.honorLabels }}
36+
honorLabels: true
37+
{{- end }}
38+
{{- with .Values.metrics.serviceMonitor.relabelings }}
39+
relabelings:
40+
{{- toYaml . | nindent 8 }}
41+
{{- end }}
42+
{{- with .Values.metrics.serviceMonitor.metricRelabelings }}
43+
metricRelabelings:
44+
{{- toYaml . | nindent 8 }}
45+
{{- end }}
46+
{{- end }}
Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
1-
{{- if and .Values.proxy.enabled .Values.proxy.config.metrics.enabled }}
1+
{{- if and .Values.proxy.enabled .Values.metrics.enabled }}
22
apiVersion: v1
33
kind: Service
44
metadata:
55
name: {{ include "chorus.fullname" . }}-proxy-metrics
66
labels:
7-
app: proxy
8-
{{- include "chorus.labels" . | nindent 4 }}
7+
{{- include "chorus.labels" . | nindent 4 }}
8+
app.kubernetes.io/component: proxy
9+
chorus.clyso.com/metrics: "true"
10+
{{- with (include "chorus.annotations" (list dict .)) }}
11+
annotations:
12+
{{- . | nindent 4 }}
13+
{{- end }}
914
spec:
1015
type: ClusterIP
1116
selector:
12-
app: proxy
13-
{{- include "chorus.selectorLabels" . | nindent 4 }}
17+
{{- include "chorus.selectorLabels" . | nindent 4 }}
18+
app.kubernetes.io/component: proxy
1419
ports:
1520
- name: metrics
16-
port: 9090
21+
port: {{ include "chorus.metricsPort" . }}
1722
targetPort: metrics
18-
{{- end }}
23+
{{- end }}

‎deploy/chorus/templates/proxy/service-proxy.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ metadata:
66
labels:
77
{{- include "chorus.labels" . | nindent 4 }}
88
app.kubernetes.io/component: proxy
9-
{{- with .Values.proxy.service.annotations }}
9+
{{- with (include "chorus.annotations" (list .Values.proxy.service.annotations .)) }}
1010
annotations:
11-
{{- toYaml . | nindent 4 }}
11+
{{- . | nindent 4 }}
1212
{{- end }}
1313
spec:
1414
type: {{ .Values.proxy.service.type }}

0 commit comments

Comments
 (0)