Skip to content

Commit 61a2a37

Browse files
committed
feat: simple mtr-exporter chart
1 parent 26aa02d commit 61a2a37

File tree

12 files changed

+408
-0
lines changed

12 files changed

+408
-0
lines changed

sickhub/mtr-exporter/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

sickhub/mtr-exporter/Chart.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v2
2+
name: mtr-exporter
3+
description: A Helm chart for an mtr-exporter pod providing metrics.
4+
type: application
5+
version: 0.0.1
6+
# https://github.com/mgumz/mtr-exporter
7+
# https://hub.docker.com/r/dragoonaethis/mtr-exporter
8+
# TODO: create new regularly updated image
9+
appVersion: "0.3.0"
10+
home: https://github.com/SickHub
11+
keywords:
12+
- mtr
13+
- exporter
14+
sources:
15+
- https://github.com/SickHub/charts
16+
maintainers:
17+
- name: SickHub
18+
email: drpsychick@drsick.net
19+
url: https://github.com/SickHub
20+
annotations:
21+
artifacthub.io/links: |
22+
- name: mtr-exporter image
23+
url: https://hub.docker.com/r/dragoonaethis/mtr-exporter

sickhub/mtr-exporter/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# mtr-exporter Helm Chart
2+
3+
A chart that lets you run an mtr-exporter to monitor routes.
4+
5+
## Deploy mtr-exporter
6+
7+
Configure `exporterJobs` in `values.yaml` to do MTRs regularly with given options to certain destinations.
8+
9+
```shell
10+
helm repo add sickhub https://sickhub.github.io/charts
11+
helm repo update
12+
helm search repo sickhub
13+
helm upgrade --create-namespace --namespace test --install --values values.yaml mtr-exporter sickhub/mtr-exporter
14+
```
15+
16+
## Test locally
17+
18+
### Lint and template
19+
20+
```shell
21+
(cd ..; ct lint --chart-dirs . --charts mtr-exporter)
22+
helm template test . -f ci/test-values.yaml
23+
```
24+
25+
### Test on local k8s
26+
```shell
27+
helm upgrade -i mtr-exporter . -f ci/test-values.yaml
28+
```
29+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
exporterJobs:
2+
- label: "mtr-example.com"
3+
mtrFlags: "-z -G 1 example.com"
4+
- label: "mtr-quad8"
5+
schedule: "@every 10s"
6+
mtrFlags: "-z -G 1 -n 8.8.8.8"
7+
volumeMounts:
8+
- mountPath: /test
9+
name: test
10+
volumes:
11+
- name: test
12+
emptyDir: {}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
1. Get the application URL by running these commands:
2+
{{- if contains "NodePort" .Values.service.type }}
3+
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "mtr-exporter.fullname" . }})
4+
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
5+
echo http://$NODE_IP:$NODE_PORT
6+
{{- else if contains "LoadBalancer" .Values.service.type }}
7+
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
8+
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "mtr-exporter.fullname" . }}'
9+
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "mtr-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
10+
echo http://$SERVICE_IP:{{ .Values.service.port }}
11+
{{- else if contains "ClusterIP" .Values.service.type }}
12+
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "mtr-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
13+
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
14+
echo "Visit http://127.0.0.1:8080 to use your application"
15+
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
16+
{{- end }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{{/*
2+
Expand the name of the chart.
3+
*/}}
4+
{{- define "mtr-exporter.name" -}}
5+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
6+
{{- end }}
7+
8+
{{/*
9+
Create a default fully qualified app name.
10+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
11+
If release name contains chart name it will be used as a full name.
12+
*/}}
13+
{{- define "mtr-exporter.fullname" -}}
14+
{{- if .Values.fullnameOverride }}
15+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
16+
{{- else }}
17+
{{- $name := default .Chart.Name .Values.nameOverride }}
18+
{{- if contains $name .Release.Name }}
19+
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
20+
{{- else }}
21+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
22+
{{- end }}
23+
{{- end }}
24+
{{- end }}
25+
26+
{{/*
27+
Create chart name and version as used by the chart label.
28+
*/}}
29+
{{- define "mtr-exporter.chart" -}}
30+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
31+
{{- end }}
32+
33+
{{/*
34+
Common labels
35+
*/}}
36+
{{- define "mtr-exporter.labels" -}}
37+
helm.sh/chart: {{ include "mtr-exporter.chart" . }}
38+
{{ include "mtr-exporter.selectorLabels" . }}
39+
{{- if .Chart.AppVersion }}
40+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
41+
{{- end }}
42+
app.kubernetes.io/managed-by: {{ .Release.Service }}
43+
{{- end }}
44+
45+
{{/*
46+
Selector labels
47+
*/}}
48+
{{- define "mtr-exporter.selectorLabels" -}}
49+
app.kubernetes.io/name: {{ include "mtr-exporter.name" . }}
50+
app.kubernetes.io/instance: {{ .Release.Name }}
51+
{{- end }}
52+
53+
{{/*
54+
Create the name of the service account to use
55+
*/}}
56+
{{- define "mtr-exporter.serviceAccountName" -}}
57+
{{- if .Values.serviceAccount.create }}
58+
{{- default (include "mtr-exporter.fullname" .) .Values.serviceAccount.name }}
59+
{{- else }}
60+
{{- default "default" .Values.serviceAccount.name }}
61+
{{- end }}
62+
{{- end }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{{- $checksum := toYaml .Values.exporterJobs | sha256sum | trunc 20 | quote }}
2+
---
3+
apiVersion: "v1"
4+
kind: "ConfigMap"
5+
metadata:
6+
name: {{ include "mtr-exporter.fullname" . }}
7+
labels:
8+
{{- include "mtr-exporter.labels" . | nindent 4 }}
9+
annotations:
10+
values/checksum: {{ $checksum }}
11+
data:
12+
mtr-exporter.jobs: |-
13+
# do not modify, generated from values.yaml by helm chart
14+
{{- range .Values.exporterJobs }}
15+
{{ .label }} -- {{ default "@every 60s" .schedule }} -- {{ .mtrFlags }}
16+
{{- end }}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{{- $checksum := toYaml .Values.exporterJobs | sha256sum | trunc 20 | quote }}
2+
---
3+
apiVersion: apps/v1
4+
kind: Deployment
5+
metadata:
6+
name: {{ include "mtr-exporter.fullname" . }}
7+
labels:
8+
{{- include "mtr-exporter.labels" . | nindent 4 }}
9+
annotations:
10+
values/checksum: {{ $checksum }}
11+
spec:
12+
replicas: {{ .Values.replicaCount }}
13+
selector:
14+
matchLabels:
15+
{{- include "mtr-exporter.selectorLabels" . | nindent 6 }}
16+
template:
17+
metadata:
18+
{{- with .Values.podAnnotations }}
19+
annotations:
20+
{{- toYaml . | nindent 8 }}
21+
{{- end }}
22+
labels:
23+
{{- include "mtr-exporter.labels" . | nindent 8 }}
24+
{{- with .Values.podLabels }}
25+
{{- toYaml . | nindent 8 }}
26+
{{- end }}
27+
spec:
28+
{{- with .Values.imagePullSecrets }}
29+
imagePullSecrets:
30+
{{- toYaml . | nindent 8 }}
31+
{{- end }}
32+
serviceAccountName: {{ include "mtr-exporter.serviceAccountName" . }}
33+
securityContext:
34+
{{- toYaml .Values.podSecurityContext | nindent 8 }}
35+
containers:
36+
- name: {{ .Chart.Name }}
37+
args:
38+
- '-jobs'
39+
- /configMaps/mtr-exporter.jobs
40+
securityContext:
41+
{{- toYaml .Values.securityContext | nindent 12 }}
42+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
43+
imagePullPolicy: {{ .Values.image.pullPolicy }}
44+
ports:
45+
- name: http
46+
containerPort: 8080
47+
protocol: TCP
48+
livenessProbe:
49+
{{- toYaml .Values.livenessProbe | nindent 12 }}
50+
readinessProbe:
51+
{{- toYaml .Values.readinessProbe | nindent 12 }}
52+
resources:
53+
{{- toYaml .Values.resources | nindent 12 }}
54+
volumeMounts:
55+
- mountPath: /configMaps/mtr-exporter.jobs
56+
name: mtr-exporter-jobs
57+
subPath: mtr-exporter.jobs
58+
{{- with .Values.volumeMounts }}
59+
{{- toYaml . | nindent 12 }}
60+
{{- end }}
61+
volumes:
62+
- name: mtr-exporter-jobs
63+
configMap:
64+
name: {{ include "mtr-exporter.fullname" . }}
65+
{{- with .Values.volumes }}
66+
{{- toYaml . | nindent 8 }}
67+
{{- end }}
68+
{{- with .Values.nodeSelector }}
69+
nodeSelector:
70+
{{- toYaml . | nindent 8 }}
71+
{{- end }}
72+
{{- with .Values.affinity }}
73+
affinity:
74+
{{- toYaml . | nindent 8 }}
75+
{{- end }}
76+
{{- with .Values.tolerations }}
77+
tolerations:
78+
{{- toYaml . | nindent 8 }}
79+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "mtr-exporter.fullname" . }}
5+
labels:
6+
{{- include "mtr-exporter.labels" . | nindent 4 }}
7+
spec:
8+
type: {{ .Values.service.type }}
9+
ports:
10+
- port: {{ .Values.service.port }}
11+
targetPort: http
12+
protocol: TCP
13+
name: http
14+
selector:
15+
{{- include "mtr-exporter.selectorLabels" . | nindent 4 }}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{{- if .Values.serviceAccount.create -}}
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: {{ include "mtr-exporter.serviceAccountName" . }}
6+
labels:
7+
{{- include "mtr-exporter.labels" . | nindent 4 }}
8+
{{- with .Values.serviceAccount.annotations }}
9+
annotations:
10+
{{- toYaml . | nindent 4 }}
11+
{{- end }}
12+
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
13+
{{- end }}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: "{{ include "mtr-exporter.fullname" . }}-test-connection"
5+
labels:
6+
{{- include "mtr-exporter.labels" . | nindent 4 }}
7+
annotations:
8+
"helm.sh/hook": test
9+
spec:
10+
containers:
11+
- name: wget
12+
image: busybox
13+
command: ['wget']
14+
args: ['{{ include "mtr-exporter.fullname" . }}:{{ .Values.service.port }}/metrics']
15+
restartPolicy: Never

0 commit comments

Comments
 (0)