Skip to content

Commit

Permalink
Merge pull request #93 from JacekZubielik/mosquitto
Browse files Browse the repository at this point in the history
chore(cleanup): code
  • Loading branch information
JacekZubielik authored Aug 22, 2024
2 parents d0a897d + f4d6a22 commit 9fc334c
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 0 deletions.
15 changes: 15 additions & 0 deletions charts/eclipse-mosquitto/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v2
appVersion: 2.0.18
description: Eclipse Mosquitto MQTT
name: mosquitto
version: 0.0.1
type: application
keywords:
- mqtt
- mosquitto
home: https://github.com/JacekZubielik/jz-helm-charts/tree/master/charts/eclipse-mosquitto
icon: https://raw.githubusercontent.com/eclipse/mosquitto/master/logo/mosquitto-logo-min.svg
sources:
- https://github.com/eclipse/mosquitto
maintainers:
- name: jacekzubielik
45 changes: 45 additions & 0 deletions charts/eclipse-mosquitto/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "eclipse-mosquitto.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 "eclipse-mosquitto.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 "eclipse-mosquitto.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Common labels
*/}}
{{- define "eclipse-mosquitto.labels" -}}
app.kubernetes.io/name: {{ include "eclipse-mosquitto.name" . }}
helm.sh/chart: {{ include "eclipse-mosquitto.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}
13 changes: 13 additions & 0 deletions charts/eclipse-mosquitto/templates/configmap-certs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "eclipse-mosquitto.fullname" . }}-certs
labels:
{{ include "eclipse-mosquitto.labels" . | indent 4 }}
data:
ca.crt: |-
{{- .Values.certs.ca.crt | nindent 4 }}
server.crt: |-
{{- .Values.certs.server.crt | nindent 4 }}
server.key: |-
{{- .Values.certs.server.key | nindent 4 }}
9 changes: 9 additions & 0 deletions charts/eclipse-mosquitto/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "eclipse-mosquitto.fullname" . }}-config
labels:
{{ include "eclipse-mosquitto.labels" . | indent 4 }}
data:
mosquitto.conf: |-
{{- .Values.config | nindent 4 }}
111 changes: 111 additions & 0 deletions charts/eclipse-mosquitto/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "eclipse-mosquitto.fullname" . }}
labels:
{{ include "eclipse-mosquitto.labels" . | indent 4 }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "eclipse-mosquitto.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "eclipse-mosquitto.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if .Values.securityContext.enabled }}
securityContext:
fsGroup: {{ .Values.securityContext.fsGroup }}
runAsUser: {{ .Values.securityContext.runAsUser }}
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: {{ .Values.container.ports.mqtt.name }}
containerPort: {{ .Values.container.ports.mqtt.port }}
protocol: TCP
- name: {{ .Values.container.ports.mqtts.name }}
containerPort: {{ .Values.container.ports.mqtts.port }}
protocol: TCP
livenessProbe:
tcpSocket:
port: {{ .Values.container.ports.mqtt.port }}
initialDelaySeconds: 5
periodSeconds: 15
readinessProbe:
tcpSocket:
port: {{ .Values.container.ports.mqtt.port }}
initialDelaySeconds: 5
periodSeconds: 10
volumeMounts:
- name: mosquitto-conf
mountPath: /mosquitto/config/mosquitto.conf
subPath: mosquitto.conf
readOnly: true
- name: mosquitto-ca-cert
mountPath: /mosquitto/config/certs/ca.crt
subPath: ca.crt
readOnly: true
- name: mosquitto-server-cert
mountPath: /mosquitto/config/certs/server.crt
subPath: server.crt
readOnly: true
- name: mosquitto-server-key
mountPath: /mosquitto/config/certs/server.key
subPath: server.key
readOnly: true
- name: mosquitto-data
mountPath: /mosquitto/data
subPath: mosquitto/data
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: mosquitto-conf
configMap:
name: {{ include "eclipse-mosquitto.fullname" . }}-config
- name: mosquitto-ca-cert
configMap:
name: {{ include "eclipse-mosquitto.fullname" . }}-certs
items:
- key: ca.crt
path: ca.crt
- name: mosquitto-server-cert
configMap:
name: {{ include "eclipse-mosquitto.fullname" . }}-certs
items:
- key: server.crt
path: server.crt
- name: mosquitto-server-key
configMap:
name: {{ include "eclipse-mosquitto.fullname" . }}-certs
items:
- key: server.key
path: server.key
- name: mosquitto-data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ include "eclipse-mosquitto.fullname" . }}-pvc
{{- else }}
emptyDir: {}
{{- 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 }}
37 changes: 37 additions & 0 deletions charts/eclipse-mosquitto/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "eclipse-mosquitto.fullname" . -}}
{{- $portName := .Values.service.ports.mqtts.name -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}-mqtt
labels:
{{ include "eclipse-mosquitto.labels" . | indent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $portName }}
{{- end }}
{{- end }}
{{- end }}
26 changes: 26 additions & 0 deletions charts/eclipse-mosquitto/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "eclipse-mosquitto.fullname" . }}-pvc
namespace: {{ .Release.Namespace }}
{{- with .Values.persistence.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
labels:
{{ include "eclipse-mosquitto.labels" . | indent 4 }}
spec:
accessModes:
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end }}
20 changes: 20 additions & 0 deletions charts/eclipse-mosquitto/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "eclipse-mosquitto.fullname" . }}
labels:
{{ include "eclipse-mosquitto.labels" . | indent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.ports.mqtt.port }}
targetPort: {{ .Values.container.ports.mqtt.name }}
protocol: TCP
name: {{ .Values.service.ports.mqtt.name }}
- port: {{ .Values.service.ports.mqtts.port }}
targetPort: {{ .Values.container.ports.mqtts.name }}
protocol: TCP
name: {{ .Values.service.ports.mqtts.name }}
selector:
app.kubernetes.io/name: {{ include "eclipse-mosquitto.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
15 changes: 15 additions & 0 deletions charts/eclipse-mosquitto/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 "eclipse-mosquitto.fullname" . }}-test-connection"
labels:
{{ include "eclipse-mosquitto.labels" . | indent 4 }}
annotations:
"helm.sh/hook": test-success
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "eclipse-mosquitto.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
Loading

0 comments on commit 9fc334c

Please sign in to comment.