From e66575be897a61e6dddb5b0715e8c889a9ac67ef Mon Sep 17 00:00:00 2001 From: August Felso Date: Thu, 26 Feb 2026 10:12:06 -0500 Subject: [PATCH 1/4] Add debug output for image tag --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 90624a3..8d331dd 100644 --- a/Makefile +++ b/Makefile @@ -41,5 +41,7 @@ test-unit: deploy: @source venv/activate > /dev/null; \ git fetch origin main --quiet; \ + IMAGE_TAG=$$(git rev-parse --short origin/main); \ + echo "Deploying image tag: $$IMAGE_TAG"; \ helm upgrade --install pi-agent helm/pi-agent \ - --set image.tag=$(shell git rev-parse --short origin/main); \ No newline at end of file + --set image.tag=$$IMAGE_TAG; \ No newline at end of file From 47d77d85578af539ff5671ca787920e6c1897c0d Mon Sep 17 00:00:00 2001 From: August Felso Date: Thu, 5 Mar 2026 07:59:39 -0500 Subject: [PATCH 2/4] Scaffold DaemonSet --- Makefile | 8 +++++++- helm/pi-agent/Chart.yaml | 4 ++-- helm/pi-agent/templates/_helpers.tpl | 13 +++++++++++++ helm/pi-agent/templates/cronjob.yaml | 16 ---------------- helm/pi-agent/templates/daemonset.yaml | 20 ++++++++++++++++++++ helm/pi-agent/values.yaml | 15 +++++++++++++-- 6 files changed, 55 insertions(+), 21 deletions(-) create mode 100644 helm/pi-agent/templates/_helpers.tpl delete mode 100644 helm/pi-agent/templates/cronjob.yaml create mode 100644 helm/pi-agent/templates/daemonset.yaml diff --git a/Makefile b/Makefile index 8d331dd..b00f975 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,10 @@ lint: test-unit: @cd app && go test ./... -cover; +.PHONY: preview +preview: + @helm template ./helm/pi-agent + .PHONY: deploy deploy: @source venv/activate > /dev/null; \ @@ -44,4 +48,6 @@ deploy: IMAGE_TAG=$$(git rev-parse --short origin/main); \ echo "Deploying image tag: $$IMAGE_TAG"; \ helm upgrade --install pi-agent helm/pi-agent \ - --set image.tag=$$IMAGE_TAG; \ No newline at end of file + --set image.tag=$$IMAGE_TAG \ + --namespace=pi-agent \ + --create-namespace; \ No newline at end of file diff --git a/helm/pi-agent/Chart.yaml b/helm/pi-agent/Chart.yaml index fc4aa1b..7eb5d1c 100644 --- a/helm/pi-agent/Chart.yaml +++ b/helm/pi-agent/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: pi-agent -description: A Helm chart for Kubernetes +description: Collects basic Raspberry Pi metrics # A chart can be either an 'application' or a 'library' chart. # @@ -21,4 +21,4 @@ version: 0.1.0 # incremented each time you make changes to the application. Versions are not expected to # follow Semantic Versioning. They should reflect the version the application is using. # It is recommended to use it with quotes. -appVersion: "1.16.0" +appVersion: "1.0.0" diff --git a/helm/pi-agent/templates/_helpers.tpl b/helm/pi-agent/templates/_helpers.tpl new file mode 100644 index 0000000..9272471 --- /dev/null +++ b/helm/pi-agent/templates/_helpers.tpl @@ -0,0 +1,13 @@ +# templates/_helpers.tpl + +# Standard labels applied to all resources +{{- define "pi-agent.labels" -}} +helm.sh/chart: {{ .Chart.Name }}-{{ .Chart.Version }} +app.kubernetes.io/name: {{ .Chart.Name }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +# Metric collector selector labels +{{- define "pi-agent.collector.selectorLabels" -}} +app.kubernetes.io/component: {{ .Values.collector.name }} +{{- end }} \ No newline at end of file diff --git a/helm/pi-agent/templates/cronjob.yaml b/helm/pi-agent/templates/cronjob.yaml deleted file mode 100644 index f41cd0b..0000000 --- a/helm/pi-agent/templates/cronjob.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: batch/v1 -kind: CronJob -metadata: - name: {{ .Release.Name }} -spec: - schedule: {{ .Values.schedule | quote }} - jobTemplate: - spec: - template: - spec: - containers: - - name: {{ .Release.Name }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - command: ["/pi-agent"] - restartPolicy: Never diff --git a/helm/pi-agent/templates/daemonset.yaml b/helm/pi-agent/templates/daemonset.yaml new file mode 100644 index 0000000..0b02805 --- /dev/null +++ b/helm/pi-agent/templates/daemonset.yaml @@ -0,0 +1,20 @@ +# Metric collector template +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: {{ .Values.collector.name }} + namespace: {{ .Release.namespace }} + labels: {{- include "pi-agent.labels" . | nindent 4 }} +spec: + selector: + matchLabels: + {{- include "pi-agent.collector.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "pi-agent.collector.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} diff --git a/helm/pi-agent/values.yaml b/helm/pi-agent/values.yaml index 68d43f1..c395a5c 100644 --- a/helm/pi-agent/values.yaml +++ b/helm/pi-agent/values.yaml @@ -1,6 +1,17 @@ -schedule: "*/5 * * * *" - +# Image configuration image: repository: ghcr.io/amfelso/pi-agent tag: latest pullPolicy: IfNotPresent + +# Metric collector configuration +collector: + name: metric-collector + schedule: 300 # Default collection interval = every 5 minutes + resources: + limits: + cpu: 500m + memory: 256Mi + requests: + cpu: 100m + memory: 128Mi From e26aaca42b99f045aa173e5f5ec415f36e514506 Mon Sep 17 00:00:00 2001 From: August Felso Date: Thu, 5 Mar 2026 08:15:19 -0500 Subject: [PATCH 3/4] Mount host sysfs --- helm/pi-agent/templates/daemonset.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/helm/pi-agent/templates/daemonset.yaml b/helm/pi-agent/templates/daemonset.yaml index 0b02805..2eeabf1 100644 --- a/helm/pi-agent/templates/daemonset.yaml +++ b/helm/pi-agent/templates/daemonset.yaml @@ -18,3 +18,14 @@ spec: - name: {{ .Chart.Name }} image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" imagePullPolicy: {{ .Values.image.pullPolicy }} + volumeMounts: + - name: sysfs + mountPath: /host/sys + readOnly: true + tolerations: + # Run on all nodes including control plane + - operator: Exists + volumes: + - name: sysfs + hostPath: + path: /sys From f8c1a95c0d21fe1e40d9ef39da5e325db6c32f36 Mon Sep 17 00:00:00 2001 From: August Felso <77752049+amfelso@users.noreply.github.com> Date: Thu, 5 Mar 2026 13:54:47 -0500 Subject: [PATCH 4/4] Use distroless image --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 49cbee8..82ceceb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -4,6 +4,6 @@ WORKDIR /app COPY . . RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} go build -o pi-agent . -FROM alpine:3.21 +FROM scratch COPY --from=builder /app/pi-agent /pi-agent ENTRYPOINT ["/pi-agent"]