17 Commits

Author SHA1 Message Date
Jonas Forsberg
0fe6d615a0 .
All checks were successful
Package and publish helm chart / package-helm (push) Successful in 14s
2024-10-22 14:29:12 +02:00
Jonas Forsberg
d4a800e3d4 . 2024-10-19 11:30:12 +02:00
Jonas Forsberg
04aa844ce6 . 2024-10-19 11:29:25 +02:00
Jonas Forsberg
4f2a9ba9b7 . 2024-10-19 11:23:43 +02:00
Jonas Forsberg
dd11ed2197 fixed default varable 2024-10-19 11:09:04 +02:00
Jonas Forsberg
817fdf175a added deployment 2024-10-19 11:00:59 +02:00
3cd2466816 Merge pull request 'hooks' (#2) from hooks into main
All checks were successful
Lint and Test Charts / lint-test (push) Successful in 9s
Reviewed-on: #2
2024-10-19 06:55:27 +00:00
Jonas Forsberg
5b8b037905 . 2024-10-19 08:54:28 +02:00
Jonas Forsberg
088ce48d6c fixed pre-commit 2024-10-19 08:53:12 +02:00
cf63ca5dc5 Merge pull request 'added *.tgz' (#1) from jonas-patch-1 into main
All checks were successful
Lint and Test Charts / lint-test (push) Successful in 7s
Reviewed-on: #1
2024-10-18 14:46:59 +00:00
5ec2a72505 added *.tgz 2024-10-18 14:46:49 +00:00
Jonas Forsberg
82caca32d4 removed hardcoded version in example
All checks were successful
Lint and Test Charts / lint-test (push) Successful in 7s
2024-10-18 16:42:00 +02:00
Jonas Forsberg
0204cc88db added env.TZ default value
All checks were successful
Lint and Test Charts / lint-test (push) Successful in 7s
2024-10-18 16:39:39 +02:00
Jonas Forsberg
f7fd24fe6f fixed trailing whitespaces
All checks were successful
Lint and Test Charts / lint-test (push) Successful in 7s
2024-10-18 16:24:24 +02:00
Jonas Forsberg
bc9963a6ca added init
All checks were successful
Lint and Test Charts / lint-test (push) Successful in 7s
2024-10-18 16:02:44 +02:00
Jonas Forsberg
9222a6f811 added githooks
All checks were successful
Lint and Test Charts / lint-test (push) Successful in 7s
2024-10-18 16:01:00 +02:00
Jonas Forsberg
4f5f14adfc fixed repository entry
All checks were successful
Lint and Test Charts / lint-test (push) Successful in 7s
2024-10-18 15:39:20 +02:00
17 changed files with 177 additions and 104 deletions

View File

@@ -10,8 +10,8 @@ to use, add this to your Charts.yaml
```
dependencies:
- name: lib
repository: "repo.rre.nu/helm"
version: 1.0.0
repository: oci://repo.rre.nu/helm
version: <chart version>
```

View File

@@ -21,3 +21,4 @@
.idea/
*.tmproj
.vscode/
*.tgz

6
CHANGES.md Normal file
View File

@@ -0,0 +1,6 @@
# next
- added env.TZ to default to Europe/Stockholm
- added deployment type
# v1.0.0
- first version

View File

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

View File

@@ -6,8 +6,8 @@ to use, add this to your Charts.yaml
```
dependencies:
- name: lib
repository: "repo.rre.nu/helm"
version: 1.0.0
repository: oci://repo.rre.nu/helm
version: <chart version>
```
Common functions for my helm charts at home
@@ -22,6 +22,9 @@ The following table lists the configurable parameters of the Lib chart and their
| `controller.enabled` | should the main workload be included or not | `true` |
| `controller.type` | valid options are deployment, statefulset, job | `"deployment"` |
| `controller.replicas` | number of replicas | `1` |
| `controller.lifecycle` | Define postStart and preStop handlers | `{}` |
| `controller.command` | override the containers entrypoint | `null` |
| `controller.args` | add argument to the override command | `[]` |
| `image.repository` | container image name | `null` |
| `image.pullPolicy` | kubernetes pull policy | `"IfNotPresent"` |
| `image.tag` | Overrides the image tag whose default is the chart appVersion. | `""` |
@@ -45,7 +48,8 @@ The following table lists the configurable parameters of the Lib chart and their
| `autoscaling.targetCPUUtilizationPercentage` | | `80` |
| `secrets` | Secrets that needs to be created | `{}` |
| `configs` | ConfigMaps that needs to be created | `{}` |
| `env` | environment variables the controller should have | `{}` |
| `envFrom` | mount environment variables from secrets or configMaps | `[]` |
| `env.TZ` | | `"Europe/Stockholm"` |
| `volumes` | | `[]` |
| `volumeMounts` | | `[]` |
| `volumeClaimTemplates` | used for statefulset https://kubernetes.io/docs/concepts/workloads/controllers/statefulset | `[]` |

View File

@@ -14,9 +14,9 @@ Main entrypoint for the common library chart. It will render all underlying temp
{{ include "lib.configs" . | nindent 0 }}
{{ if .Values.controller.enabled }}
{{ if eq .Values.controller.type "statefulset" }}
{{- include "lib.statefulset" . | nindent 0}}
{{- include "lib.statefulset" . | nindent 0 }}
{{ else if eq .Values.controller.type "deployment" }}
{{- include "lib.deployment" . | nindent 0 }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -1,6 +1,6 @@
{{- define "lib.configs" -}}
{{- $fullName := include "lib.fullname" . -}}
{{- $namespace := .Values.namespace -}}
{{- $namespace := .Values.namespace | default "default" -}}
{{- $commonLabels := include "lib.labels" . }}
{{- range $name, $values := .Values.configs }}
{{- if $values.enabled -}}
@@ -25,4 +25,4 @@ data:
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}
{{- end -}}

53
templates/_deployment.tpl Normal file
View File

@@ -0,0 +1,53 @@
{{- define "lib.deployment" -}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "lib.fullname" . }}
labels:
{{- include "lib.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "lib.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
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.podSecurityContext | nindent 8 }}
containers:
{{- include "lib.parts.container" . | nindent 8 -}}
{{- 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 }}

View File

@@ -61,8 +61,8 @@ Create the name of the service account to use
{{- end }}
{{- end }}
{{/*
Merge the local chart values and the library chart defaults
{{/*
Merge the local chart values and the library chart defaults
*/}}
{{- define "lib.values.setup" -}}
{{- if .Values.lib -}}
@@ -72,54 +72,3 @@ Merge the local chart values and the library chart defaults
{{- $_ := set . "Values" (deepCopy $mergedValues) -}}
{{- end -}}
{{- end -}}
{{/*
Get all environment variables and
secrets that should be mounted as environment variables
*/}}
{{- define "lib.environmentVariables" -}}
{{- $envIncluded := "false" -}}
{{- $fullName := include "lib.fullname" . -}}
{{- range $name, $settings := .Values.secrets -}}
{{- if $settings.enabled -}}
{{- if $settings.env -}}
{{- $envIncluded := "true" -}}
{{- range $key, $value := $settings.data }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: {{ $fullName }}-{{ $name }}
key: {{ $key }}
{{- end -}}
{{- range $key, $value := $settings.stringData }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: {{ $fullName }}-{{ $name }}
key: {{ $key }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- range $name, $settings := .Values.configs -}}
{{- if $settings.enabled -}}
{{- if $settings.env -}}
{{- $envIncluded := "true" -}}
{{- range $key, $value := $settings.data }}
- name: {{ $key }}
valueFrom:
configMapKeyRef:
name: {{ $fullName }}-{{ $name }}
key: {{ $key }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $envIncluded = "true" -}}
{{- if .Values.env -}}
{{- toYaml .Values.env | nindent 0 -}}
{{- end -}}
{{- else -}}
{{- toYaml .Values.env | nindent 0 -}}
{{- end -}}
{{- end -}}

View File

@@ -7,6 +7,7 @@
{{- $_ := 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 -}}
@@ -20,8 +21,7 @@ metadata:
namespace: {{ .Values.namespace }}
labels:
{{- include "lib.labels" . | nindent 4 }}
{{- with .Values.ingressingresstservicePort }}
{{- $svcName := .Values.ingress.service -}}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
@@ -52,7 +52,7 @@ spec:
backend:
{{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}-${{ $svcName }}
name: {{ $fullName }}-{{ $svcName }}
port:
number: {{ $svcPort }}
{{- else }}

View File

@@ -1,6 +1,6 @@
{{- define "lib.secrets" -}}
{{- $fullName := include "lib.fullname" . -}}
{{- $namespace := .Values.namespace -}}
{{- $namespace := .Values.namespace | default "default" -}}
{{- $commonLabels := include "lib.labels" . }}
{{- range $name, $values := .Values.secrets }}
{{- if $values.enabled -}}
@@ -30,4 +30,4 @@ stringData:
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -14,16 +14,16 @@ metadata:
labels:
{{- $labels | nindent 4 }}
spec:
type: {{ $values.type }}
type: {{ default "ClusterIP" $values.type }}
ports:
{{- range $k, $v := $values.ports }}
- port: {{ $v.port }}
targetPort: {{ default $v.targetPort $v.port }}
protocol: {{ $v.protocol }}
targetPort: {{ default $v.port $v.targetPort }}
protocol: {{ default "TCP" $v.protocol }}
name: {{ $k }}
{{- end }}
selector:
{{- $selectorlabels | nindent 4 }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -12,4 +12,4 @@ metadata:
{{- toYaml . | nindent 4 }}
{{- end }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
{{- end }}

View File

@@ -35,34 +35,7 @@ spec:
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 }}
env:
{{- include "lib.environmentVariables" . | default "[]" | nindent 12 }}
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
{{- range $i, $values := .Values.volumeClaimTemplates }}
- name: {{ $values.name }}
mountPath: {{ $values.mountPath }}
{{- end }}
{{- include "lib.parts.container" . | nindent 8 -}}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}

View File

@@ -0,0 +1,47 @@
{{- define "lib.parts.container" -}}
{{/*
create the environment varable list
*/}}
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 4 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.controller.command }}
command: {{ toYaml . | nindent 4}}
{{- end }}
{{- with .Values.controller.args }}
args: {{ toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.controller.lifecycle }}
lifecycle:
{{- toYaml . | nindent 4 }}
{{- end }}
ports:
{{- range $name, $values := .Values.service -}}
{{- if $values.enabled -}}
{{- range $k, $v := $values.ports }}
- name: {{ $k }}
containerPort: {{ default $v.port $v.targetPort }}
{{- end -}}
{{- end -}}
{{- end }}
env:
{{- include "lib.parts.env" . | nindent 4 -}}
{{- with .Values.livenessProbe }}
livenessProbe:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.readinessProbe }}
readinessProbe:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

26
templates/parts/_env.tpl Normal file
View File

@@ -0,0 +1,26 @@
{{/*
Get all environment variables configMaps and
secrets that should be mounted as environment variables
*/}}
{{- define "lib.parts.env" -}}
{{/*
environment variables from .Values.env
*/}}
{{- range $name, $value := .Values.env -}}
{{- printf "- name: %s" $name | nindent 0 }}
{{- printf "value: %s" $value | nindent 2 }}
{{- end -}}
{{/*
environment variables from configMaps
*/}}
{{- range $cfgName, $settings := .Values.configs -}}
{{- if and $settings.enabled $settings.env -}}
{{- range $key, $value := $settings.data -}}
{{- printf "- name: %s" $key | nindent 0 }}
{{- printf "valueFrom:" | nindent 2 }}
{{- printf "configMapKeyRef:" | nindent 4 }}
{{- printf "name: %s" $key | nindent 5 }}
{{- end }}
{{- end }}
{{- end -}}
{{- end -}}

View File

@@ -4,6 +4,9 @@ controller: # main workload
enabled: true # should the main workload be included or not
type: deployment # valid options are deployment, statefulset, job
replicas: 1 # number of replicas
lifecycle: {} # Define postStart and preStop handlers
command: # override the containers entrypoint
args: [] # add argument to the override command
image:
repository: # container image name
@@ -85,20 +88,26 @@ secrets: {} # Secrets that needs to be created
# type: #default Opaque
# annotations: {}
# labels: {}
# env: false #should template load each key in the seacret as
# data:
# KEY: VALUE
configs: {} # ConfigMaps that needs to be created
# configs:
# <name>:
# enabled: false # should the configMap be created or not
# annotations: {}
# labels: {}
# env: false #should template load each key in the seacret as
# data:
# KEY: VALUE
env: {} # environment variables the controller should have
envFrom: [] # mount environment variables from secrets or configMaps
# - configMapRef:
# name: config-map-name
# - secretRef:
# name: secret-name
env: # environment variables the controller should have
TZ: Europe/Stockholm
# Additional volumes on the output Deployment definition.
volumes: []