Skip to content

Commit

Permalink
[GENERIC] Add a generic chart to deploy simple containers
Browse files Browse the repository at this point in the history
  • Loading branch information
rouja committed Apr 30, 2024
1 parent 0b3592d commit 15c74a4
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 0 deletions.
4 changes: 4 additions & 0 deletions charts/generic/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v2
name: generic
type: application
version: 0.0.1-devel
4 changes: 4 additions & 0 deletions charts/generic/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- define "custom.labels" -}}
app: {{ .name }}
version: {{ .image.tag }}
{{- end -}}
123 changes: 123 additions & 0 deletions charts/generic/templates/_stack.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{{- define "custom.stack" -}}
{{- if .Values.components }}
{{- range $key, $component := .Values.components }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $component.name }}
namespace: {{ $.Release.Namespace | quote }}
labels:
{{ include "custom.labels" $component | indent 4 }}
spec:
replicas: {{ $component.replicas }}
{{- if hasKey $component.strategy "type" }}
strategy:
type: {{ $component.strategy.type }}
{{ end -}}
selector:
matchLabels:
{{ include "custom.labels" $component | indent 6 }}
template:
metadata:
labels:
{{ include "custom.labels" $component | indent 8 }}
spec:
{{- if $component.securityContext }}
securityContext:
{{ toYaml $component.securityContext | indent 8 }}
{{- end }}
{{ if $component.volumes -}}
volumes:
{{ toYaml $component.volumes | indent 8 }}
{{ end -}}
{{- if $component.initContainers }}
initContainers:
{{ toYaml $component.initContainers | indent 8 }}
{{- end }}
containers:
- name: {{ $component.name }}
{{- if $component.env }}
env:
{{ toYaml $component.env | indent 12 }}
{{ end -}}
{{- if $component.resources -}}
resources:
{{ toYaml $component.resources | indent 12 }}
{{- end -}}
{{- if $component.volumeMounts }}
volumeMounts:
{{ toYaml $component.volumeMounts | indent 12 }}
{{ end -}}
imagePullPolicy: {{ $component.image.pullPolicy }}
image: {{ $component.image.repository }}:{{ $component.image.tag }}
{{- with $component.ports }}
ports:
{{- range $key, $port := $component.ports }}
- containerPort: {{ $port.port }}
{{- end }}
{{- end }}
{{- if $component.sidecars }}
{{ toYaml $component.sidecars | indent 8 }}
{{ end }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ $component.name }}
namespace: {{ $.Release.Namespace | quote }}
labels:
{{ include "custom.labels" $component | indent 4 }}
spec:
selector:
{{ include "custom.labels" $component | indent 4 }}
ports:
{{- range $key, $port := $component.ports }}
- protocol: TCP
port: {{ $port.port }}
targetPort: {{ $port.port }}
{{ end }}
---
{{- range $key, $port := $component.ports }}
{{ if $port.ingress }}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
{{- if $port.ingress.annotations }}
annotations:
{{ toYaml $port.ingress.annotations | indent 4 }}
{{- end }}
name: {{ $component.name }}-{{ $port.port }}
namespace: {{ $.Release.Namespace | quote }}
labels:
{{ include "custom.labels" $component | indent 4 }}
spec:
ingressClassName: {{ $port.ingress.ingressClass | default "nginx" }}
{{- range $key2, $port2 := $component.ports }}
rules:
{{- if $port2.ingress }}
- host: {{ $port2.ingress.host }}
http:
paths:
- pathType: Prefix
path: {{ $port2.ingress.path | default "/" }}
backend:
service:
name: {{ $component.name }}
port:
number: {{ $port2.port }}
{{- end -}}
{{- end -}}
{{- range $key2, $port2 := $component.ports }}
tls:
{{- if $port2.ingress.tls }}
- hosts:
- {{ $port2.ingress.host }}
secretName: {{ $component.name }}-{{ $port2.port }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{- end -}}
{{- end -}}
{{- end -}}
1 change: 1 addition & 0 deletions charts/generic/templates/stack.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ include "custom.stack" . }}
44 changes: 44 additions & 0 deletions charts/generic/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
components:
- name: languagetool
env:
- name: toto
value: tutu
replicas: 3
securityContext:
runAsUser: 1000
fsGroup: 1000
sidecars:
- name: goofys
image: goofys
initContainers:
- name: ubuntu
image: ubuntu
strategy:
type: Recreate
volumes:
- name: config-vol
configMap:
name: log-config
items:
- key: log_level
path: log_leve
volumeMounts:
- name: config-vol
mountPath: /etc/config
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
ports:
- port: 8010
ingress:
annotations:
cert-manager.io/cluster-issuer: demo
host: toto.exemple.com
tls: true
image:
repository: erikvl87/languagetool
tag: latest
pullPolicy: IfNotPresent

0 comments on commit 15c74a4

Please sign in to comment.