Skip to content

Commit

Permalink
First attempt at a common chart
Browse files Browse the repository at this point in the history
  • Loading branch information
Wattos committed Jun 1, 2023
1 parent 805a09c commit 535bc71
Show file tree
Hide file tree
Showing 13 changed files with 286 additions and 0 deletions.
12 changes: 12 additions & 0 deletions charts/common/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
name: common
version: "1.0.0"
kubeVersion: ">=1.23.0-0"
description: The common chart
appVersion: "v1"
home: https://github.com/wattos/home-lab-charts
maintainers:
- email: [email protected]
name: wattos
sources:
- https://github.com/wattos/home-lab-charts
16 changes: 16 additions & 0 deletions charts/common/templates/_common.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{/*
Main entrypoint for the common library chart. It will render all underlying templates based on the provided values.
*/}}
{{- define "common.all" -}}

{{- include "common.values.setup" . }}

{{ include "common.volume" . | nindent 0 }}

{{ include "common.deployment" . | nindent 0 }}

{{ include "common.service" . | nindent 0 }}

{{ include "common.ingress" . | nindent 0 }}

{{- end -}}
51 changes: 51 additions & 0 deletions charts/common/templates/_deployment.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{- define "common.deployment" -}}
{{- if .Values.deployment.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "common.names.fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
selector:
matchLabels:
app: {{ include "common.names.fullname" . }}
replicas: {{ default 1 .Values.deployment.replicaCount | int }}
strategy:
type: Recreate
template:
metadata:
labels:
app: {{ include "common.names.fullname" . }}
spec:
containers:
- name: {{ include "common.names.fullname" . }}
image: {{ .Values.deployment.image }}
imagePullPolicy: Always
ports:
- containerPort: {{ .Values.deployment.port | int }}
env:
{{- toYaml .Values.deployment.env | nindent 8 }}
volumeMounts:
{{- if .Values.storage.mounts.config.enabled }}
- name: {{ include "common.names.name" . }}-config
mountPath: /config
{{- end }}
{{- if .Values.storage.mounts.media.enabled }}
- name: {{ include "common.names.name" . }}-media
mountPath: /media
{{- end }}
volumes:
{{- if .Values.storage.mounts.config.enabled }}
- name: {{ include "common.names.name" . }}-config
persistentVolumeClaim:
claimName: {{ include "common.names.name" . }}-config
{{- end }}
{{- if .Values.storage.mounts.media.enabled }}
- name: {{ include "common.names.name" . }}-media
nfs:
server: "{{ .Values..storage.mounts.media.volume.nfs.server }}"
path: "{{ .Values..storage.mounts.media.volume.nfs.path }}"
{{- end }}
{{- end }}
{{- end }}
32 changes: 32 additions & 0 deletions charts/common/templates/_ingress.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{- define "common.ingress" -}}
{{- if .Values.ingress.enabled -}}
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "common.names.fullname" . }}
labels:
app: {{ include "common.names.fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
annotations:
kubernetes.io/tls-acme: "true"
{{- toYaml .Values.ingress.annotations | nindent 4 }}
spec:
rules:
- host: {{ .Values.ingress.host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ include "common.names.fullname" . }}
port:
number: 80
tls:
- secretName: {{ include "common.names.name" . }}-cert
hosts:
- {{ .Values.ingress.host }}
{{- end -}}
{{- end }}
19 changes: 19 additions & 0 deletions charts/common/templates/_service.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- define "common.service" -}}
{{- if .Values.service.enabled -}}
apiVersion: v1
kind: Service
metadata:
name: {{ include "common.names.fullname" . }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}"
spec:
ports:
- name: {{ include "common.names.fullname" . }}
port: 80
targetPort: {{ .Values.deployment.port | int }}

selector:
app: {{ include "common.names.fullname" . }}

{{- end -}}
{{- end }}
15 changes: 15 additions & 0 deletions charts/common/templates/_volume.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- define "common.volume" -}}
{{- if .Values.storage.mounts.config.enabled }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "common.names.name" . }}-config
spec:
accessModes:
- ReadWriteOnce
storageClassName: "{{ .Values.storage.mounts.config.storageClassName }}"
resources:
requests:
storage: "{{ .Values.storage.mounts.config.size }}"
{{- end -}}
{{- end }}
30 changes: 30 additions & 0 deletions charts/common/templates/lib/_names.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{- define "common.names.name" -}}
{{- $globalNameOverride := "" -}}
{{- if hasKey .Values "global" -}}
{{- $globalNameOverride = (default $globalNameOverride .Values.global.nameOverride) -}}
{{- end -}}
{{- default .Chart.Name (default .Values.nameOverride $globalNameOverride) | trunc 63 | trimSuffix "-" -}}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "common.names.fullname" -}}
{{- $name := include "common.names.name" . -}}
{{- $globalFullNameOverride := "" -}}
{{- if hasKey .Values "global" -}}
{{- $globalFullNameOverride = (default $globalFullNameOverride .Values.global.fullnameOverride) -}}
{{- end -}}
{{- if or .Values.fullnameOverride $globalFullNameOverride -}}
{{- $name = default .Values.fullnameOverride $globalFullNameOverride -}}
{{- else -}}
{{- if contains $name .Release.Name -}}
{{- $name = .Release.Name -}}
{{- else -}}
{{- $name = printf "%s-%s" .Release.Name $name -}}
{{- end -}}
{{- end -}}
{{- trunc 63 $name | trimSuffix "-" -}}
{{- end -}}
9 changes: 9 additions & 0 deletions charts/common/templates/lib/_values.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{/* Merge the local chart values and the common chart defaults */}}
{{- define "common.values.setup" -}}
{{- if .Values.common -}}
{{- $defaultValues := deepCopy .Values.common -}}
{{- $userValues := deepCopy (omit .Values "common") -}}
{{- $mergedValues := mustMergeOverwrite $defaultValues $userValues -}}
{{- $_ := set . "Values" (deepCopy $mergedValues) -}}
{{- end -}}
{{- end -}}
29 changes: 29 additions & 0 deletions charts/common/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
deployment:
enabled: true
image:
port:
replicaCount: 1
env: []

ingress:
enabled: true
annotations: {}
host:

service:
enabled: false

storage:
mounts:
config:
enabled: false
storageClassName:
size: 200Mi

media:
enabled: false
volume:
nfs:
path:
server:

21 changes: 21 additions & 0 deletions charts/sabnzbd/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
16 changes: 16 additions & 0 deletions charts/sabnzbd/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
name: sabnzbd
version: "1.0.0"
kubeVersion: ">=1.23.0-0"
description: Helm Chart to deploy sabnzbd
appVersion: "v3"
home: https://github.com/wattos/home-lab-charts
maintainers:
- email: [email protected]
name: wattos
dependencies:
- name: common
version: "1.0.0"
repository: "file://../common"
sources:
- https://github.com/wattos/home-lab-charts
1 change: 1 addition & 0 deletions charts/sabnzbd/templates/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ include "common.all" . }}
35 changes: 35 additions & 0 deletions charts/sabnzbd/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
deployment:
enabled: true
image: "lscr.io/linuxserver/sabnzbd:latest"
port: 8080
replicaCount: 1
env:
- name: PUID
value: 1000
- name: PGID
value: 1000
- name: TZ
value: CET

ingress:
enabled: true
annotations: {}
host:

service:
enabled: true

storage:
mounts:
config:
enabled: true
storageClassName:
size: 500Mi

media:
enabled: true
volume:
nfs:
path:
server:

0 comments on commit 535bc71

Please sign in to comment.