From 34bc6849dcbcaa06f6e60a302a9db9baa935e04d Mon Sep 17 00:00:00 2001 From: ChrisMcKenzie Date: Fri, 27 Sep 2024 19:29:32 -0500 Subject: [PATCH] fix: some more missing template --- charts/big-peer/Chart.yaml | 2 +- .../big-peer/templates/classes/_ingress.tpl | 10 +--- .../templates/lib/chart/_annotations.tpl | 27 +++++++++ .../templates/lib/chart/_capabilities.tpl | 19 ++++++ .../big-peer/templates/lib/chart/_labels.tpl | 22 +++++++ .../big-peer/templates/lib/chart/_names.tpl | 58 +++++++++++++++++++ .../big-peer/templates/lib/chart/_values.tpl | 9 +++ 7 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 charts/big-peer/templates/lib/chart/_annotations.tpl create mode 100644 charts/big-peer/templates/lib/chart/_capabilities.tpl create mode 100644 charts/big-peer/templates/lib/chart/_labels.tpl create mode 100644 charts/big-peer/templates/lib/chart/_names.tpl create mode 100644 charts/big-peer/templates/lib/chart/_values.tpl diff --git a/charts/big-peer/Chart.yaml b/charts/big-peer/Chart.yaml index 14f16f7..9345fec 100644 --- a/charts/big-peer/Chart.yaml +++ b/charts/big-peer/Chart.yaml @@ -15,7 +15,7 @@ home: https://docs.ditto.live/ # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.1 +version: 0.1.2 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/big-peer/templates/classes/_ingress.tpl b/charts/big-peer/templates/classes/_ingress.tpl index 3cb3c53..21b927e 100644 --- a/charts/big-peer/templates/classes/_ingress.tpl +++ b/charts/big-peer/templates/classes/_ingress.tpl @@ -17,12 +17,8 @@ within the common library. {{- $ingressName = printf "%v-%v" $ingressName $values.nameOverride -}} {{- end -}} - {{- $primaryService := get .Values.service (include "common.service.primary" .) -}} - {{- $defaultServiceName := $fullName -}} - {{- if and (hasKey $primaryService "nameOverride") $primaryService.nameOverride -}} - {{- $defaultServiceName = printf "%v-%v" $defaultServiceName $primaryService.nameOverride -}} - {{- end -}} - {{- $defaultServicePort := get $primaryService.ports (include "common.classes.service.ports.primary" (dict "values" $primaryService)) -}} + {{- $defaultServiceName := printf "%v-hydra-subscription" $fullName -}} + {{- $defaultServicePort := "8080" -}} {{- $isStable := include "common.capabilities.ingress.isStable" . }} --- apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }} @@ -58,7 +54,7 @@ spec: paths: {{- range .paths }} {{- $service := $defaultServiceName -}} - {{- $port := $defaultServicePort.port -}} + {{- $port := $defaultServicePort -}} {{- if .service -}} {{- $service = default $service .service.name -}} {{- $port = default $port .service.port -}} diff --git a/charts/big-peer/templates/lib/chart/_annotations.tpl b/charts/big-peer/templates/lib/chart/_annotations.tpl new file mode 100644 index 0000000..2c64a36 --- /dev/null +++ b/charts/big-peer/templates/lib/chart/_annotations.tpl @@ -0,0 +1,27 @@ +{{/* Common annotations shared across objects */}} +{{- define "common.annotations" -}} + {{- with .Values.global.annotations }} + {{- range $k, $v := . }} + {{- $name := $k }} + {{- $value := tpl $v $ }} +{{ $name }}: {{ quote $value }} + {{- end }} + {{- end }} +{{- end -}} + +{{/* Determine the Pod annotations used in the controller */}} +{{- define "common.podAnnotations" -}} + {{- if .Values.podAnnotations -}} + {{- tpl (toYaml .Values.podAnnotations) . | nindent 0 -}} + {{- end -}} + + {{- $configMapsFound := false -}} + {{- range $name, $configmap := .Values.configmap -}} + {{- if $configmap.enabled -}} + {{- $configMapsFound = true -}} + {{- end -}} + {{- end -}} + {{- if $configMapsFound -}} + {{- printf "checksum/config: %v" (include ("common.configmap") . | sha256sum) | nindent 0 -}} + {{- end -}} +{{- end -}} diff --git a/charts/big-peer/templates/lib/chart/_capabilities.tpl b/charts/big-peer/templates/lib/chart/_capabilities.tpl new file mode 100644 index 0000000..96de3c1 --- /dev/null +++ b/charts/big-peer/templates/lib/chart/_capabilities.tpl @@ -0,0 +1,19 @@ +{{/* Allow KubeVersion to be overridden. */}} +{{- define "common.capabilities.ingress.kubeVersion" -}} + {{- default .Capabilities.KubeVersion.Version .Values.kubeVersionOverride -}} +{{- end -}} + +{{/* Return the appropriate apiVersion for Ingress objects */}} +{{- define "common.capabilities.ingress.apiVersion" -}} + {{- print "networking.k8s.io/v1" -}} + {{- if semverCompare "<1.19" (include "common.capabilities.ingress.kubeVersion" .) -}} + {{- print "beta1" -}} + {{- end -}} +{{- end -}} + +{{/* Check Ingress stability */}} +{{- define "common.capabilities.ingress.isStable" -}} + {{- if eq (include "common.capabilities.ingress.apiVersion" .) "networking.k8s.io/v1" -}} + {{- true -}} + {{- end -}} +{{- end -}} diff --git a/charts/big-peer/templates/lib/chart/_labels.tpl b/charts/big-peer/templates/lib/chart/_labels.tpl new file mode 100644 index 0000000..73b5068 --- /dev/null +++ b/charts/big-peer/templates/lib/chart/_labels.tpl @@ -0,0 +1,22 @@ +{{/* Common labels shared across objects */}} +{{- define "common.labels" -}} +helm.sh/chart: {{ include "common.names.chart" . }} +{{ include "common.labels.selectorLabels" . }} + {{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} + {{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} + {{- with .Values.global.labels }} + {{- range $k, $v := . }} + {{- $name := $k }} + {{- $value := tpl $v $ }} +{{ $name }}: {{ quote $value }} + {{- end }} + {{- end }} +{{- end -}} + +{{/* Selector labels shared across objects */}} +{{- define "common.labels.selectorLabels" -}} +app.kubernetes.io/name: {{ include "common.names.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} diff --git a/charts/big-peer/templates/lib/chart/_names.tpl b/charts/big-peer/templates/lib/chart/_names.tpl new file mode 100644 index 0000000..a32d572 --- /dev/null +++ b/charts/big-peer/templates/lib/chart/_names.tpl @@ -0,0 +1,58 @@ +{{/* Expand the name of the chart */}} +{{- define "common.names.name" -}} + {{- $globalNameOverride := "" -}} + {{- if hasKey .Values "global" -}} + {{- $globalNameOverride = (default $globalNameOverride .Values.global.nameOverride) -}} + {{- end -}} + {{- default .Chart.Name (default .Values.nameOverride $globalNameOverride) | 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 "common.names.fullname" -}} + {{- $name := include "common.names.name" . -}} + {{- $globalFullNameOverride := "" -}} + {{- if hasKey .Values "global" -}} + {{- $globalFullNameOverride = (default $globalFullNameOverride .Values.global.fullnameOverride) -}} + {{- end -}} + {{- if or .Values.fullnameOverride $globalFullNameOverride -}} + {{- $name = default .Values.fullnameOverride $globalFullNameOverride -}} + {{- else -}} + {{- if contains $name .Release.Name -}} + {{- $name = .Release.Name -}} + {{- else -}} + {{- $name = printf "%s-%s" .Release.Name $name -}} + {{- end -}} + {{- end -}} + {{- trunc 63 $name | trimSuffix "-" -}} +{{- end -}} + +{{/* Create chart name and version as used by the chart label */}} +{{- define "common.names.chart" -}} + {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* Create the name of the ServiceAccount to use */}} +{{- define "common.names.serviceAccountName" -}} + {{- if .Values.serviceAccount.create -}} + {{- default (include "common.names.fullname" .) .Values.serviceAccount.name -}} + {{- else -}} + {{- default "default" .Values.serviceAccount.name -}} + {{- end -}} +{{- end -}} + +{{/* Return the properly cased version of the controller type */}} +{{- define "common.names.controllerType" -}} + {{- if eq .Values.controller.type "deployment" -}} + {{- print "Deployment" -}} + {{- else if eq .Values.controller.type "daemonset" -}} + {{- print "DaemonSet" -}} + {{- else if eq .Values.controller.type "statefulset" -}} + {{- print "StatefulSet" -}} + {{- else -}} + {{- fail (printf "Not a valid controller.type (%s)" .Values.controller.type) -}} + {{- end -}} +{{- end -}} diff --git a/charts/big-peer/templates/lib/chart/_values.tpl b/charts/big-peer/templates/lib/chart/_values.tpl new file mode 100644 index 0000000..d3c8413 --- /dev/null +++ b/charts/big-peer/templates/lib/chart/_values.tpl @@ -0,0 +1,9 @@ +{{/* Merge the local chart values and the common chart defaults */}} +{{- define "common.values.setup" -}} + {{- if .Values.common -}} + {{- $defaultValues := deepCopy .Values.common -}} + {{- $userValues := deepCopy (omit .Values "common") -}} + {{- $mergedValues := mustMergeOverwrite $defaultValues $userValues -}} + {{- $_ := set . "Values" (deepCopy $mergedValues) -}} + {{- end -}} +{{- end -}}