Skip to content

Commit

Permalink
feat: simple mtr-exporter chart (#84)
Browse files Browse the repository at this point in the history
based on https://github.com/mgumz/mtr-exporter and ghcr.io/mgumz/mtr-exporter
  • Loading branch information
DrPsychick authored Dec 22, 2024
1 parent 26aa02d commit 78f590d
Show file tree
Hide file tree
Showing 14 changed files with 413 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
[![GitHub pull requests](https://img.shields.io/github/issues-pr/sickhub/charts.svg)](https://github.com/sickhub/charts/pulls)
[![GitHub closed pull requests](https://img.shields.io/github/issues-pr-closed/sickhub/charts.svg)](https://github.com/sickhub/charts/pulls?q=is%3Apr+is%3Aclosed)

## Generic charts, like `cronjobs`, `nginx-phpfpm`
## Generic charts, like `cronjobs`, `nginx-phpfpm`, `mtr-exporter`
* requires helm v3

```shell script
Expand Down
23 changes: 23 additions & 0 deletions sickhub/mtr-exporter/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
23 changes: 23 additions & 0 deletions sickhub/mtr-exporter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: mtr-exporter
description: A Helm chart for an mtr-exporter pod providing metrics.
type: application
version: 0.0.1
# https://github.com/mgumz/mtr-exporter
# https://github.com/mgumz/mtr-exporter/pkgs/container/mtr-exporter
appVersion: "0.4.0"
home: https://github.com/SickHub
icon: https://raw.githubusercontent.com/SickHub/charts/master/sickhub/mtr-exporter/icon.png
keywords:
- mtr
- exporter
sources:
- https://github.com/SickHub/charts
maintainers:
- name: SickHub
email: drpsychick@drsick.net
url: https://github.com/SickHub
annotations:
artifacthub.io/links: |
- name: mtr-exporter image
url: https://github.com/mgumz/mtr-exporter/pkgs/container/mtr-exporter
31 changes: 31 additions & 0 deletions sickhub/mtr-exporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# mtr-exporter Helm Chart

A chart that lets you run an mtr-exporter to monitor routes.

## Deploy mtr-exporter

Configure `exporterJobs` in `values.yaml` to do MTRs regularly with given options to certain destinations.

```shell
helm repo add sickhub https://sickhub.github.io/charts
helm repo update
helm search repo sickhub
helm upgrade --create-namespace --namespace test --install --values values.yaml mtr-exporter sickhub/mtr-exporter
```

## Test locally

### Lint and template

```shell
(cd ..; ct lint --chart-dirs . --charts mtr-exporter)
helm template test . -f ci/test-values.yaml
```

### Test on local k8s
```shell
helm upgrade -i mtr-exporter . -f ci/test-values.yaml
```

## Credits
* Icon from [Smashicons](https://www.flaticon.com/authors/smashicons) found on [FlatIcon](https://www.flaticon.com/)
12 changes: 12 additions & 0 deletions sickhub/mtr-exporter/ci/test-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
exporterJobs:
- label: "mtr-example.com"
mtrFlags: "-z -G 1 example.com"
- label: "mtr-quad8"
schedule: "@every 10s"
mtrFlags: "-z -G 1 -n 8.8.8.8"
volumeMounts:
- mountPath: /test
name: test
volumes:
- name: test
emptyDir: {}
Binary file added sickhub/mtr-exporter/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions sickhub/mtr-exporter/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
1. Get the application URL by running these commands:
{{- if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "mtr-exporter.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "mtr-exporter.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "mtr-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
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}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions sickhub/mtr-exporter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "mtr-exporter.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "mtr-exporter.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "mtr-exporter.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "mtr-exporter.labels" -}}
helm.sh/chart: {{ include "mtr-exporter.chart" . }}
{{ include "mtr-exporter.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "mtr-exporter.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mtr-exporter.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "mtr-exporter.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "mtr-exporter.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
16 changes: 16 additions & 0 deletions sickhub/mtr-exporter/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- $checksum := toYaml .Values.exporterJobs | sha256sum | trunc 20 | quote }}
---
apiVersion: "v1"
kind: "ConfigMap"
metadata:
name: {{ include "mtr-exporter.fullname" . }}
labels:
{{- include "mtr-exporter.labels" . | nindent 4 }}
annotations:
values/checksum: {{ $checksum }}
data:
mtr-exporter.jobs: |-
# do not modify, generated from values.yaml by helm chart
{{- range .Values.exporterJobs }}
{{ .label }} -- {{ default "@every 60s" .schedule }} -- {{ .mtrFlags }}
{{- end }}
81 changes: 81 additions & 0 deletions sickhub/mtr-exporter/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{{- $checksum := toYaml .Values.exporterJobs | sha256sum | trunc 20 | quote }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "mtr-exporter.fullname" . }}
labels:
{{- include "mtr-exporter.labels" . | nindent 4 }}
annotations:
values/checksum: {{ $checksum }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "mtr-exporter.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "mtr-exporter.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "mtr-exporter.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
command:
- /usr/bin/mtr-exporter
args:
- '-jobs'
- /configMaps/mtr-exporter.jobs
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: 8080
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- mountPath: /configMaps/mtr-exporter.jobs
name: mtr-exporter-jobs
subPath: mtr-exporter.jobs
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
volumes:
- name: mtr-exporter-jobs
configMap:
name: {{ include "mtr-exporter.fullname" . }}
{{- with .Values.volumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
15 changes: 15 additions & 0 deletions sickhub/mtr-exporter/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "mtr-exporter.fullname" . }}
labels:
{{- include "mtr-exporter.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: http
protocol: TCP
name: http
selector:
{{- include "mtr-exporter.selectorLabels" . | nindent 4 }}
13 changes: 13 additions & 0 deletions sickhub/mtr-exporter/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "mtr-exporter.serviceAccountName" . }}
labels:
{{- include "mtr-exporter.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
15 changes: 15 additions & 0 deletions sickhub/mtr-exporter/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "mtr-exporter.fullname" . }}-test-connection"
labels:
{{- include "mtr-exporter.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "mtr-exporter.fullname" . }}:{{ .Values.service.port }}/metrics']
restartPolicy: Never
Loading

0 comments on commit 78f590d

Please sign in to comment.