Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update librepod chart library #16

Merged
merged 2 commits into from
Aug 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion charts/librepod/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v2
name: librepod
description: A Helm library chart for LibrePod specific Kubernetes clusters
type: library
version: 0.1.0
version: 1.0.0
33 changes: 33 additions & 0 deletions charts/librepod/templates/_all.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{{/*
Main entrypoint for the librepod library chart. It will render all underlying templates based on the provided values.
*/}}
{{- define "librepod.all" -}}
{{- /* Merge the local chart values and the librepod chart defaults */ -}}
{{- include "librepod.values.setup" . }}

{{ include "librepod.configmap" . | nindent 0 }}

{{- /* Build the templates */ -}}
{{- include "librepod.pvc" . }}

{{- if .Values.serviceAccount.create -}}
{{- include "librepod.serviceAccount" . }}
{{- end -}}

{{- if .Values.controller.enabled }}
{{- if eq .Values.controller.type "deployment" }}
{{- include "librepod.deployment" . | nindent 0 }}
{{ else if eq .Values.controller.type "daemonset" }}
{{- include "librepod.daemonset" . | nindent 0 }}
{{ else if eq .Values.controller.type "statefulset" }}
{{- include "librepod.statefulset" . | nindent 0 }}
{{ else }}
{{- fail (printf "Not a valid controller.type (%s)" .Values.controller.type) }}
{{- end -}}
{{- end -}}

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

{{ include "librepod.ingressroute" . | nindent 0 }}

{{- end -}}
30 changes: 18 additions & 12 deletions charts/librepod/templates/_configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
{{- define "librepod.configmap.tpl" -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "librepod.names.fullname" . }}
labels:
{{- include "librepod.names.labels" . | nindent 4 }}
data: {}
{{- end -}}

{{/*
Renders the configMap objects required by the chart.
*/}}
{{- define "librepod.configmap" -}}
{{- include "librepod.util.merge" (append . "librepod.configmap.tpl") -}}
{{- end -}}
{{- /* Generate named configMaps as required */ -}}
{{- range $name, $configmap := .Values.configmap }}
{{- if $configmap.enabled -}}
{{- $configmapValues := $configmap -}}

{{/* set the default nameOverride to the configMap name */}}
{{- if not $configmapValues.nameOverride -}}
{{- $_ := set $configmapValues "nameOverride" $name -}}
{{ end -}}

{{- $_ := set $ "ObjectValues" (dict "configmap" $configmapValues) -}}
{{- include "librepod.classes.configmap" $ }}
{{- end }}
{{- end }}
{{- end }}
73 changes: 39 additions & 34 deletions charts/librepod/templates/_deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,51 +1,56 @@
{{- define "librepod.deployment" -}}
{{/*
This template serves as the blueprint for the Deployment objects that are created
within the librepod library.
*/}}
{{- define "librepod.deployment" }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "librepod.names.fullname" . }}
labels:
{{- include "librepod.names.labels" . | nindent 4 }}
{{- include "librepod.labels" . | nindent 4 }}
{{- with .Values.controller.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.controller.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
revisionHistoryLimit: {{ .Values.controller.revisionHistoryLimit }}
replicas: {{ .Values.controller.replicas }}
{{- $strategy := default "Recreate" .Values.controller.strategy }}
{{- if and (ne $strategy "Recreate") (ne $strategy "RollingUpdate") }}
{{- fail (printf "Not a valid strategy type for Deployment (%s)" $strategy) }}
{{- end }}
strategy:
type: {{ $strategy }}
{{- with .Values.controller.rollingUpdate }}
{{- if and (eq $strategy "RollingUpdate") (or .surge .unavailable) }}
rollingUpdate:
{{- with .unavailable }}
maxUnavailable: {{ . }}
{{- end }}
{{- with .surge }}
maxSurge: {{ . }}
{{- end }}
{{- end }}
{{- end }}
selector:
matchLabels:
{{- include "librepod.names.selectorLabels" . | nindent 6 }}
{{- include "librepod.labels.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "librepod.names.selectorLabels" . | nindent 8 }}
{{- include "librepod.labels.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "librepod.names.serviceAccountName" . }}
volumes:
- name: config-volume
configMap:
name: {{ template "librepod.names.fullname" . }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
volumeMounts:
- name: config-volume
mountPath: "/config/config.yaml"
subPath: "config.yaml"
ports:
- name: http
containerPort: {{ .Values.service.targetPort }}
protocol: TCP
# livenessProbe:
# httpGet:
# path: /
# port: http
# readinessProbe:
# httpGet:
# path: /
# port: http
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- end -}}
{{- include "librepod.controller.pod" . | nindent 6 }}
{{- end }}
51 changes: 49 additions & 2 deletions charts/librepod/templates/_ingressroute.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{{/* Renders the Ingress objects required by the chart */}}
{{/*
{{- define "librepod.ingressroute" -}}
{{- $fullName := include "librepod.names.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- $svcPort := .Values.service.main.port -}}
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: {{ $fullName }}
labels:
{{- include "librepod.names.labels" . | nindent 4 }}
{{- include "librepod.labels" . | nindent 4 }}
spec:
entryPoints:
- web
Expand All @@ -19,3 +20,49 @@ spec:
- name: {{ $fullName }}
port: {{ $svcPort }}
{{- end -}}
*/}}

{{/*
This template serves as a blueprint for all Ingress objects that are created
within the librepod library.
*/}}

{{/* Renders the IngressRoute objects required by the chart */}}
{{- define "librepod.ingressroute" -}}
{{- /* Generate named ingresses as required */ -}}
{{- range $name, $ingress := .Values.ingress }}
{{- if $ingress.enabled -}}
{{- $ingressValues := $ingress -}}

{{/* set defaults */}}
{{- if and (not $ingressValues.nameOverride) (ne $name (include "librepod.ingress.primary" $)) -}}
{{- $_ := set $ingressValues "nameOverride" $name -}}
{{- end -}}

{{- $_ := set $ "ObjectValues" (dict "ingress" $ingressValues) -}}
{{- include "librepod.classes.ingress" $ }}
{{- end }}
{{- end }}
{{- end }}

{{/* Return the name of the primary ingress object */}}
{{- define "librepod.ingress.primary" -}}
{{- $enabledIngresses := dict -}}
{{- range $name, $ingress := .Values.ingress -}}
{{- if $ingress.enabled -}}
{{- $_ := set $enabledIngresses $name . -}}
{{- end -}}
{{- end -}}

{{- $result := "" -}}
{{- range $name, $ingress := $enabledIngresses -}}
{{- if and (hasKey $ingress "primary") $ingress.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}

{{- if not $result -}}
{{- $result = keys $enabledIngresses | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}
16 changes: 16 additions & 0 deletions charts/librepod/templates/_pvc.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{/*
Renders the Persistent Volume Claim objects required by the chart.
*/}}
{{- define "librepod.pvc" -}}
{{- /* Generate pvc as required */ -}}
{{- range $index, $PVC := .Values.persistence }}
{{- if and $PVC.enabled (eq (default "pvc" $PVC.type) "pvc") (not $PVC.existingClaim) -}}
{{- $persistenceValues := $PVC -}}
{{- if not $persistenceValues.nameOverride -}}
{{- $_ := set $persistenceValues "nameOverride" $index -}}
{{- end -}}
{{- $_ := set $ "ObjectValues" (dict "persistence" $persistenceValues) -}}
{{- include "librepod.classes.pvc" $ | nindent 0 -}}
{{- end }}
{{- end }}
{{- end }}
56 changes: 41 additions & 15 deletions charts/librepod/templates/_service.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,43 @@
{{/*
Renders the Service objects required by the chart.
*/}}
{{- define "librepod.service" -}}
apiVersion: v1
kind: Service
metadata:
name: {{ include "librepod.names.fullname" . }}
labels:
{{- include "librepod.names.labels" . | nindent 4 }}
spec:
type: {{ default "ClusterIP" .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ default .Values.service.port .Values.service.targetPort }}
protocol: TCP
name: http
selector:
{{- include "librepod.names.selectorLabels" . | nindent 4 }}
{{- /* Generate named services as required */ -}}
{{- range $name, $service := .Values.service }}
{{- if $service.enabled -}}
{{- $serviceValues := $service -}}

{{/* set the default nameOverride to the service name */}}
{{- if and (not $serviceValues.nameOverride) (ne $name (include "librepod.service.primary" $)) -}}
{{- $_ := set $serviceValues "nameOverride" $name -}}
{{ end -}}

{{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}}
{{- include "librepod.classes.service" $ }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Return the primary service object
*/}}
{{- define "librepod.service.primary" -}}
{{- $enabledServices := dict -}}
{{- range $name, $service := .Values.service -}}
{{- if $service.enabled -}}
{{- $_ := set $enabledServices $name . -}}
{{- end -}}
{{- end -}}

{{- $result := "" -}}
{{- range $name, $service := $enabledServices -}}
{{- if and (hasKey $service "primary") $service.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}

{{- if not $result -}}
{{- $result = keys $enabledServices | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}
16 changes: 9 additions & 7 deletions charts/librepod/templates/_serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{{- define "librepod.serviceAccount" -}}
{{/*
The ServiceAccount object to be created.
*/}}
{{- define "librepod.serviceAccount" }}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "librepod.names.serviceAccountName" . }}
labels:
{{- include "librepod.names.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
labels: {{- include "librepod.labels" $ | nindent 4 }}
{{- with (merge (.Values.serviceAccount.annotations | default dict) (include "librepod.annotations" $ | fromYaml)) }}
annotations: {{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}}
{{- end }}
Loading