feat(common): Release version 1.1.0 (#81)

# Removed
- Promtail add-on has been removed

# Fixed
- Fixed httpGet probe whitespace rendering (#76)
- Fixed Secret management for ServiceAccounts (fixes #78)
- Fixed code-server add-on Service rendering

# Added
- Added support for Gateway API Routes (#59)

# Changed
- Services and their ports are now assumed enabled by default
- Updated `code-server` image to v4.8.3
- Updated `netshoot` image to v0.8

Signed-off-by: András Maróy <andras@maroy.hu>
Signed-off-by: András Maróy <andras@maroy.hu>
Co-authored-by: András Maróy <andras@maroy.hu>
Co-authored-by: pando85 <pando855@gmail.com>
This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2022-11-19 13:24:11 +01:00 committed by GitHub
parent 841d562827
commit a2a0b8ea2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
46 changed files with 1393 additions and 320 deletions

View file

@ -14,7 +14,7 @@ It will include / inject the required templates based on the given values.
{{- if or .Values.addons.codeserver.git.deployKey .Values.addons.codeserver.git.deployKeyBase64 -}}
{{- $deployKeySecret := include "bjw-s.common.addon.codeserver.deployKeySecret" . -}}
{{- if $deployKeySecret -}}
{{- $_ := set .Values.secrets "addon-codeserver-deploykey" (dict "enabled" "true" "stringData" ($deployKeySecret | fromYaml)) -}}
{{- $_ := set .Values.secrets "addon-codeserver-deploykey" (dict "enabled" true "stringData" ($deployKeySecret | fromYaml)) -}}
{{- end -}}
{{- end -}}
@ -22,12 +22,18 @@ It will include / inject the required templates based on the given values.
{{- if or .Values.addons.codeserver.git.deployKey .Values.addons.codeserver.git.deployKeyBase64 .Values.addons.codeserver.git.deployKeySecret }}
{{- $volume := include "bjw-s.common.addon.codeserver.deployKeyVolumeSpec" . | fromYaml -}}
{{- if $volume -}}
{{- $_ := set .Values.persistence "deploykey" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $volume) -}}
{{- $_ := set .Values.persistence "deploykey" (dict "enabled" true "mountPath" "-" "type" "custom" "volumeSpec" $volume) -}}
{{- end -}}
{{- end -}}
{{/* Add the code-server service */}}
{{- $_ := set .Values.service "addon-codeserver" .Values.addons.codeserver.service -}}
{{- if .Values.addons.codeserver.service.enabled -}}
{{- $serviceValues := .Values.addons.codeserver.service -}}
{{- $_ := set $serviceValues "nameOverride" "addon-codeserver" -}}
{{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}}
{{- include "bjw-s.common.class.service" $ -}}
{{- $_ := unset $.ObjectValues "service" -}}
{{- end -}}
{{/* Add the code-server ingress */}}
{{- $svcName := printf "%v-addon-codeserver" (include "bjw-s.common.lib.chart.names.fullname" .) -}}

View file

@ -1,25 +0,0 @@
{{/*
Template to render promtail addon
It will include / inject the required templates based on the given values.
*/}}
{{- define "bjw-s.common.addon.promtail" -}}
{{- if .Values.addons.promtail.enabled -}}
{{/* Append the promtail container to the additionalContainers */}}
{{- $container := include "bjw-s.common.addon.promtail.container" . | fromYaml -}}
{{- if $container -}}
{{- $_ := set .Values.additionalContainers "addon-promtail" $container -}}
{{- end -}}
{{/* Append the promtail configMap to the configmaps dict */}}
{{- $configmap := include "bjw-s.common.addon.promtail.configmap" . -}}
{{- if $configmap -}}
{{- $_ := set .Values.configMaps "addon-promtail" (dict "enabled" "true" "data" ($configmap | fromYaml)) -}}
{{- end -}}
{{/* Append the promtail config volume to the volumes */}}
{{- $volume := include "bjw-s.common.addon.promtail.volumeSpec" . | fromYaml -}}
{{- if $volume -}}
{{- $_ := set .Values.persistence "addon-promtail" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $volume) -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -1,25 +0,0 @@
{{/*
The promtail config to be included.
*/}}
{{- define "bjw-s.common.addon.promtail.configmap" -}}
promtail.yaml: |
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
{{- with .Values.addons.promtail.loki }}
client:
url: {{ . }}
{{- end }}
scrape_configs:
{{- range .Values.addons.promtail.logs }}
- job_name: {{ .name }}
static_configs:
- targets:
- localhost
labels:
job: {{ .name }}
__path__: "{{ .path }}"
{{- end }}
{{- end -}}

View file

@ -1,39 +0,0 @@
{{/*
The promtail sidecar container to be inserted.
*/}}
{{- define "bjw-s.common.addon.promtail.container" -}}
{{- if lt (len .Values.addons.promtail.volumeMounts) 1 }}
{{- fail "At least 1 volumeMount is required for the promtail container" }}
{{- end -}}
name: promtail
image: "{{ .Values.addons.promtail.image.repository }}:{{ .Values.addons.promtail.image.tag }}"
imagePullPolicy: {{ .Values.addons.promtail.pullPolicy }}
{{- with .Values.addons.promtail.securityContext }}
securityContext:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.addons.promtail.env }}
env:
{{- range $k, $v := . }}
- name: {{ $k }}
value: {{ $v | quote }}
{{- end }}
{{- end }}
args:
{{- range .Values.addons.promtail.args }}
- {{ . | quote }}
{{- end }}
- "-config.file=/etc/promtail/promtail.yaml"
volumeMounts:
- name: addon-promtail
mountPath: /etc/promtail/promtail.yaml
subPath: promtail.yaml
readOnly: true
{{- with .Values.addons.promtail.volumeMounts }}
{{- toYaml . | nindent 2 }}
{{- end }}
{{- with .Values.addons.promtail.resources }}
resources:
{{- toYaml . | nindent 2 }}
{{- end }}
{{- end -}}

View file

@ -1,7 +0,0 @@
{{/*
The volume (referencing config) to be inserted into additionalVolumes.
*/}}
{{- define "bjw-s.common.addon.promtail.volumeSpec" -}}
configMap:
name: {{ include "bjw-s.common.lib.chart.names.fullname" . }}-addon-promtail
{{- end -}}

View file

@ -12,7 +12,7 @@ It will include / inject the required templates based on the given values.
{{- if or .Values.addons.vpn.scripts.up .Values.addons.vpn.scripts.down }}
{{- $configmap := include "bjw-s.common.addon.vpn.configmap" . -}}
{{- if $configmap -}}
{{- $_ := set .Values.configMaps "addon-vpn" (dict "enabled" "true" "data" ($configmap | fromYaml)) -}}
{{- $_ := set .Values.configMaps "addon-vpn" (dict "enabled" true "data" ($configmap | fromYaml)) -}}
{{- end -}}
{{- end -}}
@ -20,20 +20,20 @@ It will include / inject the required templates based on the given values.
{{- if and .Values.addons.vpn.configFile (not .Values.addons.vpn.configFileSecret) }}
{{- $secret := include "bjw-s.common.addon.vpn.secret" . -}}
{{- if $secret -}}
{{- $_ := set .Values.secrets "addon-vpn-config" (dict "enabled" "true" "stringData" ($secret | fromYaml)) -}}
{{- $_ := set .Values.secrets "addon-vpn-config" (dict "enabled" true "stringData" ($secret | fromYaml)) -}}
{{- end -}}
{{- end -}}
{{/* Append the vpn scripts volume to the volumes */}}
{{- $scriptVolume := include "bjw-s.common.addon.vpn.scriptsVolumeSpec" . | fromYaml -}}
{{- if $scriptVolume -}}
{{- $_ := set .Values.persistence "vpnscript" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $scriptVolume) -}}
{{- $_ := set .Values.persistence "vpnscript" (dict "enabled" true "mountPath" "-" "type" "custom" "volumeSpec" $scriptVolume) -}}
{{- end -}}
{{/* Append the vpn config volume to the volumes */}}
{{- $configVolume := include "bjw-s.common.addon.vpn.configVolumeSpec" . | fromYaml }}
{{ if $configVolume -}}
{{- $_ := set .Values.persistence "vpnconfig" (dict "enabled" "true" "mountPath" "-" "type" "custom" "volumeSpec" $configVolume) -}}
{{- $_ := set .Values.persistence "vpnconfig" (dict "enabled" true "mountPath" "-" "type" "custom" "volumeSpec" $configVolume) -}}
{{- end -}}
{{/* Include the networkpolicy if not empty */}}

View file

@ -0,0 +1,71 @@
{{/*
This template serves as a blueprint for all Route objects that are created
within the common library.
*/}}
{{- define "bjw-s.common.class.route" -}}
{{- $values := .Values.route -}}
{{- if hasKey . "ObjectValues" -}}
{{- with .ObjectValues.route -}}
{{- $values = . -}}
{{- end -}}
{{ end -}}
{{- $fullName := include "bjw-s.common.lib.chart.names.fullname" . -}}
{{- if and (hasKey $values "nameOverride") $values.nameOverride -}}
{{- $fullName = printf "%v-%v" $fullName $values.nameOverride -}}
{{ end -}}
{{- $routeKind := $values.kind | default "HTTPRoute" -}}
{{- $primaryService := get .Values.service (include "bjw-s.common.lib.service.primary" .) -}}
{{- $defaultServiceName := $fullName -}}
{{- if and (hasKey $primaryService "nameOverride") $primaryService.nameOverride -}}
{{- $defaultServiceName = printf "%v-%v" $defaultServiceName $primaryService.nameOverride -}}
{{- end -}}
{{- $defaultServicePort := get $primaryService.ports (include "bjw-s.common.lib.service.primaryPort" (dict "values" $primaryService)) -}}
---
apiVersion: gateway.networking.k8s.io/v1alpha2
{{- if and (ne $routeKind "GRPCRoute") (ne $routeKind "HTTPRoute") (ne $routeKind "TCPRoute") (ne $routeKind "TLSRoute") (ne $routeKind "UDPRoute") }}
{{- fail (printf "Not a valid route kind (%s)" $routeKind) }}
{{- end }}
kind: {{ $routeKind }}
metadata:
name: {{ $fullName }}
{{- with (merge ($values.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)) }}
labels: {{- toYaml . | nindent 4 }}
{{- end }}
{{- with (merge ($values.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
spec:
parentRefs:
{{- range $values.parentRefs }}
- group: {{ default "gateway.networking.k8s.io" .group }}
kind: {{ default "Gateway" .kind }}
name: {{ required (printf "parentRef name is required for %v %v" $routeKind $fullName) .name }}
namespace: {{ required (printf "parentRef namespace is required for %v %v" $routeKind $fullName) .namespace }}
sectionName: {{ default "" .sectionName | quote}}
{{- end }}
{{- if and (ne $routeKind "TCPRoute") (ne $routeKind "UDPRoute") $values.hostnames }}
hostnames:
{{- with $values.hostnames }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
rules:
{{- range $values.rules }}
- backendRefs:
{{- range .backendRefs }}
- group: {{ default "" .group | quote}}
kind: {{ default "Service" .kind }}
name: {{ default $defaultServiceName .name }}
namespace: {{ default $.Release.Namespace .namespace }}
port: {{ default $defaultServicePort.port .port }}
weight: {{ default 1 .weight }}
{{- end }}
{{- if (eq $routeKind "HTTPRoute") }}
{{- with .matches }}
matches:
{{- toYaml . | nindent 6 }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}

View file

@ -19,6 +19,9 @@ within the common library.
---
apiVersion: v1
kind: Secret
{{- with $values.type }}
type: {{ . }}
{{- end }}
metadata:
name: {{ $secretName }}
{{- with (merge ($values.labels | default dict) (include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml)) }}
@ -27,8 +30,8 @@ metadata:
{{- with (merge ($values.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
stringData:
{{- with $values.stringData }}
stringData:
{{- tpl (toYaml .) $ | nindent 2 }}
{{- end }}
{{- end -}}

View file

@ -15,6 +15,7 @@ within the common library.
{{- $serviceName = printf "%v-%v" $serviceName $values.nameOverride -}}
{{ end -}}
{{- $svcType := $values.type | default "" -}}
{{- $enabledPorts := include "bjw-s.common.lib.service.enabledPorts" (dict "serviceName" $serviceName "values" $values) | fromYaml }}
{{- $primaryPort := get $values.ports (include "bjw-s.common.lib.service.primaryPort" (dict "values" $values)) }}
---
apiVersion: v1
@ -76,25 +77,23 @@ spec:
{{ toYaml . | nindent 4 }}
{{- end }}
ports:
{{- range $name, $port := $values.ports }}
{{- if $port.enabled }}
- port: {{ $port.port }}
targetPort: {{ $port.targetPort | default $name }}
{{- if $port.protocol }}
{{- if or ( eq $port.protocol "HTTP" ) ( eq $port.protocol "HTTPS" ) ( eq $port.protocol "TCP" ) }}
protocol: TCP
{{- else }}
protocol: {{ $port.protocol }}
{{- end }}
{{- else }}
protocol: TCP
{{- end }}
name: {{ $name }}
{{- if (and (eq $svcType "NodePort") (not (empty $port.nodePort))) }}
nodePort: {{ $port.nodePort }}
{{ end }}
{{- end }}
{{- end }}
{{- range $name, $port := $enabledPorts }}
- port: {{ $port.port }}
targetPort: {{ $port.targetPort | default $name }}
{{- if $port.protocol }}
{{- if or ( eq $port.protocol "HTTP" ) ( eq $port.protocol "HTTPS" ) ( eq $port.protocol "TCP" ) }}
protocol: TCP
{{- else }}
protocol: {{ $port.protocol }}
{{- end }}
{{- else }}
protocol: TCP
{{- end }}
name: {{ $name }}
{{- if (and (eq $svcType "NodePort") (not (empty $port.nodePort))) }}
nodePort: {{ $port.nodePort }}
{{ end }}
{{- end -}}
{{- with (merge ($values.extraSelectorLabels | default dict) (include "bjw-s.common.lib.metadata.selectorLabels" . | fromYaml)) }}
selector: {{- toYaml . | nindent 4 }}
{{- end }}

View file

@ -8,8 +8,12 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "bjw-s.common.lib.chart.names.serviceAccountName" . }}
labels: {{- include "bjw-s.common.lib.metadata.allLabels" $ | nindent 4 }}
{{- with include "bjw-s.common.lib.metadata.allLabels" $ | fromYaml }}
labels: {{- toYaml . | nindent 4 }}
{{- end }}
{{- with (merge (.Values.serviceAccount.annotations | default dict) (include "bjw-s.common.lib.metadata.globalAnnotations" $ | fromYaml)) }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
secrets:
- name: {{ include "bjw-s.common.lib.chart.names.fullname" . }}-sa-token
{{- end -}}

View file

@ -3,19 +3,18 @@ Ports included by the controller.
*/}}
{{- define "bjw-s.common.lib.container.ports" -}}
{{- $ports := list -}}
{{- range .Values.service -}}
{{- if .enabled -}}
{{- range $name, $port := .ports -}}
{{- $_ := set $port "name" $name -}}
{{- $ports = mustAppend $ports $port -}}
{{- end }}
{{- range $servicename, $service := .Values.service -}}
{{- $enabledPorts := include "bjw-s.common.lib.service.enabledPorts" (dict "serviceName" $servicename "values" $service) | fromYaml }}
{{- range $portname, $port := ($enabledPorts | default dict) -}}
{{- $_ := set $port "name" $portname -}}
{{- $ports = mustAppend $ports $port -}}
{{- end }}
{{- end }}
{{/* export/render the list of ports */}}
{{- if $ports -}}
{{- range $_ := $ports }}
{{- if .enabled }}
{{- if default true .enabled | }}
- name: {{ .name }}
{{- if and .targetPort (kindIs "string" .targetPort) }}
{{- fail (printf "Our charts do not support named ports for targetPort. (port name %s, targetPort %s)" .name .targetPort) }}

View file

@ -22,7 +22,7 @@ Probes selection logic.
{{- else -}}
{{- $probeType = $probe.type | default "TCP" -}}
{{- end }}
{{- if or ( eq $probeType "HTTPS" ) ( eq $probeType "HTTP" ) -}}
{{- if or ( eq $probeType "HTTPS" ) ( eq $probeType "HTTP" ) }}
httpGet:
path: {{ $probe.path }}
scheme: {{ $probeType }}

View file

@ -0,0 +1,23 @@
{{/*
Return the enabled ports for a given Service object.
*/}}
{{- define "bjw-s.common.lib.service.enabledPorts" -}}
{{- $enabledPorts := dict -}}
{{- range $name, $port := .values.ports -}}
{{- if kindIs "map" $port -}}
{{- $portEnabled := true -}}
{{- if hasKey $port "enabled" -}}
{{- $portEnabled = $port.enabled -}}
{{- end -}}
{{- if $portEnabled -}}
{{- $_ := set $enabledPorts $name . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if eq 0 (len $enabledPorts) }}
{{- fail (printf "No ports are enabled for service \"%s\"!" (.serviceName | default "")) }}
{{- end }}
{{- $enabledPorts | toYaml -}}
{{- end -}}

View file

@ -0,0 +1,18 @@
{{/*
Return the enabled services.
*/}}
{{- define "bjw-s.common.lib.service.enabledServices" -}}
{{- $enabledServices := dict -}}
{{- range $name, $service := .Values.service -}}
{{- if kindIs "map" $service -}}
{{- $serviceEnabled := true -}}
{{- if hasKey $service "enabled" -}}
{{- $serviceEnabled = $service.enabled -}}
{{- end -}}
{{- if $serviceEnabled -}}
{{- $_ := set $enabledServices $name . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $enabledServices | toYaml -}}
{{- end -}}

View file

@ -2,12 +2,7 @@
Return the primary service object
*/}}
{{- define "bjw-s.common.lib.service.primary" -}}
{{- $enabledServices := dict -}}
{{- range $name, $service := .Values.service -}}
{{- if $service.enabled -}}
{{- $_ := set $enabledServices $name . -}}
{{- end -}}
{{- end -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" $ | fromYaml ) }}
{{- $result := "" -}}
{{- range $name, $service := $enabledServices -}}

View file

@ -2,16 +2,7 @@
Return the primary port for a given Service object.
*/}}
{{- define "bjw-s.common.lib.service.primaryPort" -}}
{{- $enabledPorts := dict -}}
{{- range $name, $port := .values.ports -}}
{{- if $port.enabled -}}
{{- $_ := set $enabledPorts $name . -}}
{{- end -}}
{{- end -}}
{{- if eq 0 (len $enabledPorts) }}
{{- fail (printf "No ports are enabled for service \"%s\"!" .serviceName) }}
{{- end }}
{{- $enabledPorts := (include "bjw-s.common.lib.service.enabledPorts" . | fromYaml) }}
{{- $result := "" -}}
{{- range $name, $port := $enabledPorts -}}

View file

@ -12,23 +12,19 @@ Secondary entrypoint and primary loader for the common chart
{{- include "bjw-s.common.addon.vpn" . | nindent 0 -}}
{{- end -}}
{{- /* Enable promtail add-on if required */ -}}
{{- if .Values.addons.promtail.enabled -}}
{{- include "bjw-s.common.addon.promtail" . | nindent 0 -}}
{{- end -}}
{{- /* Enable netshoot add-on if required */ -}}
{{- if .Values.addons.netshoot.enabled -}}
{{- include "bjw-s.common.addon.netshoot" . | nindent 0 -}}
{{- end -}}
{{- /* Build the templates */ -}}
{{- include "bjw-s.common.render.configmaps" . | nindent 0 -}}
{{- include "bjw-s.common.render.secrets" . | nindent 0 -}}
{{- include "bjw-s.common.render.pvcs" . | nindent 0 -}}
{{- include "bjw-s.common.render.serviceAccount" . | nindent 0 -}}
{{- include "bjw-s.common.render.controller" . | nindent 0 -}}
{{- include "bjw-s.common.render.services" . | nindent 0 -}}
{{- include "bjw-s.common.render.ingresses" . | nindent 0 -}}
{{- include "bjw-s.common.render.serviceMonitors" . | nindent 0 -}}
{{- include "bjw-s.common.render.routes" . | nindent 0 -}}
{{- include "bjw-s.common.render.configmaps" . | nindent 0 -}}
{{- include "bjw-s.common.render.secrets" . | nindent 0 -}}
{{- end -}}

View file

@ -0,0 +1,18 @@
{{/* Renders the Route objects required by the chart */}}
{{- define "bjw-s.common.render.routes" -}}
{{- /* Generate named routes as required */ -}}
{{- range $name, $route := .Values.route }}
{{- if $route.enabled -}}
{{- $routeValues := $route -}}
{{/* set defaults */}}
{{- if not $routeValues.nameOverride -}}
{{- $_ := set $routeValues "nameOverride" $name -}}
{{- end -}}
{{- $_ := set $ "ObjectValues" (dict "route" $routeValues) -}}
{{- include "bjw-s.common.class.route" $ | nindent 0 -}}
{{- $_ := unset $.ObjectValues "route" -}}
{{- end }}
{{- end }}
{{- end }}

View file

@ -3,6 +3,21 @@ Renders the serviceAccount object required by the chart.
*/}}
{{- define "bjw-s.common.render.serviceAccount" -}}
{{- if .Values.serviceAccount.create -}}
{{- /* Create a service account secret */ -}}
{{- $_ := set .Values.secrets "sa-token" (dict "enabled" true "type" "kubernetes.io/service-account-token") -}}
{{- include "bjw-s.common.class.serviceAccount" $ | nindent 0 -}}
{{- end -}}
{{- end -}}
# 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: ""

View file

@ -4,7 +4,7 @@ Renders the Service objects required by the chart.
{{- define "bjw-s.common.render.services" -}}
{{- /* Generate named services as required */ -}}
{{- range $name, $service := .Values.service -}}
{{- if $service.enabled -}}
{{- if ($service.enabled | default true ) -}}
{{- $serviceValues := $service -}}
{{/* set the default nameOverride to the service name */}}