first commit

This commit is contained in:
Jonas Forsberg 2024-10-15 16:19:57 +02:00
commit 869a756e4b
11 changed files with 449 additions and 0 deletions

23
.helmignore Normal file
View File

@ -0,0 +1,23 @@
# 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
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

11
Chart.yaml Normal file
View File

@ -0,0 +1,11 @@
---
apiVersion: v2
name: lib
description: Common functions for my helm charts at home
type: library
version: 0.0.0
kubeVersion: ">=1.27.0"
home: git.rre.nu
maintainers:
- name: Jonas Forsberg
email: barregargamel@gmail.com

6
Makefile Normal file
View File

@ -0,0 +1,6 @@
NEW_VERSION:=$(shell yq '.version |= (split(".") | .[-1] |= ((. tag = "!!int") + 1) | join("."))' Chart.yaml | yq '.version')
branch:
@echo "New chart version is: $(NEW_VERSION)"
git checkout -b lib_$(NEW_VERSION)
yq '.version="$(NEW_VERSION)"' Chart.yaml

15
templates/_all.tpl Normal file
View File

@ -0,0 +1,15 @@
{{/*
Main entrypoint for the common library chart. It will render all underlying templates based on the provided values.
*/}}
{{- define "lib.all" -}}
{{- include "lib.values.setup" . }}
{{- if .Values.serviceAccount.create -}}
{{- include "lib.serviceaccount" . | nindent 0 }}
{{- end -}}
{{ include "lib.service" . | nindent 0 }}
{{ if eq .Values.controller.type "statefulset" }}
{{- include "lib.statefulset" . | nindent 0}}
{{- end -}}
{{- end -}}

72
templates/_helpers.tpl Normal file
View File

@ -0,0 +1,72 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "lib.name" -}}
{{- default .Chart.Name .Values.nameOverride | 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 "lib.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "lib.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}
{{/*
Common labels
*/}}
{{- define "lib.labels" -}}
helm.sh/chart: {{ include "lib.chart" . }}
{{ include "lib.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
*/}}
{{- define "lib.selectorLabels" -}}
app.kubernetes.io/name: {{ include "lib.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
{{/*
Create the name of the service account to use
*/}}
{{- define "lib.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "lib.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
{{/* Merge the local chart values and the library chart defaults */}}
{{- define "lib.values.setup" -}}
{{- if .Values.lib -}}
{{- $defaultValues := deepCopy .Values.lib -}}
{{- $userValues := deepCopy (omit .Values "lib") -}}
{{- $mergedValues := mustMergeOverwrite $defaultValues $userValues -}}
{{- $_ := set . "Values" (deepCopy $mergedValues) -}}
{{- end -}}
{{- end -}}

62
templates/_ingress.tpl Normal file
View File

@ -0,0 +1,62 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "lib.fullname" . -}}
{{- $svcName := .Values.ingress.service -}}
{{- $svcPort := .Values.ingress.servicePort -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}}
{{- end }}
{{- end }}
{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1
{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}}
apiVersion: networking.k8s.io/v1beta1
{{- else -}}
apiVersion: extensions/v1beta1
{{- end }}
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "lib.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.ingress.className }}
{{- end }}
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

8
templates/_notes.tpl Normal file
View File

@ -0,0 +1,8 @@
{{/*
Default NOTES.txt content.
*/}}
{{- define "lib.defaultNotes" -}}
{{- end -}}

29
templates/_service.tpl Normal file
View File

@ -0,0 +1,29 @@
{{- define "lib.service" -}}
{{- $servicename := include "lib.fullname" . }}
{{- $labels := include "lib.labels" . }}
{{- $selectorlabels := include "lib.selectorLabels" . }}
{{- $ns := .Values.namespace }}
{{- range $name, $values := .Values.service }}
{{- if $values.enabled }}
---
apiVersion: v1
kind: Service
metadata:
name: {{ $servicename }}-{{ $name }}
namespace: {{ $ns }}
labels:
{{- $labels | nindent 4 }}
spec:
type: {{ $values.type }}
ports:
{{- range $k, $v := $values.ports }}
- port: {{ $v.port }}
targetPort: {{ default $v.targetPort $v.port }}
protocol: {{ $v.protocol }}
name: {{ $k }}
{{- end }}
selector:
{{- $selectorlabels | nindent 4 }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@ -0,0 +1,15 @@
{{- define "lib.serviceaccount" -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "lib.serviceAccountName" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "lib.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}

View File

@ -0,0 +1,79 @@
{{- define "lib.statefulset" }}
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "lib.fullname" . }}
namespace: {{ .Values.namespace }}
labels:
{{- include "lib.labels" . | nindent 4 }}
spec:
persistentVolumeClaimRetentionPolicy:
whenDeleted: Retain
whenScaled: Retain
replicas: {{ .Values.controller.replicas }}
selector:
matchLabels:
{{- include "lib.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.controller.annotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "lib.labels" . | nindent 8 }}
{{- with .Values.controller.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "lib.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.controller.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.controller.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
{{- range $name, $values := .Values.service -}}
{{- if $values.enabled -}}
{{- range $k, $v := $values.ports }}
- name: {{ $k }}
containerPort: {{ $v.targetPort | default $v.port }}
protocol: {{ $v.protocol }}
{{- end -}}
{{- end -}}
{{- end }}
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end -}}

129
values.yaml Normal file
View File

@ -0,0 +1,129 @@
---
# Namespace to deploy to, if not set it targets default namespace
namespace: default
controller:
# -- enable the controller
enabled: true
# type of controller
# valid options are deployment, statefulset, job
type: deployment
annotations: {}
labels: {}
replicas: 1
podSecurityContext: {}
securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000
image:
repository:
pullPolicy:
# Overrides the image tag whose default is the chart appVersion.
tag: ""
imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
serviceAccount:
# Specifies whether a service account should be created
create: true
# Automatically mount a ServiceAccount's API credentials?
automount: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
service:
main:
enabled: false
type: ClusterIP
annotations: {}
labels: {}
ports: {}
# http:
# # -- Enables or disables the port
# enabled: false#
#
# # -- The port number
# port:
#
# # -- Port protocol.
# # Support values are `HTTP`, `HTTPS`, `TCP` and `UDP`.
# # HTTPS and HTTPS spawn a TCP service and get used for internal URL and name generation
# protocol: HTTP
#
# # -- Specify a service targetPort if you wish to differ the service port from the application port.
# # If `targetPort` is specified, this port number is used in the container definition instead of
# # the `port` value. Therefore named ports are not supported for this field.
# targetPort:
#
# # -- Specify the nodePort value for the LoadBalancer and NodePort service types.
# # [[ref]](https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport)
# nodePort:
ingress:
main:
enabled: false
className: ""
annotations: {}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
service: main
servicePort: 80
hosts:
- host: chart-example.local
paths:
- path: /
pathType: ImplementationSpecific
tls: []
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi
autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 5
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80
# Additional volumes on the output Deployment definition.
volumes: []
# - name: foo
# secret:
# secretName: mysecret
# optional: false
# Additional volumeMounts on the output Deployment definition.
volumeMounts: []
# - name: foo
# mountPath: "/etc/foo"
# readOnly: true
nodeSelector: {}
tolerations: []
affinity: {}