From 3c16f77f4aca5146c6016b95532b4106d1ed47a5 Mon Sep 17 00:00:00 2001 From: Ben Morrow Date: Wed, 27 Nov 2024 11:25:59 +0000 Subject: [PATCH 1/3] Create an edge MQTT broker chart --- .../charts/mqtt-broker/Chart.yaml | 4 ++ .../charts/mqtt-broker/templates/_helpers.tpl | 12 +++++ .../mqtt-broker/templates/mqtt-broker.yaml | 52 +++++++++++++++++++ .../charts/mqtt-broker/templates/service.yaml | 18 +++++++ .../charts/mqtt-broker/values.yaml | 27 ++++++++++ 5 files changed, 113 insertions(+) create mode 100644 edge-helm-charts/charts/mqtt-broker/Chart.yaml create mode 100644 edge-helm-charts/charts/mqtt-broker/templates/_helpers.tpl create mode 100644 edge-helm-charts/charts/mqtt-broker/templates/mqtt-broker.yaml create mode 100644 edge-helm-charts/charts/mqtt-broker/templates/service.yaml create mode 100644 edge-helm-charts/charts/mqtt-broker/values.yaml diff --git a/edge-helm-charts/charts/mqtt-broker/Chart.yaml b/edge-helm-charts/charts/mqtt-broker/Chart.yaml new file mode 100644 index 00000000..cc6f4c64 --- /dev/null +++ b/edge-helm-charts/charts/mqtt-broker/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v2 +name: mqtt-broker +version: "0.0.1" +description: "ACS edge MQTT broker" diff --git a/edge-helm-charts/charts/mqtt-broker/templates/_helpers.tpl b/edge-helm-charts/charts/mqtt-broker/templates/_helpers.tpl new file mode 100644 index 00000000..37dc4976 --- /dev/null +++ b/edge-helm-charts/charts/mqtt-broker/templates/_helpers.tpl @@ -0,0 +1,12 @@ +{{- define "acs.image" -}} +{{- $root := index . 0 -}} +{{- $key := index . 1 -}} +{{- $image := $root.Values.image -}} +{{- $spec := merge (get $image $key) $image.default -}} +image: "{{ $spec.registry }}/{{ $spec.repository }}:{{ $spec.tag }}" +imagePullPolicy: {{ $spec.pullPolicy }} +{{- end }} + +{{- define "acs.k8sname" }} +{{- .Values.name | lower | replace "_" "-" }} +{{- end }} diff --git a/edge-helm-charts/charts/mqtt-broker/templates/mqtt-broker.yaml b/edge-helm-charts/charts/mqtt-broker/templates/mqtt-broker.yaml new file mode 100644 index 00000000..be925367 --- /dev/null +++ b/edge-helm-charts/charts/mqtt-broker/templates/mqtt-broker.yaml @@ -0,0 +1,52 @@ +{{- $k8sname := include "acs.k8sname" . }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ .Chart.Name }}-{{ $k8sname }} + namespace: {{ .Release.Namespace }} + labels: + factory-plus.app: {{ .Chart.Name }} + factory-plus.uuid: {{ .Values.uuid }} + factory-plus.name: {{ .Values.name }} +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + factory-plus.app: {{ .Chart.Name }} + factory-plus.uuid: {{ .Values.uuid }} + template: + metadata: + labels: + factory-plus.app: {{ .Chart.Name }} + factory-plus.uuid: {{ .Values.uuid }} + factory-plus.name: {{ .Values.name }} + spec: +{{ if .Values.hostname }} + nodeSelector: + kubernetes.io/hostname: {{ .Values.hostname | quote }} + tolerations: {{ .Values.tolerations.specific | toYaml | nindent 8 }} +{{ else }} + tolerations: {{ .Values.tolerations.floating | toYaml | nindent 8 }} +{{ end }} + volumes: + - name: config + configMap: + name: {{ .Chart.Name }}-{{ $k8sname }} + containers: + - name: mqtt-broker +{{ list . "mosquitto" | include "acs.image" | indent 10 }} + volumeMounts: + - mountPath: /mosquitto/config + name: config +--- +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: {{ .Release.Namespace }} + name: {{ .Chart.Name }}-{{ $k8sname }} +data: + mosquitto.conf: | + listener 1883 + allow_anonymous true diff --git a/edge-helm-charts/charts/mqtt-broker/templates/service.yaml b/edge-helm-charts/charts/mqtt-broker/templates/service.yaml new file mode 100644 index 00000000..e5583f3b --- /dev/null +++ b/edge-helm-charts/charts/mqtt-broker/templates/service.yaml @@ -0,0 +1,18 @@ +{{- $k8sname := include "acs.k8sname" . }} +apiVersion: v1 +kind: Service +metadata: + namespace: {{ .Release.Namespace }} + name: {{ .Chart.Name }}-{{ $k8sname }} +spec: + selector: + factory-plus.app: {{ .Chart.Name }} + factory-plus.uuid: {{ .Values.uuid }} +{{- with .Values.expose }} + internalTrafficPolicy: {{ .internalTrafficPolicy }} + ports: + - name: mqtt + port: {{ .port }} + targetPort: 1883 + externalIPs: {{ .externalIPs }} +{{- end }} diff --git a/edge-helm-charts/charts/mqtt-broker/values.yaml b/edge-helm-charts/charts/mqtt-broker/values.yaml new file mode 100644 index 00000000..3a963532 --- /dev/null +++ b/edge-helm-charts/charts/mqtt-broker/values.yaml @@ -0,0 +1,27 @@ +# This is required +# uuid: 12345 +# This deploys to a specific host +#hostname: foo +image: + default: + pullPolicy: IfNotPresent + mosquitto: + registry: docker.io + repository: eclipse-mosquitto + tag: "2.0" +tolerations: + # Tolerations to apply to pods deployed to a specific host + specific: + - key: factoryplus.app.amrc.co.uk/specialised + operator: Exists + # Tolerations to apply to floating pods + floating: [] +# Whether to expose the broker externally +expose: + # Expose on an existing external IP + externalIPs: [] + # Port to expose on + port: 1883 + # How to route cluster-internal traffic. Setting this to Local will + # prevent pods on different nodes from contacting the service. + internalTrafficPolicy: Local From 1b4deae0314d4da3b4d5f61a6fa5a7afe29e0c62 Mon Sep 17 00:00:00 2001 From: Ben Morrow Date: Wed, 27 Nov 2024 11:33:56 +0000 Subject: [PATCH 2/3] Create an _Edge deployment_ class The original design was that an edge deployment was focussed on an Edge Agent, with sidecar charts deployed as needed. It has turned out to be better to deploy subsidiary charts as separate deployments because of the values handling; the objects defining these should not be in the _Call Gateway_ class. Create a class for them. --- acs-service-setup/dumps/helm.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/acs-service-setup/dumps/helm.yaml b/acs-service-setup/dumps/helm.yaml index b7e84bac..4a1944dc 100644 --- a/acs-service-setup/dumps/helm.yaml +++ b/acs-service-setup/dumps/helm.yaml @@ -2,6 +2,7 @@ service: !u UUIDs.Service.ConfigDB version: 1 classes: - !u Clusters.Class.HelmChart + - !u ACS.Class.EdgeDeployment objects: !u UUIDs.Class.App: - !u Clusters.App.HelmRelease @@ -11,6 +12,7 @@ objects: configs: !u UUIDs.App.Info: !u Clusters.Class.HelmChart: { name: "Helm chart" } + !u Clusters.Class.EdgeDeployment: { name: "Edge deployment" } !u Clusters.App.HelmRelease: { name: "HelmRelease template" } !u Clusters.App.HelmTemplate: { name: "Helm chart template" } !u UUIDs.App.ConfigSchema: From 1e7bae8eb5b8e0acd6d972743082ae52ae7deeaf Mon Sep 17 00:00:00 2001 From: Ben Morrow Date: Wed, 27 Nov 2024 11:35:37 +0000 Subject: [PATCH 3/3] Create a Helm template for the edge broker --- acs-service-setup/lib/helm.js | 7 +++++++ acs-service-setup/lib/uuids.js | 1 + 2 files changed, 8 insertions(+) diff --git a/acs-service-setup/lib/helm.js b/acs-service-setup/lib/helm.js index aea93f83..a510501f 100644 --- a/acs-service-setup/lib/helm.js +++ b/acs-service-setup/lib/helm.js @@ -136,6 +136,13 @@ export async function setup_helm (ss) { uuid: "{{uuid}}", hostname: "{{hostname}}", } }], + ["mqtt", "Edge MQTT broker", { + chart: "mqtt-broker", + values: { + name: "{{name}}", + uuid: "{{uuid}}", + hostname: "{{hostname}}", + } }], ); return await conf.finish(); diff --git a/acs-service-setup/lib/uuids.js b/acs-service-setup/lib/uuids.js index b5e9b35b..7150773e 100644 --- a/acs-service-setup/lib/uuids.js +++ b/acs-service-setup/lib/uuids.js @@ -11,6 +11,7 @@ export const ACS = { Permission: "8ae784bb-c4b5-4995-9bf6-799b3c7f21ad", UserAccount: "8b3e8f35-78e5-4f93-bf21-7238bcb2ba9d", UserGroup: "f1fabdd1-de90-4399-b3da-ccf6c2b2c08b", + EdgeDeployment: "e6f6a6e6-f6b2-422a-bc86-2dcb417a362a", }, App: { SchemaIcon: "65c0ccba-151d-48d3-97b4-d0026a811900",