Skip to content

Commit

Permalink
Add helm chart for rabbitmq-tester (#125)
Browse files Browse the repository at this point in the history
* Add helm chart for rabbitmq-tester

* Fix helm lint

* Pin image tag
  • Loading branch information
Stian Haugland authored Apr 27, 2021
1 parent 863e3f1 commit 173bf3b
Show file tree
Hide file tree
Showing 10 changed files with 452 additions and 1 deletion.
2 changes: 1 addition & 1 deletion node-dns-exporter/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ nodeDns:
#listenAddress: 0.0.0.0:8080
#testInterval: 120

alertFor: #3m
alertFor: #3m

# Sets the alertmanager instance as a label
# in case the chart is deployed in an environment with
Expand Down
23 changes: 23 additions & 0 deletions rabbitmq-tester/.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/
24 changes: 24 additions & 0 deletions rabbitmq-tester/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: rabbitmq-tester
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 1.0.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "main-980d6c5d"
63 changes: 63 additions & 0 deletions rabbitmq-tester/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "rabbitmq-tester.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 "rabbitmq-tester.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 "rabbitmq-tester.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "rabbitmq-tester.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "rabbitmq-tester.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
33 changes: 33 additions & 0 deletions rabbitmq-tester/templates/alert-rules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{- if .Values.alert.alertmanagerEnabled }}
apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
name: {{ template "rabbitmq-tester.name" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "rabbitmq-tester.labels" . | nindent 4 }}
alertmanager: {{ .Values.alert.alertManager | default "default" }}
spec:
groups:
- name: Rabbitmq-tester
rules:
- alert: FailedToConnectProducer
annotations:
message: |-
{{`Producer: {{$labels.pod}}({{$labels.node}}) failed to connect to Rabbitmq`}}
expr: 'sum(rabbitmq_test_produce_consume{status="failed",kind="producer"}>0) BY (pod,node,namespace,job,status)'
for: {{ .Values.alert.for | default "3m" }}
labels:
serverity: error
- alert: FailedToConnectConsumer
annotations:
message: |-
{{`Consumer: {{$labels.pod}}({{$labels.node}}) failed to connect to Rabbitmq`}}
expr: 'sum(rabbitmq_test_produce_consume{status="failed",kind="consumer"}>0) BY (pod,node,namespace,job,status)'
for: {{ .Values.alert.for | default "3m" }}
labels:
serverity: error
{{- if .Values.customAlertRules }}
{{ toYaml .Values.customAlertRules | indent 4 }}
{{- end }}
{{- end }}
73 changes: 73 additions & 0 deletions rabbitmq-tester/templates/consumer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: {{ include "rabbitmq-tester.fullname" . }}-consumer
labels:
{{- include "rabbitmq-tester.labels" . | nindent 4 }}
app.kubernetes.io/component: consumer
spec:
selector:
matchLabels:
{{- include "rabbitmq-tester.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: consumer
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "rabbitmq-tester.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: consumer
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "rabbitmq-tester.serviceAccountName" . }}-consumer
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
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:
httpGet:
path: /metrics
port: http
readinessProbe:
httpGet:
path: /metrics
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
args:
- "--listen-address={{ .Values.rabbitmqTester.listenAddress | default "0.0.0.0:8080" }}"
- "--rabbitmq-address={{ .Values.rabbitmqTester.rabbitmqAddress | default "amqp://guest:guest@localhost:5672/"}}"
- "--exchange-name={{ .Values.rabbitmqTester.exchangeName | default "rabbitmq-test-exchange" }}"
- "--is-producer=false"
- "--test-interval-seconds={{ .Values.rabbitmqTester.testInterval | default "120" }}"
- "--node-name={{ .Values.rabbitmqTester.nodeName | default "$(NODE_NAME)" }}"
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
47 changes: 47 additions & 0 deletions rabbitmq-tester/templates/podmonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{- if .Values.metrics.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: {{ template "rabbitmq-tester.fullname" . }}-consumer
labels:
{{- include "rabbitmq-tester.labels" . | nindent 4 }}
app.kubernetes.io/component: consumer
spec:
jobLabel: {{ template "rabbitmq-tester.fullname" . }}-consumer
selector:
matchLabels:
{{- include "rabbitmq-tester.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: consumer
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
podMetricsEndpoints:
- port: http
path: /metrics
interval: {{ .Values.metrics.interval | default "15s"}}
{{- end }}

---

{{- if .Values.metrics.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: PodMonitor
metadata:
name: {{ template "rabbitmq-tester.fullname" . }}-producer
labels:
{{- include "rabbitmq-tester.labels" . | nindent 4 }}
app.kubernetes.io/component: producer
spec:
jobLabel: {{ template "rabbitmq-tester.fullname" . }}-producer
selector:
matchLabels:
{{- include "rabbitmq-tester.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: producer
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
podMetricsEndpoints:
- port: http
path: /metrics
interval: {{ .Values.metrics.interval | default "15s"}}
{{- end }}
73 changes: 73 additions & 0 deletions rabbitmq-tester/templates/producer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "rabbitmq-tester.fullname" .}}-producer
labels:
{{- include "rabbitmq-tester.labels" . | nindent 4 }}
app.kubernetes.io/component: producer
spec:
selector:
matchLabels:
{{- include "rabbitmq-tester.selectorLabels" . | nindent 6 }}
app.kubernetes.io/component: producer
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "rabbitmq-tester.selectorLabels" . | nindent 8 }}
app.kubernetes.io/component: producer
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "rabbitmq-tester.serviceAccountName" . }}-producer
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
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:
httpGet:
path: /metrics
port: http
readinessProbe:
httpGet:
path: /metrics
port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
args:
- "--listen-address={{ .Values.rabbitmqTester.listenAddress | default "0.0.0.0:8080" }}"
- "--rabbitmq-address={{ .Values.rabbitmqTester.rabbitmqAddress | default "amqp://guest:guest@localhost:5672/"}}"
- "--exchange-name={{ .Values.rabbitmqTester.exchangeName | default "rabbitmq-test-exchange" }}"
- "--is-producer=true"
- "--test-interval-seconds={{ .Values.rabbitmqTester.testInterval | default "120" }}"
- "--node-name={{ .Values.rabbitmqTester.nodeName | default "$(NODE_NAME)" }}"
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
29 changes: 29 additions & 0 deletions rabbitmq-tester/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "rabbitmq-tester.serviceAccountName" . }}-consumer
labels:
{{- include "rabbitmq-tester.labels" . | nindent 4 }}
app.kubernetes.io/component: consumer
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

---

{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "rabbitmq-tester.serviceAccountName" . }}-producer
labels:
{{- include "rabbitmq-tester.labels" . | nindent 4 }}
app.kubernetes.io/component: producer
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit 173bf3b

Please sign in to comment.