diff --git a/Makefile b/Makefile index 90624a3..b00f975 100644 --- a/Makefile +++ b/Makefile @@ -37,9 +37,17 @@ lint: test-unit: @cd app && go test ./... -cover; +.PHONY: preview +preview: + @helm template ./helm/pi-agent + .PHONY: deploy 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 \ + --namespace=pi-agent \ + --create-namespace; \ No newline at end of file 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"] 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..2eeabf1 --- /dev/null +++ b/helm/pi-agent/templates/daemonset.yaml @@ -0,0 +1,31 @@ +# 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 }} + volumeMounts: + - name: sysfs + mountPath: /host/sys + readOnly: true + tolerations: + # Run on all nodes including control plane + - operator: Exists + volumes: + - name: sysfs + hostPath: + path: /sys 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