diff --git a/README.md b/README.md index 8e558ab..c3bcc0d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/sickhub/mtr-exporter/.helmignore b/sickhub/mtr-exporter/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/sickhub/mtr-exporter/.helmignore @@ -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/ diff --git a/sickhub/mtr-exporter/Chart.yaml b/sickhub/mtr-exporter/Chart.yaml new file mode 100644 index 0000000..d40a4b4 --- /dev/null +++ b/sickhub/mtr-exporter/Chart.yaml @@ -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 diff --git a/sickhub/mtr-exporter/README.md b/sickhub/mtr-exporter/README.md new file mode 100644 index 0000000..dd46962 --- /dev/null +++ b/sickhub/mtr-exporter/README.md @@ -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/) diff --git a/sickhub/mtr-exporter/ci/test-values.yaml b/sickhub/mtr-exporter/ci/test-values.yaml new file mode 100644 index 0000000..828aa25 --- /dev/null +++ b/sickhub/mtr-exporter/ci/test-values.yaml @@ -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: {} diff --git a/sickhub/mtr-exporter/icon.png b/sickhub/mtr-exporter/icon.png new file mode 100644 index 0000000..2644c45 Binary files /dev/null and b/sickhub/mtr-exporter/icon.png differ diff --git a/sickhub/mtr-exporter/templates/NOTES.txt b/sickhub/mtr-exporter/templates/NOTES.txt new file mode 100644 index 0000000..40a7123 --- /dev/null +++ b/sickhub/mtr-exporter/templates/NOTES.txt @@ -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 }} diff --git a/sickhub/mtr-exporter/templates/_helpers.tpl b/sickhub/mtr-exporter/templates/_helpers.tpl new file mode 100644 index 0000000..281b5dd --- /dev/null +++ b/sickhub/mtr-exporter/templates/_helpers.tpl @@ -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 }} diff --git a/sickhub/mtr-exporter/templates/configmap.yaml b/sickhub/mtr-exporter/templates/configmap.yaml new file mode 100644 index 0000000..f7038c1 --- /dev/null +++ b/sickhub/mtr-exporter/templates/configmap.yaml @@ -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 }} diff --git a/sickhub/mtr-exporter/templates/deployment.yaml b/sickhub/mtr-exporter/templates/deployment.yaml new file mode 100644 index 0000000..5eefc9e --- /dev/null +++ b/sickhub/mtr-exporter/templates/deployment.yaml @@ -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 }} diff --git a/sickhub/mtr-exporter/templates/service.yaml b/sickhub/mtr-exporter/templates/service.yaml new file mode 100644 index 0000000..421fc79 --- /dev/null +++ b/sickhub/mtr-exporter/templates/service.yaml @@ -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 }} diff --git a/sickhub/mtr-exporter/templates/serviceaccount.yaml b/sickhub/mtr-exporter/templates/serviceaccount.yaml new file mode 100644 index 0000000..540bd29 --- /dev/null +++ b/sickhub/mtr-exporter/templates/serviceaccount.yaml @@ -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 }} diff --git a/sickhub/mtr-exporter/templates/tests/test-connection.yaml b/sickhub/mtr-exporter/templates/tests/test-connection.yaml new file mode 100644 index 0000000..0fd1126 --- /dev/null +++ b/sickhub/mtr-exporter/templates/tests/test-connection.yaml @@ -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 diff --git a/sickhub/mtr-exporter/values.yaml b/sickhub/mtr-exporter/values.yaml new file mode 100644 index 0000000..07f92e9 --- /dev/null +++ b/sickhub/mtr-exporter/values.yaml @@ -0,0 +1,105 @@ +# Default values for mtr-exporter. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/ +replicaCount: 1 + +# This sets the container image more information can be found here: https://kubernetes.io/docs/concepts/containers/images/ +image: + repository: ghcr.io/mgumz/mtr-exporter + # This sets the pull policy for images. + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +# This is for the secretes for pulling an image from a private repository more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/ +imagePullSecrets: [] +# This is to override the chart name. +nameOverride: "" +fullnameOverride: "" + +# Define mtr-exporter jobs +# see https://github.com/mgumz/mtr-exporter?tab=readme-ov-file#jobs-file-syntax +exporterJobs: [] +# - label: "example.com" +# schedule: "@every 120s" +# mtrFlags: "-G 1 example.com" + +# This section builds out the service account more information can be found here: https://kubernetes.io/docs/concepts/security/service-accounts/ +serviceAccount: + # Specifies whether a service account should be created + create: true + # Automatically mount a ServiceAccount's API credentials? + automount: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +# This is for setting Kubernetes Annotations to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/ +podAnnotations: {} +# This is for setting Kubernetes Labels to a Pod. +# For more information checkout: https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ +podLabels: {} + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +# This is for setting up a service more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/ +service: + # This sets the service type more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types + type: ClusterIP + # This sets the ports more information can be found here: https://kubernetes.io/docs/concepts/services-networking/service/#field-spec-ports + port: 80 + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/ +livenessProbe: + httpGet: + path: /metrics + port: http +readinessProbe: + httpGet: + path: /metrics + port: http + +# Additional volumes on the output Deployment definition. +volumes: [] +# - name: foo +# secret: +# secretName: mysecret +# optional: false + +# Additional volumeMounts on the output Deployment definition. +volumeMounts: [] +# - name: foo +# mountPath: "/etc/foo" +# readOnly: true + +nodeSelector: {} + +tolerations: [] + +affinity: {}