Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Team Broker #484

Merged
merged 18 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions helm/flowforge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ To use STMP to send email

`forge.broker.createMetricsUser` parameter controlls if a dedicated MQTT user with broker metrics collection permissions should be created. This user can by used by the tools like [Mosquitto Exporter](https://github.com/sapcc/mosquitto-exporter) to expose broker's metrics for Prometheus scrapper.

### Team Broker

- `broker.storageClassName` the StorageClass to use for the teamBroker persistent Storage
- `broker.listenersServiceTemplate` Service spec for the MQTT listeners
- `broker.dashboardServiceTemplate` Service spec for the teamBroker admin console
- `broker.existingSecret` name of existing Secret holding dashboard admin password and API key

### Telemetry

Enables FlowForge Telemetry
Expand Down
2 changes: 1 addition & 1 deletion helm/flowforge/templates/broker-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.forge.broker.enabled -}}
{{- if and ( eq .Values.forge.broker.enabled true) ( eq .Values.forge.broker.teamBroker.enabled false ) -}}
{{- $metricsUser := "metrics_reader" }}
apiVersion: v1
kind: ConfigMap
Expand Down
2 changes: 1 addition & 1 deletion helm/flowforge/templates/broker-ingress.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.forge.broker.enabled -}}
{{- if and ( eq .Values.forge.broker.enabled true) ( eq .Values.forge.broker.teamBroker.enabled false ) -}}
{{- $brokerHostname := (printf "%s%s" "mqtt." .Values.forge.domain) -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
Expand Down
2 changes: 1 addition & 1 deletion helm/flowforge/templates/broker.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- if .Values.forge.broker.enabled -}}
{{- if and ( eq .Values.forge.broker.enabled true) ( eq .Values.forge.broker.teamBroker.enabled false ) -}}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down
6 changes: 5 additions & 1 deletion helm/flowforge/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,18 @@ data:
{{ if .Values.forge.broker.url -}}
url: {{ .Values.forge.broker.url }}
{{ else -}}
{{ if .Values.forge.broker.teamBroker }}
url: mqtt://emqx-listeners.{{ .Release.Namespace }}:1883
{{ else -}}
url: mqtt://flowforge-broker.{{ .Release.Namespace }}:1883
{{end -}}
{{ end -}}
{{ if .Values.forge.broker.public_url -}}
public_url: {{ .Values.forge.broker.public_url }}
{{ else -}}
public_url: ws{{- if .Values.forge.https -}}s{{- end -}}://{{ include "forge.brokerDomain" . }}
{{ end -}}
{{ if .Values.forge.broker.teamBroker.enabled }}
{{ if or .Values.forge.broker.teamBroker.enabled .Values.forge.broker.teamBroker.uiOnly }}
teamBroker:
enabled: true
{{ end -}}
Expand Down
259 changes: 259 additions & 0 deletions helm/flowforge/templates/emqx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
{{- if and ( eq .Values.forge.broker.enabled true) ( eq .Values.forge.broker.teamBroker.enabled true ) -}}
{{- if .Capabilities.APIVersions.Has "apps.emqx.io/v2beta1" }}
apiVersion: apps.emqx.io/v2beta1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With Capabilities we should check if this API exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like

{{ if .Capabilities.APIVersions.Has('apps.emqx.io/v2beta1') }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to add --api-versions=apps.emqx.io/v2beta1 to the template tests

kind: EMQX
metadata:
name: emqx
spec:
image: emqx:5
imagePullPolicy: IfNotPresent
config:
data: |
authentication = [
{
backend = http
body = {
clientId = "${clientid}"
username = "${username}"
password = "${password}"
}
enable = true
connect_timeout = "15s"
enable_pipelining = 100
headers {
content-type = "application/json"
}
mechanism = password_based
method = post
pool_size = 8
request_timeout = "8s"
ssl {
enable = false
}
url = "http://forge.{{ .Release.Namespace }}/api/comms/v2/auth"
}
]
authorization {
cache {
enable = true
excludes = []
max_size = 32
ttl = "1m"
}
deny_action = ignore
no_match = allow
sources = [
{
enable = true
enable_pipelining = 100
connect_timeout = "15s"
request_timeout = "30s"
pool_size = 8
body {
action = "${action}"
topic = "${topic}"
username = "${username}"
}
headers {
content-type = "application/json"
}
method = post
type = http
ssl {
enable = false
}
url = "http://forge.{{ .Release.Namespace }}/api/comms/v2/acls"
}
]
}
listeners {
tcp {
default {
bind = "0.0.0.0:1883"
access_rules = [
"allow all"
]
enable = true
enable_authn = true
mountpoint = "${client_attrs.team}"
max_connections = infinity
acceptors = 16
proxy_protocol = false
proxy_protocol_timeout = 3s
tcp_options {
backlog = 1024
send_timeout = 15s
recbuf = 2KB
sndbuf = 4KB
buffer = 4KB
high_watermark = 1MB
nodelay = true
reuseaddr = true
keepalive = "none"
}
}
}
ssl {
default {
enable = false
}
}
wss {
default {
enable = false
}
}
ws {
default {
bind = "0.0.0.0:8080"
access_rules = [
"allow all"
]
enable = true
enable_authn = true
mountpoint = "${client_attrs.team}"
max_connections = infinity
proxy_protocol = false
proxy_protocol_timeout = 3s
tcp_options {
backlog = 1024
send_timeout = 15s
recbuf = 2KB
sndbuf = 4KB
buffer = 4KB
high_watermark = 1MB
nodelay = true
reuseaddr = true
keepalive = "none"
}
websocket {
mqtt_path = "/"
allow_origin_absence = true
check_origin_enable = false
fail_if_no_subprotocol = true
supported_subprotocols = "mqtt, mqtt-v3, mqtt-v3.1.1 mqtt-v5"
mqtt_piggyback = multiple
compress = false
idle_timeout = 7200s
max_frame_size = infinity
proxy_address_header = "x-forwarded-for"
proxy_port_header = "x-forwarded-port"
}
}
}
}
api_key {
bootstrap_file = "/mounted/config/api-keys"
}
coreTemplate:
spec:
{{- if .Values.forge.registrySecrets }}
imagePullSecrets:
{{- range .Values.forge.registrySecrets }}
- name: {{ . }}
{{- end }}
{{- end }}
env:
- name: EMQX_DASHBOARD__DEFAULT_PASSWORD
valueFrom:
secretKeyRef:
{{- if .Values.broker.exisitingSecret }}
name: {{ .Values.broker.exisitingSecret }}
{{- else }}
name: emqx-config-secrets
{{- end }}
key: EMQX_DASHBOARD__DEFAULT_PASSWORD
volumeClaimTemplates:
{{- if .Values.broker.storageClassName }}
storageClassName: {{ .Values.broker.storageClassName }}
{{- end}}
resources:
requests:
storage: 5Gi
accessModes:
- ReadWriteOnce
extraVolumes:
- name: config
secret:
{{- if .Values.broker.exisitingSecret }}
secretName: {{ .Values.broker.exisitingSecret }}
{{- else }}
secretName: emqx-config-secrets
{{- end }}
extraVolumeMounts:
- name: config
mountPath: /mounted/config/api-keys
subPath: api-keys
{{- if .Values.forge.broker.affinity }}
affinity: {{ toYaml .Values.forge.broker.affinity | indent 12 }}
{{- end }}
{{- if .Values.forge.broker.tolerations}}
tolerations:
{{ toYaml .Values.forge.broker.tolerations | nindent 12 }}
{{- end }}
listenersServiceTemplate:
spec:
{{- if .Values.broker.listenersServiceTemplate }}
{{ toYaml .Values.broker.listenersServiceTemplate | indent 12 }}
{{ else }}
type: ClusterIP
{{- end }}
dashboardServiceTemplate:
spec:
{{- if .Values.broker.dashboardServiceTemplate }}
{{ toYaml .Values.broker.dashboardServiceTemplate | indent 12 }}
{{ else }}
type: ClusterIP
{{- end }}
---
{{- if not .Values.broker.exisitingSecret }}
apiVersion: v1
kind: Secret
metadata:
name: emqx-config-secrets
namespace: {{ .Release.Namespace }}
type: Opaque
data:
EMQX_DASHBOARD__DEFAULT_PASSWORD: {{ "topSecret" | b64enc | quote }}
api-keys: |
{{ "flowfuse:verySecret:administrator" | b64enc | quote }}
---
{{- end }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: flowforge-broker
labels:
{{- include "forge.brokerSelectorLabels" . | nindent 4 }}
annotations:
{{- if .Values.ingress.certManagerIssuer }}
cert-manager.io/cluster-issuer: {{ $.Values.ingress.certManagerIssuer }}
{{- end }}
{{- if and .Values.forge.broker.enabled .Values.forge.broker.ingress (hasKey .Values.forge.broker.ingress "annotations") }}
{{ toYaml .Values.forge.broker.ingress.annotations | replace "{{ instanceHost }}" "{{ include forge.brokerDomain . }}" | replace "{{ serviceName }}" "flowforge-broker" | indent 4 }}
{{- end }}
spec:
{{- if $.Values.ingress.className }}
ingressClassName: {{ $.Values.ingress.className }}
{{- end }}
rules:
- host: {{ include "forge.brokerDomain" . }}
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: emqx-listeners
port:
number: 8080
{{- if .Values.ingress.certManagerIssuer }}
tls:
- hosts:
- {{ include "forge.brokerDomain" . }}
secretName: {{ include "forge.brokerDomain" . }}
{{- end }}
{{- else }}
{{- fail "EMQX Operator not installed" }}
{{- end }}
{{- end }}
17 changes: 17 additions & 0 deletions helm/flowforge/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,23 @@
"required": ["username", "password", "database"]
}
}
},
"broker": {
"type": "object",
"properties": {
"storageClassName": {
"type": "string"
},
"listenersServiceTemplate": {
"type": "object"
},
"dashboardServiceTemplate": {
"type": "object"
},
"existingSecret": {
"type": "string"
}
}
}
},
"if": {
Expand Down
6 changes: 6 additions & 0 deletions helm/flowforge/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,9 @@ editors:
create: true
annotations: {}
name: editors

broker:
storageClassName: ''
listenersServiceTemplate: {}
dashboardServiceTemplate: {}
existingSecret: ''
Loading
Loading