Skip to content

Commit

Permalink
Merge pull request #9 from JacekZubielik/mosquitto
Browse files Browse the repository at this point in the history
chore(init): init
  • Loading branch information
JacekZubielik authored May 22, 2024
2 parents e62ee6f + 1261088 commit 98e1228
Show file tree
Hide file tree
Showing 11 changed files with 578 additions and 0 deletions.
15 changes: 15 additions & 0 deletions charts/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
21 changes: 21 additions & 0 deletions charts/mosquitto/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "app.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 the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "app.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "app.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
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 "app.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
51 changes: 51 additions & 0 deletions charts/mosquitto/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/* Expand the name of the chart. */}}
{{- define "app.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 "app.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 "app.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/* Common labels */}}
{{- define "app.labels" -}}
app.kubernetes.io/name: {{ include "app.name" . }}
helm.sh/chart: {{ include "app.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

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

{{/* Create the name of the service account to use */}}
{{- define "app.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "app.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
166 changes: 166 additions & 0 deletions charts/mosquitto/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
apiVersion: apps/v1
kind: Deployment
metadata:
{{- if .Values.service.annotations }}
annotations:
{{- toYaml .Values.service.annotations | nindent 4 }}
{{- end }}
name: {{ include "app.fullname" . }}
labels:
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
replicas: {{ .Values.replicas }}
revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
strategy:
type: {{ .Values.strategyType }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
serviceAccountName: {{ include "app.serviceAccountName" . }}
{{- if .Values.securityContext.enabled }}
securityContext:
runAsUser: {{ .Values.securityContext.runAsUser }}
runAsGroup: {{ .Values.securityContext.runAsGrop }}
fsGroup: {{ .Values.securityContext.fsGroup }}
{{- end }}
initContainers:
- name: init-config
image: busybox
command: ["/bin/cp", "-v", "/tmp/password_file", "/mosquitto/password_file"]
securityContext:
runAsNonRoot: false
privileged: true
volumeMounts:
- name: mosquitto-passwd
mountPath: /tmp/password_file
subPath: password_file
- name: mosquitto-data
mountPath: /mosquitto
- name: setup-permissions
image: busybox
command: ["/bin/chown", "-R", "1883:1883", "/mosquitto"]
securityContext:
runAsUser: 0
privileged: true
volumeMounts:
- name: mosquitto-data
mountPath: /mosquitto
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: [ "mosquitto", "-c", "/mosquitto/config/mosquitto.conf" ]
ports:
- name: mqtt
containerPort: {{ .Values.service.mqttPort }}
protocol: TCP
- name: mqtts
containerPort: {{ .Values.service.mqttsPort }}
protocol: TCP
- name: metrics
containerPort: {{ .Values.service.metricsPort }}
protocol: TCP
{{- if .Values.livenessProbe.enabled }}
livenessProbe:
httpGet:
path: /
port: {{ .Values.service.mqttPort }}
scheme: {{ .Values.livenessProbe.scheme }}
periodSeconds: {{ .Values.livenessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }}
successThreshold: {{ .Values.livenessProbe.successThreshold }}
failureThreshold: {{ .Values.livenessProbe.failureThreshold }}
initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds}}
{{- end }}
{{- if .Values.readinessProbe.enabled }}
readinessProbe:
httpGet:
path: /
port: {{ .Values.service.mqttPort }}
scheme: {{ .Values.livenessProbe.scheme }}
periodSeconds: {{ .Values.readinessProbe.periodSeconds }}
timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }}
successThreshold: {{ .Values.readinessProbe.successThreshold }}
failureThreshold: {{ .Values.readinessProbe.failureThreshold }}
initialDelaySeconds: {{ .Values.readinessProbe.initialDelaySeconds}}
{{- end }}
volumeMounts:
- name: mosquitto-conf
mountPath: /mosquitto/config/mosquitto.conf
subPath: mosquitto.conf
- name: mosquitto-passwd
mountPath: /mosquitto/password_file
subPath: password_file
- name: mosquitto-ca-cert
mountPath: /mosquitto/config/certs/ca.crt
subPath: ca.crt
- name: mosquitto-server-cert
mountPath: /mosquitto/config/certs/server.crt
subPath: server.crt
- name: mosquitto-server-key
mountPath: /mosquitto/config/certs/server.key
subPath: server.key
readOnly: true
- name: mosquitto-data
mountPath: /mosquitto
subPath: mosquitto
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumes:
- name: mosquitto-passwd
secret:
secretName: mosquitto-secrets
items:
- key: password_file
path: password_file
mode: 0644
- name: mosquitto-conf
configMap:
name: {{ include "app.fullname" . }}
- name: mosquitto-ca-cert
secret:
secretName: mosquitto-ca-cert
- name: mosquitto-server-cert
secret:
secretName: mosquitto-server-cert
- name: mosquitto-server-key
secret:
secretName: mosquitto-server-key
- name: mosquitto-data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ include "app.fullname" . }}
{{- 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/mosquitto/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "app.fullname" . -}}
{{- $portName := .Values.service.ports.mqtts.name -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{ include "app.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 }}
- {{ . }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: {{ $fullName }}
servicePort: {{ $portName }}
{{- end }}
{{- end }}
{{- end }}
25 changes: 25 additions & 0 deletions charts/mosquitto/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "app.fullname" . }} #
{{- with .Values.persistence.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
labels:
{{ include "app.labels" . | indent 4 }}
spec:
accessModes:
- {{ .Values.persistence.accessMode }}
resources:
requests:
storage: {{ .Values.persistence.size }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end }}
46 changes: 46 additions & 0 deletions charts/mosquitto/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
apiVersion: v1
kind: Service
metadata:
{{- if .Values.service.annotations }}
annotations:
{{- toYaml .Values.service.annotations | nindent 4 }}
{{- end }}
name: {{ include "app.fullname" . }}
labels:
{{- include "app.labels" . | nindent 4 }}
{{- if .Values.service.labels }}
{{ toYaml .Values.service.labels | indent 4 }}
{{- end }}
spec:
type: {{ .Values.service.type }}
{{- if .Values.service.externalIPs }}
externalIPs:
{{- toYaml .Values.service.externalIPs | nindent 4 }}
{{- end }}
{{- if .Values.service.externalTrafficPolicy }}
externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }}
{{- end }}
{{- if .Values.service.loadBalancerIP }}
loadBalancerIP: {{ .Values.service.loadBalancerIP }}
{{- end }}
{{- if .Values.service.loadBalancerSourceRanges }}
loadBalancerSourceRanges:
{{- toYaml .Values.service.loadBalancerSourceRanges | nindent 4 }}
{{- end }}
publishNotReadyAddresses: {{ .Values.service.publishNotReadyAddresses }}
ports:
- name: mqtt
port: {{ .Values.service.mqttPort }}
targetPort: {{ .Values.service.mqtt }}
protocol: TCP
- name: mqtts
port: {{ .Values.service.mqttsPort }}
targetPort: {{ .Values.service.mqttsPort }}
protocol: TCP
- name: metrics
port: {{ .Values.service.metricsPort }}
targetPort: {{ .Values.service.metricsPort }}
protocol: TCP
selector:
app.kubernetes.io/name: {{ include "app.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
16 changes: 16 additions & 0 deletions charts/mosquitto/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
{{- if .Values.serviceAccount.annotations }}
annotations:
{{- toYaml .Values.serviceAccount.annotations | nindent 4 }}
{{- end }}
name: {{ template "app.fullname" . }}
labels:
{{- include "app.labels" . | nindent 4 }}
{{- if .Values.serviceAccount.labels }}
{{ toYaml .Values.serviceAccount.labels | indent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }}
{{- end }}
Loading

0 comments on commit 98e1228

Please sign in to comment.