Skip to content

Commit

Permalink
Implement multiple modules
Browse files Browse the repository at this point in the history
- Create deployment for each modules
- Create modules settings and configmap
- Code refactoring

Signed-off-by: Francesco Torchia <[email protected]>
  • Loading branch information
torchiaf committed Dec 29, 2024
1 parent 06bfb01 commit b5814e1
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 40 deletions.
3 changes: 0 additions & 3 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
- Implement OpenAPI definitions
- Golang process on master node to call the rabbitMQ endpoints, fetch data and update CRDS
- Pin and raspberry version should be parameters
- Create Rancher extensions to handle sensors CRDs
- Create settings file to define raspberry modules
- sensors helm charts should get the settings and create as many deployments as the numbers of raspberry modules
- Create a manifest.yaml file for each supported sensors (svg, description, link to homepage)
- Create a CRD for each sensor
- Create a CRD for each raspberry module
Expand Down
4 changes: 2 additions & 2 deletions charts/rabbitmq-cluster/templates/rabbitmq-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ spec:
additionalConfig: |
log.console.level = {{ .Values.rabbitmq.config.logLevel }}
channel_max = 700
default_user= {{ .Values.settings.rabbitmq.username }}
default_pass = {{ .Values.settings.rabbitmq.password }}
default_user= {{ .Values.sensors.rabbitmq.username }}
default_pass = {{ .Values.sensors.rabbitmq.password }}
default_user_tags.administrator = true
service:
type: LoadBalancer
9 changes: 9 additions & 0 deletions charts/sensors/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "sensors.fullname" . }}
labels:
{{- include "sensors.labels" . | nindent 4 }}
data:
modules: |
{{- toYaml .Values.sensors.modules | nindent 4 }}
70 changes: 42 additions & 28 deletions charts/sensors/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ spec:
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
- name: modules
mountPath: "/sensors"
envFrom:
- secretRef:
name: {{ include "sensors.fullname" . }}-rabbitmq
optional: false
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
- name: modules
configMap:
name: {{ include "sensors.fullname" . }}
items:
- key: modules
path: modules.yaml
{{- with .Values.controller.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand All @@ -67,71 +69,83 @@ spec:
{{- toYaml . | nindent 8 }}
{{- end }}
---
{{- range $index, $elem := .Values.sensors.modules }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "sensors.fullname" . }}-raspberrypi
name: {{ include "sensors.fullname" $ }}-{{ $elem.name }}
labels:
{{- include "sensors.labels" . | nindent 4 }}
{{- include "sensors.labels" $ | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- if not $.Values.autoscaling.enabled }}
replicas: {{ $.Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "sensors.selectorLabels" . | nindent 6 }}
{{- include "sensors.selectorLabels" $ | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
{{- with $.Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "sensors.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- include "sensors.labels" $ | nindent 8 }}
{{- with $.Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
{{- with $.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "sensors.serviceAccountName" . }}
serviceAccountName: {{ include "sensors.serviceAccountName" $ }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
{{- toYaml $.Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
- name: {{ $elem.name }}
securityContext:
privileged: true
image: "{{ .Values.raspberrypi.image.repository }}:{{ .Values.raspberrypi.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.raspberrypi.image.pullPolicy }}
{{- with get $.Values $elem.type }}
image: "{{ .image.repository }}:{{ .image.tag | default $.Chart.AppVersion }}"
imagePullPolicy: {{ .image.pullPolicy }}
{{- end }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
containerPort: {{ $.Values.service.port }}
protocol: TCP
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
{{- toYaml $.Values.resources | nindent 12 }}
{{- with $.Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: RPC_QUEUE
value: {{ $elem.rpc_queue }}
{{- range $device := $elem.devices }}
{{- toYaml $device.env | nindent 12 }}
{{- end }}
envFrom:
- secretRef:
name: {{ include "sensors.fullname" . }}-rabbitmq
name: {{ include "sensors.fullname" $ }}-rabbitmq
optional: false
{{- with .Values.volumes }}
{{- with $.Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.raspberrypi.nodeSelector }}
nodeName: {{ $elem.nodeName }}
{{- with $.Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
{{- with $.Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
{{- with $.Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
---
{{- end }}
4 changes: 2 additions & 2 deletions charts/sensors/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
{{- include "sensors.labels" . | nindent 4 }}
data:
RABBITMQ_USERNAME: {{ .Values.settings.rabbitmq.username | b64enc }}
RABBITMQ_PASSWORD: {{ .Values.settings.rabbitmq.password | b64enc }}
RABBITMQ_USERNAME: {{ .Values.sensors.rabbitmq.username | b64enc }}
RABBITMQ_PASSWORD: {{ .Values.sensors.rabbitmq.password | b64enc }}
type: Opaque
immutable: true
2 changes: 0 additions & 2 deletions charts/sensors/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ raspberrypi:
pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion.
tag: "main"
nodeSelector:
sensors.role: "worker"

# This will set the replicaset count more information can be found here: https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/
replicaCount: 1
Expand Down
25 changes: 24 additions & 1 deletion charts/settings.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
settings:
sensors:
rabbitmq:
username: admin
password: password
modules:
- name: raspberrypi-0
nodeName: raspberrypi
type: raspberrypi
rpc_queue: raspberrypi-0
devices:
- name: dht11
env:
- name: DHT11_PIN
value: "12"
- name: RASPBERRYPI_VERSION
value: "3"
# - name: raspberrypi-1
# nodeName: raspberrypi-1
# type: raspberrypi
# rpc_queue: raspberrypi-0
# devices:
# - name: dht11
# env:
# - name: DHT11_PIN
# value: "12"
# - name: RASPBERRYPI_VERSION
# value: "3"
5 changes: 3 additions & 2 deletions controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
FROM golang:alpine AS build
ADD . /sensors
RUN cd /sensors && go build -o controller
WORKDIR /sensors
RUN go build -o init

FROM alpine
WORKDIR /controller
COPY --from=build /sensors /controller

CMD ["./controller"]
CMD ["./init"]

0 comments on commit b5814e1

Please sign in to comment.