Skip to content

Commit 78c4b06

Browse files
feat(helm): ✨ add helm chart
Signed-off-by: Mario Vejlupek <[email protected]>
1 parent a96c7e9 commit 78c4b06

13 files changed

+227
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmp

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"conventionalCommits.scopes": [
3+
"helm"
4+
]
5+
}

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test:
2+
helm upgrade --install --debug -n customer-monitoring-system --set-file script_py=./tmp/script.py -f ./tmp/values.test.yaml s3-metrics ./helm
3+
4+
template:
5+
helm template --debug --output-dir=./tmp/ -n customer-monitoring-system --set-file script_py=./tmp/script.py -f ./tmp/values.test.yaml s3-metrics ./helm
6+

helm/Chart.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
name: python-aws-exporter-base
3+
description: A Helm chart for the Python S3 script
4+
version: 2.1.0
5+
appVersion: v2.0

helm/templates/_helpers.tpl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "python-aws-exporter-base.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "python-aws-exporter-base.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Create chart name and version as used by the chart label.
29+
*/}}
30+
{{- define "python-aws-exporter-base.chart" -}}
31+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
32+
{{- end -}}
33+
34+
{{/*
35+
Common labels
36+
*/}}
37+
{{- define "python-aws-exporter-base.labels" -}}
38+
app.kubernetes.io/name: {{ include "python-aws-exporter-base.name" . }}
39+
helm.sh/chart: {{ include "python-aws-exporter-base.chart" . }}
40+
app.kubernetes.io/instance: {{ .Release.Name }}
41+
{{- if .Chart.AppVersion }}
42+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
43+
{{- end }}
44+
app.kubernetes.io/managed-by: {{ .Release.Service }}
45+
{{- end -}}
46+
47+
{{/*
48+
Create the name of the service account to use
49+
*/}}
50+
{{- define "python-aws-exporter-base.serviceAccountName" -}}
51+
{{- if .Values.serviceAccount.create -}}
52+
{{ default (include "python-aws-exporter-base.fullname" .) .Values.serviceAccount.name }}
53+
{{- else -}}
54+
{{ default "default" .Values.serviceAccount.name }}
55+
{{- end -}}
56+
{{- end -}}

helm/templates/aws.secret.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Secret with AWS credentials from .Values
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: {{ include "python-aws-exporter-base.fullname" . }}-aws-credentials
6+
type: Opaque
7+
data:
8+
AWS_ACCESS_KEY_ID: {{ .Values.aws.access_key_id | b64enc | quote }}
9+
AWS_SECRET_ACCESS_KEY: {{ .Values.aws.secret_access_key | b64enc | quote }}
10+
AWS_REGION: {{ .Values.aws.region | b64enc | quote }}
11+

helm/templates/configmap.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ include "python-aws-exporter-base.fullname" . }}-configmap
5+
data:
6+
7+
{{ if .Values.pip_install }}
8+
requirements.txt: |-
9+
{{ .Values.pip_install | indent 4 }}
10+
{{ end }}
11+
12+
script.py: |
13+
{{ .Values.script_py | indent 4 }}

helm/templates/deployment.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: {{ include "python-aws-exporter-base.fullname" . }}
5+
spec:
6+
replicas: {{ .Values.replicaCount }}
7+
selector:
8+
matchLabels:
9+
app: {{ include "python-aws-exporter-base.fullname" . }}
10+
template:
11+
metadata:
12+
labels:
13+
app: {{ include "python-aws-exporter-base.fullname" . }}
14+
annotations:
15+
# aws.secret.yaml checksum
16+
checksum/aws.secret.yaml: {{ include (print $.Template.BasePath "/aws.secret.yaml") . | sha256sum }}
17+
checksum/configmap.yaml: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
18+
19+
spec:
20+
containers:
21+
- name: python-script
22+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
23+
imagePullPolicy: {{ .Values.image.pullPolicy }}
24+
{{ if .Values.pip_install }}
25+
command: ["sh", "-c", "pip install -r /script/requirements.txt && python /script/script.py"]
26+
{{ else }}
27+
args: ["/script/script.py"]
28+
{{ end }}
29+
volumeMounts:
30+
- name: python-script
31+
mountPath: /script
32+
ports:
33+
- name: http
34+
containerPort: 8000
35+
env:
36+
- name: AWS_ACCESS_KEY_ID
37+
valueFrom:
38+
secretKeyRef:
39+
name: {{ include "python-aws-exporter-base.fullname" . }}-aws-credentials
40+
key: AWS_ACCESS_KEY_ID
41+
- name: AWS_SECRET_ACCESS_KEY
42+
valueFrom:
43+
secretKeyRef:
44+
name: {{ include "python-aws-exporter-base.fullname" . }}-aws-credentials
45+
key: AWS_SECRET_ACCESS_KEY
46+
- name: AWS_REGION
47+
valueFrom:
48+
secretKeyRef:
49+
name: {{ include "python-aws-exporter-base.fullname" . }}-aws-credentials
50+
key: AWS_REGION
51+
resources:
52+
{{ toYaml .Values.resources | indent 12 }}
53+
volumes:
54+
- name: python-script
55+
configMap:
56+
name: {{ include "python-aws-exporter-base.fullname" . }}-configmap

helm/templates/service.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: {{ include "python-aws-exporter-base.fullname" . }}
5+
labels:
6+
app: {{ include "python-aws-exporter-base.fullname" . }}
7+
spec:
8+
type: ClusterIP
9+
ports:
10+
- port: 8000
11+
targetPort: http
12+
protocol: TCP
13+
name: http
14+
selector:
15+
app: {{ include "python-aws-exporter-base.fullname" . }}

helm/templates/servicemonitor.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- if .Values.serviceMonitor.enabled }}
2+
apiVersion: monitoring.coreos.com/v1
3+
kind: ServiceMonitor
4+
metadata:
5+
name: {{ include "python-aws-exporter-base.fullname" . }}
6+
spec:
7+
selector:
8+
matchLabels:
9+
app: {{ include "python-aws-exporter-base.fullname" . }}
10+
endpoints:
11+
- port: http
12+
interval: {{ .Values.serviceMonitor.interval }}
13+
scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }}
14+
path: /
15+
{{- end }}

helm/values.test.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
aws:
2+
access_key_id: AKIAT2IIDSITZ7JKTCEF
3+
secret_access_key: XXXXX
4+
region: eu-central-1

helm/values.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
replicaCount: 1
2+
3+
aws:
4+
access_key_id:
5+
secret_access_key:
6+
region:
7+
8+
script_py: |
9+
while True:
10+
print("Hello World")
11+
12+
image:
13+
repository: ghcr.io/container-driven-development/python-aws-exporter-base
14+
pullPolicy: IfNotPresent
15+
# tag: v0.1
16+
17+
pip_install:
18+
# pip_install: |
19+
# antigravity==0.1
20+
21+
nameOverride: ""
22+
fullnameOverride: ""
23+
24+
serviceMonitor:
25+
enabled: true
26+
interval: 3600s
27+
scrapeTimeout: 30s
28+
29+
service:
30+
type: ClusterIP
31+
port: 8000
32+
33+
resources:
34+
limits:
35+
memory: 160Mi
36+
requests:
37+
cpu: 50m
38+
memory: 128Mi
39+

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
boto3==1.28.19
22
prometheus_client==0.17.1
3+
python_json_logger==2.0.7

0 commit comments

Comments
 (0)