Skip to content

Commit

Permalink
feat: adding volumes and some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Crty committed May 16, 2024
1 parent e550f33 commit d5280cc
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 32 deletions.
2 changes: 1 addition & 1 deletion charts/generic-app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: generic-app
description: A Helm Chart for Generic App
type: application
version: 0.1.10
version: 0.2.0
sources:
- https://github.com/David-Crty/helm-chart
maintainers:
Expand Down
2 changes: 1 addition & 1 deletion charts/generic-app/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
kind: ConfigMap
apiVersion: v1
metadata:
name: env-configmap-{{ $fullName }}
name: {{ $fullName }}
data:
{{- range $key, $value := $values.env }}
{{ $key }}: "{{ $value }}"
Expand Down
8 changes: 4 additions & 4 deletions charts/generic-app/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{- $fullName := include "generic-app.fullname" . -}}
{{ $values := .Values }}
{{- if $values.cronjobs }}
{{- range $name, $cronjob := $values.cronjobs }}
{{- if $values.cronJobs }}
{{- range $name, $cronjob := $values.cronJobs }}
apiVersion: batch/v1
kind: CronJob
metadata:
Expand Down Expand Up @@ -33,11 +33,11 @@ spec:
envFrom:
{{- if $values.env }}
- configMapRef:
name: env-configmap-{{ $fullName }}
name: {{ $fullName }}
{{- end }}
{{- if $values.envEncrypted }}
- secretRef:
name: env-secret-{{ $fullName }}
name: {{ $fullName }}
{{- end }}
{{- end }}
restartPolicy: OnFailure
Expand Down
48 changes: 29 additions & 19 deletions charts/generic-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-{{ $fullName }}
name: {{ $fullName }}
labels:
{{- include "generic-app.labels" . | nindent 4 }}
annotations:
Expand All @@ -18,7 +18,7 @@ spec:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
type: {{ .Values.deploymentStrategy }}
template:
metadata:
labels:
Expand All @@ -36,8 +36,8 @@ spec:
{{- end }}
spec:
containers:
- name: web-{{ $fullName }}
image: {{ $values.image }}
- name: {{ $fullName }}
image: {{ $values.image }}:{{ $values.tag }}
imagePullPolicy: Always
ports:
- name: http
Expand All @@ -46,11 +46,11 @@ spec:
envFrom:
{{- if $values.env }}
- configMapRef:
name: env-configmap-{{ $fullName }}
name: {{ $fullName }}
{{- end }}
{{- if $values.envEncrypted }}
- secretRef:
name: env-secret-{{ $fullName }}
name: {{ $fullName }}
{{- end }}
{{- end }}
lifecycle:
Expand All @@ -70,38 +70,47 @@ spec:
port: http
failureThreshold: 60
periodSeconds: 5
readinessProbe:
httpGet:
path: {{ $values.healthCheckPath }}
port: http
failureThreshold: 1
periodSeconds: 5
{{- end }}
{{- if $values.volumes }}
volumeMounts:
{{- range $volumeName, $volume := $values.volumes }}
- name: {{ $volumeName }}
mountPath: {{ $volume.mountPath }}
{{- end }}
{{- end }}
{{- if $values.volumes }}
volumes:
{{- range $volumeName, $volume := $values.volumes }}
- name: {{ $volumeName }}
persistentVolumeClaim:
claimName: {{ $fullName }}-{{ $volumeName }}
{{- end }}
{{- end }}
---
{{- if $values.workers }}
{{- range $keyWorker, $valuesWorker := $values.workers }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: consumer-{{ $fullName }}-{{ $keyWorker }}
name: {{ $fullName }}-{{ $keyWorker }}
labels:
{{- include "generic-app.labels" $ | nindent 4 }}
spec:
revisionHistoryLimit: 3
selector:
matchLabels:
app.kubernetes.io/name: consumer-{{ $fullName }}-{{ $keyWorker }}
app.kubernetes.io/name: {{ $fullName }}-{{ $keyWorker }}
replicas: {{ $valuesWorker.replicas }}
template:
metadata:
labels:
app.kubernetes.io/name: consumer-{{ $fullName }}-{{ $keyWorker }}
app.kubernetes.io/name: {{ $fullName }}-{{ $keyWorker }}
annotations:
checksum/env: {{ $values.env | toString | sha256sum }}
checksum/envEncrypted: {{ $values.envEncrypted | toString | sha256sum }}
spec:
containers:
- name: consumer-{{ $fullName }}-{{ $keyWorker }}
- name: {{ $fullName }}-{{ $keyWorker }}
image: {{ $values.image }}
imagePullPolicy: Always
command:
Expand All @@ -112,12 +121,13 @@ spec:
envFrom:
{{- if $values.env }}
- configMapRef:
name: env-configmap-{{ $fullName }}
name: {{ $fullName }}
{{- end }}
{{- if $values.envEncrypted }}
- secretRef:
name: env-secret-{{ $fullName }}
name: {{ $fullName }}
{{- end }}
{{- end }}
{{- end }}
---
{{- end }}
18 changes: 18 additions & 0 deletions charts/generic-app/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# pvc from values.yaml
{{- range $volumeName, $volume := .Values.volumes }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ include "generic-app.fullname" . }}-{{ $volumeName }}
labels:
{{- include "generic-app.labels" $ | nindent 4 }}
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ $volume.size }}
storageClassName: {{ $volume.storageClass }}
volumeMode: Filesystem
---
{{- end }}
6 changes: 2 additions & 4 deletions charts/generic-app/templates/sealedsecret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: bitnami.com/v1alpha1
kind: SealedSecret
metadata:
name: env-secret-{{ $fullName }}
name: {{ $fullName }}
labels:
{{- include "generic-app.labels" . | nindent 4 }}
annotations:
Expand All @@ -14,9 +14,7 @@ spec:
{{ $key }}: {{ $value }}
{{- end }}
template:
data: null
metadata:
creationTimestamp: null
namespace: {{ .Release.Namespace }}
name: env-secret-{{ $fullName }}
name: {{ $fullName }}
{{- end }}
54 changes: 54 additions & 0 deletions charts/generic-app/tests/__snapshot__/deployment_test.yaml.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
should work:
1: |
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
link.argocd.argoproj.io/external-link: https://hello-world.com
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: generic-app
helm.sh/chart: generic-app-0.1.10
name: web-RELEASE-NAME-generic-app
spec:
replicas: 1
revisionHistoryLimit: 3
selector:
matchLabels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: generic-app
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
type: RollingUpdate
template:
metadata:
annotations:
checksum/env: 52133ddfcd583280388a8bbfb67a417b6b660f75bc63ec1b01beec811d4498ef
checksum/envEncrypted: 52133ddfcd583280388a8bbfb67a417b6b660f75bc63ec1b01beec811d4498ef
labels:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: generic-app
spec:
containers:
- image: map[tag:latest]
imagePullPolicy: Always
lifecycle:
preStop:
exec:
command:
- sleep
- "10"
name: web-RELEASE-NAME-generic-app
ports:
- containerPort: 80
name: http
volumeMounts:
- mountPath: /data
name: data
volumes:
- name: data
persistentVolumeClaim:
claimName: RELEASE-NAME-generic-app-data
13 changes: 13 additions & 0 deletions charts/generic-app/tests/deployment_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
suite: test deployment
templates:
- deployment.yaml
tests:
- it: should have volume mounts for data
set:
volumes:
data:
size: 1Gi
storageClass: ""
mountPath: /data
asserts:
- matchSnapshot: {}
12 changes: 9 additions & 3 deletions charts/generic-app/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
appName: demo-app
image: hello-world
tag: latest
port: 80
host: hello-world.com
https: false
Expand All @@ -11,10 +11,16 @@ workers: {}
# consumer:
# command: echo "hello world"
# replicas: 1
cronjobs: {}
cronJobs: {}
# cron-1:
# command: echo "hello world"
# schedule: "* * * * *"
env: {}
envEncrypted: {}
redirectHosts: []
redirectHosts: []
deploymentStrategy: RollingUpdate
volumes: {}
# data:
# size: 1Gi
# storageClass: ""
# mountPath: /data

0 comments on commit d5280cc

Please sign in to comment.