From 996f016d275edd18b671955d80656b36b44ca66a Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Fri, 22 Nov 2024 11:02:04 +0000 Subject: [PATCH 1/5] Allow MQTT broker container config fixes #502 --- helm/flowforge/README.md | 1 + helm/flowforge/templates/broker.yaml | 10 +--------- helm/flowforge/values.schema.json | 3 +++ helm/flowforge/values.yaml | 1 + 4 files changed, 6 insertions(+), 9 deletions(-) diff --git a/helm/flowforge/README.md b/helm/flowforge/README.md index a1b53413..c37c8f7c 100644 --- a/helm/flowforge/README.md +++ b/helm/flowforge/README.md @@ -89,6 +89,7 @@ To use STMP to send email ### MQTT Broker - `forge.broker.enabled` (default `false`) + - `forge.broker.image` Allows the mosquitto broker container image to be overidden (default `iegomez/mosquitto-go-auth`) - `forge.broker.url` URL to access the broker from inside the cluster (default `mqtt://flowforge-broker.[namespace]:1883`) - `forge.broker.public_url` URL to access the broker from outside the cluster (default `ws://mqtt.[forge.domain]`, uses `wss://` if `forge.https` is `true`) - `forge.broker.hostname` the custom Fully Qualified Domain Name (FQDN) where the broker will be hosted (default `mqtt.[forge.domain]`) diff --git a/helm/flowforge/templates/broker.yaml b/helm/flowforge/templates/broker.yaml index 74aa9df4..246d14eb 100644 --- a/helm/flowforge/templates/broker.yaml +++ b/helm/flowforge/templates/broker.yaml @@ -36,7 +36,7 @@ spec: {{- toYaml .Values.forge.broker.podSecurityContext | nindent 8 }} containers: - name: broker - image: iegomez/mosquitto-go-auth + image: {{ .Values.forge.broker.image | default "iegomez/mosquitto-go-auth" | quote }} imagePullPolicy: Always volumeMounts: - name: config @@ -126,8 +126,6 @@ spec: {{- if .Values.forge.broker.affinity }} affinity: {{ toYaml .Values.forge.broker.affinity | nindent 8 }} {{- end }} -{{- end }} -{{- if eq .Values.forge.broker.enabled true -}} --- apiVersion: v1 kind: Service @@ -146,11 +144,5 @@ spec: protocol: TCP name: mqtt-ws selector: - {{- if and ( eq .Values.forge.broker.enabled true) ( eq .Values.forge.broker.teamBroker.enabled false ) -}} {{- include "forge.brokerSelectorLabels" . | nindent 4 }} - {{- else -}} - apps.emqx.io/db-role: core - apps.emqx.io/instance: emqx - apps.emqx.io/managed-by: emqx-operator - {{- end }} {{- end -}} \ No newline at end of file diff --git a/helm/flowforge/values.schema.json b/helm/flowforge/values.schema.json index 484dc241..5307475f 100644 --- a/helm/flowforge/values.schema.json +++ b/helm/flowforge/values.schema.json @@ -368,6 +368,9 @@ }, "createMetricsUser": { "type": "boolean" + }, + "image": { + "type": "string" } }, "required": [ diff --git a/helm/flowforge/values.yaml b/helm/flowforge/values.yaml index 6506f6f9..e5914282 100644 --- a/helm/flowforge/values.yaml +++ b/helm/flowforge/values.yaml @@ -19,6 +19,7 @@ forge: podLabels: {} broker: enabled: false + image: iegomez/mosquitto-go-auth teamBroker: enabled: false createMetricsUser: false From b5a69163028e5acc1d151c5d50bb9fa02ab08758 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Fri, 22 Nov 2024 12:09:49 +0000 Subject: [PATCH 2/5] Fix service --- helm/flowforge/templates/broker.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/helm/flowforge/templates/broker.yaml b/helm/flowforge/templates/broker.yaml index 246d14eb..90c47b6b 100644 --- a/helm/flowforge/templates/broker.yaml +++ b/helm/flowforge/templates/broker.yaml @@ -126,6 +126,8 @@ spec: {{- if .Values.forge.broker.affinity }} affinity: {{ toYaml .Values.forge.broker.affinity | nindent 8 }} {{- end }} +{{- end }} +{{- if eq .Values.forge.broker.enabled true -}} --- apiVersion: v1 kind: Service @@ -144,5 +146,11 @@ spec: protocol: TCP name: mqtt-ws selector: + {{- if and ( eq .Values.forge.broker.enabled true) ( eq .Values.forge.broker.teamBroker.enabled false ) -}} {{- include "forge.brokerSelectorLabels" . | nindent 4 }} + {{- else -}} + apps.emqx.io/db-role: core + apps.emqx.io/instance: emqx + apps.emqx.io/managed-by: emqx-operator + {{- end }} {{- end -}} \ No newline at end of file From cb4b803e660fa0f068eb33fe55705c8493796baa Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Fri, 22 Nov 2024 12:10:27 +0000 Subject: [PATCH 3/5] Update helm/flowforge/templates/broker.yaml Co-authored-by: PPawlowski --- helm/flowforge/templates/broker.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helm/flowforge/templates/broker.yaml b/helm/flowforge/templates/broker.yaml index 90c47b6b..9d44c2a3 100644 --- a/helm/flowforge/templates/broker.yaml +++ b/helm/flowforge/templates/broker.yaml @@ -36,7 +36,7 @@ spec: {{- toYaml .Values.forge.broker.podSecurityContext | nindent 8 }} containers: - name: broker - image: {{ .Values.forge.broker.image | default "iegomez/mosquitto-go-auth" | quote }} + image: {{ .Values.forge.broker.image }} imagePullPolicy: Always volumeMounts: - name: config From 493c57c725b77daf1a9f2983d8f7071b345aee2b Mon Sep 17 00:00:00 2001 From: ppawlowski Date: Fri, 22 Nov 2024 13:56:10 +0100 Subject: [PATCH 4/5] Fix broker template --- helm/flowforge/templates/broker.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/helm/flowforge/templates/broker.yaml b/helm/flowforge/templates/broker.yaml index 9d44c2a3..df962fc7 100644 --- a/helm/flowforge/templates/broker.yaml +++ b/helm/flowforge/templates/broker.yaml @@ -127,7 +127,7 @@ spec: affinity: {{ toYaml .Values.forge.broker.affinity | nindent 8 }} {{- end }} {{- end }} -{{- if eq .Values.forge.broker.enabled true -}} +{{- if .Values.forge.broker.enabled }} --- apiVersion: v1 kind: Service @@ -148,7 +148,7 @@ spec: selector: {{- if and ( eq .Values.forge.broker.enabled true) ( eq .Values.forge.broker.teamBroker.enabled false ) -}} {{- include "forge.brokerSelectorLabels" . | nindent 4 }} - {{- else -}} + {{- else }} apps.emqx.io/db-role: core apps.emqx.io/instance: emqx apps.emqx.io/managed-by: emqx-operator From 9861dc46d73fcc2eaca1ecacf145be8637ffcbd2 Mon Sep 17 00:00:00 2001 From: ppawlowski Date: Fri, 22 Nov 2024 13:56:33 +0100 Subject: [PATCH 5/5] Add basic unit tests for broker service and deployment --- helm/flowforge/tests/broker_test.yaml | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 helm/flowforge/tests/broker_test.yaml diff --git a/helm/flowforge/tests/broker_test.yaml b/helm/flowforge/tests/broker_test.yaml new file mode 100644 index 00000000..d33c12a8 --- /dev/null +++ b/helm/flowforge/tests/broker_test.yaml @@ -0,0 +1,53 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json +suite: test broker deployment +templates: + - broker.yaml + - broker-config.yaml +set: + forge.domain: "chart-unit-tests.com" + forge.broker.enabled: true +tests: + - it: should create a mosquitto broker deployment + template: broker.yaml + documentIndex: 0 + asserts: + - isKind: + of: Deployment + - equal: + path: spec.template.spec.containers[?(@.name == "broker")].image + value: iegomez/mosquitto-go-auth + - lengthEqual: + path: spec.template.spec.containers + count: 1 + + - it: should create a broker service for mosquitto broker deployment + template: broker.yaml + documentIndex: 1 + asserts: + - isKind: + of: Service + - equal: + path: spec.selector + value: + app: flowforge-broker + - not: true + equal: + path: spec.selector + value: apps.emqx.io/instance + + - it: should create a broker service for emqx deployment + template: broker.yaml + documentIndex: 0 + set: + forge.broker.teamBroker.enabled: true + asserts: + - isKind: + of: Service + - notExists: + path: spec.selector.app + - equal: + path: spec.selector + value: + apps.emqx.io/db-role: core + apps.emqx.io/instance: emqx + apps.emqx.io/managed-by: emqx-operator