[common] 1.6.0 (#178)

Co-authored-by: Bernd Schörgers <bernd@bjws.nl>
Co-authored-by: bjws <bernd@bjws.nl>
This commit is contained in:
ᗪєνιη ᗷυнʟ 2020-11-23 07:55:12 -05:00 committed by GitHub
parent 158674fc45
commit 5f17e040e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 305 additions and 58 deletions

View File

@ -2,7 +2,7 @@ apiVersion: v2
name: common
description: Function library for k8s-at-home charts
type: library
version: 1.5.1
version: 1.6.0
keywords:
- k8s-at-home
- common

View File

@ -1,7 +1,10 @@
# Library chart for k8s@home media charts
## **THIS CHART IS NOT MEANT TO BE INSTALLED DIRECTLY**
This is a [Helm Library Chart](https://helm.sh/docs/topics/library_charts/#helm) for grouping common logic between k8s@home charts.
**WARNING: THIS CHART IS NOT MEANT TO BE INSTALLED DIRECTLY**
This is a [Helm Library Chart](https://helm.sh/docs/topics/library_charts/#helm). It's purpose is for grouping common logic between the k8s@home charts.
Since a lot of charts follow the same pattern this library was built to reduce maintenance cost between the charts that use it and try achieve a goal of being DRY.
## Introduction
@ -9,22 +12,84 @@ This chart provides common template helpers which can be used to develop new cha
## TL;DR
When using one of the many charts that uses this library be sure to view this [values.yaml](./values.yaml) for configuration options. Any setting here can be used to define what values your helm deployment will use.
For example using the helm CLI tool
```bash
helm install node-red \
--set image.repository="nodered/node-red" \
--set image.tag="1.2.5" \
--set env.TZ="America/New_York" \
k8s-at-home/node-red
```
or
```yaml
dependencies:
- name: common
version: 0.x.x
repository: https://k8s-at-home.com/charts/
# node-red-values.yaml
image:
repository: nodered/node-red
tag: 1.2.5
env:
TZ: America/New_York
```
```bash
$ helm dependency update
helm install node-red \
--values=./node-red-values.yaml \
k8s-at-home/node-red
```
## Creating a new chart
First be sure to checkout the many charts that already use this like [qBittorrent](../qbittorrent/), [node-red](../node-red/) or the many others in this repository.
Include this chart as a dependency in your `Chart.yaml` e.g.
```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "common.names.fullname" . }}
data:
myvalue: "Hello World"
# Chart.yaml
dependencies:
- name: common
version: x.x.x
repository: https://k8s-at-home.com/charts/
```
Write a `values.yaml` with some basic defaults you want to present to the user e.g.
```yaml
# Default values for node-red.
image:
repository: nodered/node-red
pullPolicy: IfNotPresent
tag: 1.2.5
strategy:
type: Recreate
# See more environment varaibles in the node-red documentation
# https://nodered.org/docs/getting-started/docker
env: {}
# TZ:
# NODE_OPTIONS:
# NODE_RED_ENABLE_PROJECTS:
# NODE_RED_ENABLE_SAFE_MODE:
# FLOWS:
service:
port:
port: 1880
persistence:
data:
enabled: false
emptyDir: false
mountPath: /data
```
If testing locally make sure you update the dependencies with:
```bash
helm dependency update
```

View File

@ -1,3 +1,6 @@
{{/*
Main entrypoint for the common library chart. It will render all underlying templates based on the provided values.
*/}}
{{- define "common.all" -}}
{{- /* Merge the local chart values and the common chart defaults */ -}}
{{- include "common.values.setup" . }}
@ -10,10 +13,16 @@
{{- /* Build the templates */ -}}
{{- include "common.pvc" . }}
{{- print "---" | nindent 0 -}}
{{- if eq .Values.controllerType "statefulset" }}
{{- include "common.statefulset" . | nindent 0 }}
{{ else }}
{{- if .Values.serviceAccount.create -}}
{{- include "common.serviceAccount" . }}
{{- print "---" | nindent 0 -}}
{{- end -}}
{{- if eq .Values.controllerType "deployment" }}
{{- include "common.deployment" . | nindent 0 }}
{{ else if eq .Values.controllerType "daemonset" }}
{{- include "common.daemonset" . | nindent 0 }}
{{ else if eq .Values.controllerType "statefulset" }}
{{- include "common.statefulset" . | nindent 0 }}
{{- end -}}
{{- print "---" | nindent 0 -}}
{{ include "common.service" . | nindent 0 }}

View File

@ -0,0 +1,74 @@
{{/*
This template serves as the blueprint for the DaemonSet objects that are created
within the common library.
*/}}
{{- define "common.daemonset" -}}
apiVersion: {{ include "common.capabilities.daemonset.apiVersion" . }}
kind: DaemonSet
metadata:
name: {{ include "common.names.fullname" . }}
labels:
{{- include "common.labels" . | nindent 4 }}
{{- with .Values.controllerLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.controllerAnnotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
selector:
matchLabels:
{{- include "common.labels.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "common.labels.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "common.names.serviceAccountName" . }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.hostNetwork }}
hostNetwork: {{ . }}
{{- end }}
{{- with .Values.dnsPolicy }}
dnsPolicy: {{ . }}
{{- end }}
{{- with .Values.initContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
{{- end }}
containers:
{{- include "common.controller.mainContainer" . | nindent 6 }}
{{- with .Values.additionalContainers }}
{{- toYaml . | nindent 6 }}
{{- end }}
volumes:
{{- include "common.controller.volumes" . | trim | nindent 6 }}
{{- with .Values.hostAliases }}
hostAliases:
{{- 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

@ -1,8 +1,12 @@
{{/*
This template serves as the blueprint for the Deployment objects that are created
within the common library.
*/}}
{{- define "common.deployment" -}}
apiVersion: {{ include "common.capabilities.deployment.apiVersion" . }}
kind: Deployment
metadata:
name: {{ template "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}
labels:
{{- include "common.labels" . | nindent 4 }}
{{- with .Values.controllerLabels }}
@ -34,10 +38,17 @@ spec:
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "common.names.serviceAccountName" . }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.hostNetwork }}
hostNetwork: {{ . }}
{{- end }}
{{- with .Values.dnsPolicy }}
dnsPolicy: {{ . }}
{{- end }}
{{- with .Values.initContainers }}
initContainers:
{{- toYaml . | nindent 8 }}
@ -51,6 +62,10 @@ spec:
volumes:
{{- include "common.controller.volumes" . | trim | nindent 6 }}
{{- with .Values.hostAliases }}
hostAliases:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}

View File

@ -1,3 +1,7 @@
{{/*
Renders the Ingress objects required by the chart by returning a concatinated list
of the main Ingress and any additionalIngresses.
*/}}
{{- define "common.ingress" -}}
{{- if .Values.ingress.enabled -}}
{{- $svcPort := .Values.service.port.port -}}

View File

@ -1,3 +1,7 @@
{{/*
Renders the PersistentVolumeClaim objects required by the chart by returning a concatinated list
of all the entries of the persistence key.
*/}}
{{- define "common.pvc" -}}
{{- /* Generate pvc as required */ -}}
{{- range $index, $PVC := .Values.persistence }}

View File

@ -1,3 +1,7 @@
{{/*
Renders the Service objects required by the chart by returning a concatinated list
of the main Service and any additionalServices.
*/}}
{{- define "common.service" -}}
{{- if .Values.service.enabled -}}
{{- /* Generate primary service */ -}}

View File

@ -0,0 +1,15 @@
{{/*
The ServiceAccount object to be created.
*/}}
{{- define "common.serviceAccount" -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "common.names.serviceAccountName" . }}
labels:
{{- include "common.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}

View File

@ -1,8 +1,12 @@
{{/*
This template serves as the blueprint for the StatefulSet objects that are created
within the common library.
*/}}
{{- define "common.statefulset" -}}
apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
kind: StatefulSet
metadata:
name: {{ template "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}
labels:
{{- include "common.labels" . | nindent 4 }}
{{- with .Values.controllerLabels }}
@ -35,6 +39,7 @@ spec:
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "common.names.serviceAccountName" . }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}

View File

@ -1,12 +1,12 @@
{{/*
The OpenVPN configmaps to be included
The VPN config and scripts to be included.
*/}}
{{- define "common.addon.vpn.configmap" -}}
{{- if or .Values.addons.vpn.configFile .Values.addons.vpn.scripts.up .Values.addons.vpn.scripts.down }}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "common.names.fullname" . }}-vpn
name: {{ include "common.names.fullname" . }}-vpn
labels:
{{- include "common.labels" . | nindent 4 }}
data:

View File

@ -1,12 +1,12 @@
{{/*
The OpenVPN networkpolicy to be included
Blueprint for the NetworkPolicy object that can be included in the addon.
*/}}
{{- define "common.addon.vpn.networkpolicy" -}}
{{- if .Values.addons.vpn.networkPolicy.enabled -}}
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: {{ template "common.names.fullname" . }}
name: {{ include "common.names.fullname" . }}
spec:
podSelector:
matchLabels:

View File

@ -1,11 +1,11 @@
{{/*
The OpenVPN shared volume to be inserted
The volume (referencing VPN config and scripts) to be inserted into additionalVolumes.
*/}}
{{- define "common.addon.vpn.volume" -}}
{{- if or .Values.addons.vpn.configFile .Values.addons.vpn.scripts.up .Values.addons.vpn.scripts.down -}}
name: vpnconfig
configMap:
name: {{ template "common.names.fullname" . }}-vpn
name: {{ include "common.names.fullname" . }}-vpn
items:
{{- if .Values.addons.vpn.configFile }}
- key: vpnConfigfile

View File

@ -1,5 +1,6 @@
{{/*
Template to render VPN addon
It will include / inject the required templates based on the given values.
*/}}
{{- define "common.addon.vpn" -}}
{{- if .Values.addons.vpn.enabled -}}

View File

@ -1,5 +1,6 @@
{{/*
Template to render OpenVPN addon
Template to render OpenVPN addon. It will add the container to the list of additionalContainers
and add a credentials secret if speciffied.
*/}}
{{- define "common.addon.openvpn" -}}
{{/* Append the openVPN container to the additionalContainers */}}

View File

@ -1,5 +1,5 @@
{{/*
The OpenVPN container(s) to be inserted
The OpenVPN sidecar container to be inserted.
*/}}
{{- define "common.addon.openvpn.container" -}}
name: openvpn
@ -22,7 +22,7 @@ envFrom:
{{- if .Values.addons.vpn.openvpn.authSecret }}
name: {{ .Values.addons.vpn.openvpn.authSecret }}
{{- else }}
name: {{ template "common.names.fullname" . }}-openvpn
name: {{ include "common.names.fullname" . }}-openvpn
{{- end }}
{{- end }}
{{- if or .Values.addons.vpn.configFile .Values.addons.vpn.scripts.up .Values.addons.vpn.scripts.down .Values.addons.vpn.additionalVolumeMounts .Values.persistence.shared.enabled }}

View File

@ -1,12 +1,12 @@
{{/*
The OpenVPN secrets to be included
The OpenVPN credentials secrets to be included.
*/}}
{{- define "common.addon.openvpn.secret" -}}
{{- with .Values.addons.vpn.openvpn.auth -}}
apiVersion: v1
kind: Secret
metadata:
name: {{ template "common.names.fullname" $ }}-openvpn
name: {{ include "common.names.fullname" $ }}-openvpn
labels:
{{- include "common.labels" $ | nindent 4 }}
data:

View File

@ -1,5 +1,6 @@
{{/*
Template to render Wireguard addon
Template to render Wireguard addon. It will add the container to the list of additionalContainers.
*/}}
*/}}
{{- define "common.addon.wireguard" -}}
{{/* Append the Wireguard container to the additionalContainers */}}

View File

@ -1,5 +1,5 @@
{{/*
The Wireguard container(s) to be inserted
The Wireguard sidecar container to be inserted.
*/}}
{{- define "common.addon.wireguard.container" -}}
name: wireguard

View File

@ -1,3 +1,7 @@
{{/*
This template serves as a blueprint for all Ingress objects that are created
within the common library.
*/}}
{{- define "common.classes.ingress" -}}
{{- $ingressName := include "common.names.fullname" . -}}
{{- $values := .Values.ingress -}}

View File

@ -1,3 +1,7 @@
{{/*
This template serves as a blueprint for all PersistentVolumeClaim objects that are created
within the common library.
*/}}
{{- define "common.classes.pvc" -}}
{{- $values := .Values.persistence -}}
{{- if hasKey . "ObjectValues" -}}

View File

@ -1,5 +1,6 @@
{{/*
service class: all services should adhere to this
This template serves as a blueprint for all Service objects that are created
within the common library.
*/}}
{{- define "common.classes.service" -}}
{{- $values := .Values.service -}}

View File

@ -1,5 +1,5 @@
{{/*
logic that lists the ports and additionalPorts for a service
Render all the ports and additionalPorts for a Service object.
*/}}
{{- define "common.classes.service.ports" -}}
{{- $ports := list -}}
@ -12,9 +12,9 @@ logic that lists the ports and additionalPorts for a service
ports:
{{- range $_ := $ports }}
- port: {{ .port }}
targetPort: {{ .targetPort | default .name }}
targetPort: {{ .targetPort | default "http" }}
protocol: {{ .protocol | default "TCP" }}
name: {{ .name }}
name: {{ .name | default "http" }}
{{- if (and (eq $.svcType "NodePort") (not (empty .nodePort))) }}
nodePort: {{ .nodePort }}
{{ end }}

View File

@ -1,5 +1,16 @@
{{/*
Return the appropriate apiVersion for deployment.
Return the appropriate apiVersion for DaemonSet objects.
*/}}
{{- define "common.capabilities.daemonset.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}
{{- print "extensions/v1beta1" -}}
{{- else -}}
{{- print "apps/v1" -}}
{{- end -}}
{{- end -}}
{{/*
Return the appropriate apiVersion for Deployment objects.
*/}}
{{- define "common.capabilities.deployment.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}
@ -10,7 +21,7 @@ Return the appropriate apiVersion for deployment.
{{- end -}}
{{/*
Return the appropriate apiVersion for statefulset.
Return the appropriate apiVersion for StatefulSet objects.
*/}}
{{- define "common.capabilities.statefulset.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}
@ -21,7 +32,7 @@ Return the appropriate apiVersion for statefulset.
{{- end -}}
{{/*
Return the appropriate apiVersion for ingress.
Return the appropriate apiVersion for Ingress objects.
*/}}
{{- define "common.capabilities.ingress.apiVersion" -}}
{{- if semverCompare "<1.14-0" .Capabilities.KubeVersion.GitVersion -}}

View File

@ -1,5 +1,5 @@
{{/*
Common labels
Common labels shared across objects.
*/}}
{{- define "common.labels" -}}
helm.sh/chart: {{ include "common.names.chart" . }}
@ -11,7 +11,7 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}
{{/*
Selector labels
Selector labels shared across objects.
*/}}
{{- define "common.labels.selectorLabels" -}}
app.kubernetes.io/name: {{ include "common.names.name" . }}

View File

@ -31,11 +31,11 @@ Create chart name and version as used by the chart label.
{{- end }}
{{/*
Create the name of the service account to use
Create the name of the ServiceAccount to use.
*/}}
{{- define "common.names.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "k8s-at-home.fullname" .) .Values.serviceAccount.name }}
{{- default (include "common.names.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}

View File

@ -1,5 +1,7 @@
{{/*
Merge the local chart values and the common chart defaults.
*/}}
{{- define "common.values.setup" -}}
{{- /* Merge the local chart values and the common chart defaults */ -}}
{{- if .Values.common -}}
{{- $defaultValues := deepCopy .Values.common -}}
{{- $userValues := deepCopy (omit .Values "common") -}}

View File

@ -1,8 +1,8 @@
{{- /*
The main containter that will be included in the controller
The main container included in the controller.
*/ -}}
{{- define "common.controller.mainContainer" -}}
- name: {{ template "common.names.fullname" . }}
- name: {{ include "common.names.fullname" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}

View File

@ -1,5 +1,5 @@
{{/*
ports included by the controller
Ports included by the controller.
*/}}
{{- define "common.controller.ports" -}}
{{- $ports := list -}}

View File

@ -1,5 +1,5 @@
{{/*
Default liveness/readiness/startup probes
Liveness/readiness/startup probes based on tcpSocket checks.
*/}}
{{- define "common.controller.probes.tcpSocket" -}}
{{- if .Values.probes.liveness.enabled -}}

View File

@ -1,5 +1,5 @@
{{/*
volumes included by the controller
Volumes included by the controller.
*/}}
{{- define "common.controller.volumes" -}}
{{- range $index, $persistence := .Values.persistence }}

View File

@ -1,21 +1,36 @@
# type: options are statefulset or deployment
# type: options are deployment, daemonset or statefulset
controllerType: deployment
# Set annotations on the deployment/statefulset
# Set annotations on the deployment/statefulset/daemonset
controllerAnnotations: {}
# Set labels on the deployment/statefulset
# Set labels on the deployment/statefulset/daemonset
controllerLabels: {}
replicas: 1
strategy:
## For Deployments, valid values are Recreate and RollingUpdate
## For StatefulSets, valid values are OnDelete and RollingUpdate
## DaemonSets ignore this
type: RollingUpdate
# Set annotations on the pod
podAnnotations: {}
serviceAccount:
# Specifies whether a service account should be created
create: false
# 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: ""
env: {}
# When using hostNetwork make sure you set dnsPolicy to ClusterFirstWithHostNet
hostNetwork: false
dnsPolicy: Default
initContainers: []
additionalContainers: []
@ -44,9 +59,11 @@ service:
# Specify the default port information
port:
port:
name: http
# name defaults to http
name:
protocol: TCP
targetPort: http
# targetPort defaults to http
targetPort:
## Specify the nodePort value for the LoadBalancer and NodePort service types.
## ref: https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport
##
@ -66,10 +83,12 @@ service:
# type: ClusterIP
# # Specify the default port information
# port:
# port: ""
# name: http
# port:
# # name defaults to http
# name:
# protocol: TCP
# targetPort: http
# # targetPort defaults to http
# targetPort:
# # nodePort:
# additionalPorts: []
# annotations: {}
@ -147,6 +166,14 @@ affinity: {}
tolerations: []
hostAliases: []
# Use hostAliases to add custom entries to /etc/hosts - mapping IP addresses to hostnames.
# ref: https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/
# - ip: "192.168.1.100"
# hostnames:
# - "example.com"
# - "www.example.com"
addons:
vpn:
enabled: false