From 52ed0d9374ae030d20e4d0980e722b1b039fe180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Skyler=20M=C3=A4ntysaari?= Date: Wed, 15 Feb 2023 03:25:36 +0200 Subject: [PATCH] Progress --- charts/apps/piped/Chart.yaml | 13 + .../{ => apps}/piped/README_CONFIG.md.gotmpl | 2 +- .../piped/templates/backend/deployment.yaml | 49 ++++ .../templates/backend/lib/_container.tpl | 54 +++++ .../piped/templates/backend/lib/_env_vars.tpl | 43 ++++ .../piped/templates/backend/lib/_names.tpl | 111 +++++++++ .../apps/piped/templates/backend/lib/_pod.tpl | 105 ++++++++ .../piped/templates/backend/lib/_ports.tpl | 36 +++ .../piped/templates/backend/lib/_probes.tpl | 33 +++ .../piped/templates/backend/lib/_service.tpl | 185 ++++++++++++++ .../piped/templates/backend/lib/_volumes.tpl | 68 ++++++ .../apps/piped/templates/backend/service.yaml | 1 + charts/apps/piped/templates/common.yaml | 13 + .../piped/templates/frontend/deployment.yaml | 49 ++++ .../templates/frontend/lib/_container.tpl | 54 +++++ .../templates/frontend/lib/_env_vars.tpl | 43 ++++ .../piped/templates/frontend/lib/_names.tpl | 111 +++++++++ .../piped/templates/frontend/lib/_pod.tpl | 101 ++++++++ .../piped/templates/frontend/lib/_ports.tpl | 36 +++ .../piped/templates/frontend/lib/_probes.tpl | 33 +++ .../piped/templates/frontend/lib/_service.tpl | 186 ++++++++++++++ .../piped/templates/frontend/service.yaml | 1 + charts/apps/piped/templates/ingress.yaml | 228 ++++++++++++++++++ .../piped/templates/ytproxy/deployment.yaml | 49 ++++ .../templates/ytproxy/lib/_container.tpl | 54 +++++ .../piped/templates/ytproxy/lib/_env_vars.tpl | 43 ++++ .../piped/templates/ytproxy/lib/_ingress.tpl | 19 ++ .../piped/templates/ytproxy/lib/_names.tpl | 111 +++++++++ .../apps/piped/templates/ytproxy/lib/_pod.tpl | 105 ++++++++ .../piped/templates/ytproxy/lib/_ports.tpl | 36 +++ .../piped/templates/ytproxy/lib/_probes.tpl | 33 +++ .../piped/templates/ytproxy/lib/_service.tpl | 186 ++++++++++++++ .../piped/templates/ytproxy/lib/_volumes.tpl | 64 +++++ .../apps/piped/templates/ytproxy/service.yaml | 1 + charts/apps/piped/values.yaml | 184 ++++++++++++++ charts/piped/.helmignore | 26 -- charts/piped/Chart.yaml | 42 ---- charts/piped/README.md | 111 --------- charts/piped/templates/NOTES.txt | 1 - charts/piped/templates/common.yaml | 11 - charts/piped/values.yaml | 77 ------ 41 files changed, 2439 insertions(+), 269 deletions(-) create mode 100644 charts/apps/piped/Chart.yaml rename charts/{ => apps}/piped/README_CONFIG.md.gotmpl (94%) create mode 100644 charts/apps/piped/templates/backend/deployment.yaml create mode 100644 charts/apps/piped/templates/backend/lib/_container.tpl create mode 100644 charts/apps/piped/templates/backend/lib/_env_vars.tpl create mode 100644 charts/apps/piped/templates/backend/lib/_names.tpl create mode 100644 charts/apps/piped/templates/backend/lib/_pod.tpl create mode 100644 charts/apps/piped/templates/backend/lib/_ports.tpl create mode 100644 charts/apps/piped/templates/backend/lib/_probes.tpl create mode 100644 charts/apps/piped/templates/backend/lib/_service.tpl create mode 100644 charts/apps/piped/templates/backend/lib/_volumes.tpl create mode 100644 charts/apps/piped/templates/backend/service.yaml create mode 100644 charts/apps/piped/templates/common.yaml create mode 100644 charts/apps/piped/templates/frontend/deployment.yaml create mode 100644 charts/apps/piped/templates/frontend/lib/_container.tpl create mode 100644 charts/apps/piped/templates/frontend/lib/_env_vars.tpl create mode 100644 charts/apps/piped/templates/frontend/lib/_names.tpl create mode 100644 charts/apps/piped/templates/frontend/lib/_pod.tpl create mode 100644 charts/apps/piped/templates/frontend/lib/_ports.tpl create mode 100644 charts/apps/piped/templates/frontend/lib/_probes.tpl create mode 100644 charts/apps/piped/templates/frontend/lib/_service.tpl create mode 100644 charts/apps/piped/templates/frontend/service.yaml create mode 100644 charts/apps/piped/templates/ingress.yaml create mode 100644 charts/apps/piped/templates/ytproxy/deployment.yaml create mode 100644 charts/apps/piped/templates/ytproxy/lib/_container.tpl create mode 100644 charts/apps/piped/templates/ytproxy/lib/_env_vars.tpl create mode 100644 charts/apps/piped/templates/ytproxy/lib/_ingress.tpl create mode 100644 charts/apps/piped/templates/ytproxy/lib/_names.tpl create mode 100644 charts/apps/piped/templates/ytproxy/lib/_pod.tpl create mode 100644 charts/apps/piped/templates/ytproxy/lib/_ports.tpl create mode 100644 charts/apps/piped/templates/ytproxy/lib/_probes.tpl create mode 100644 charts/apps/piped/templates/ytproxy/lib/_service.tpl create mode 100644 charts/apps/piped/templates/ytproxy/lib/_volumes.tpl create mode 100644 charts/apps/piped/templates/ytproxy/service.yaml create mode 100644 charts/apps/piped/values.yaml delete mode 100644 charts/piped/.helmignore delete mode 100644 charts/piped/Chart.yaml delete mode 100644 charts/piped/README.md delete mode 100644 charts/piped/templates/NOTES.txt delete mode 100644 charts/piped/templates/common.yaml delete mode 100644 charts/piped/values.yaml diff --git a/charts/apps/piped/Chart.yaml b/charts/apps/piped/Chart.yaml new file mode 100644 index 0000000..9aab11a --- /dev/null +++ b/charts/apps/piped/Chart.yaml @@ -0,0 +1,13 @@ +--- +apiVersion: v2 +description: A chart to power Piped running on Kubernetes +name: piped +version: 0.0.1 +appVersion: latest +maintainers: + - name: Skyler Mäntysaari + email: samip5@users.noreply.github.com +dependencies: + - name: common + repository: https://bjw-s.github.io/helm-charts + version: 0.1.0 diff --git a/charts/piped/README_CONFIG.md.gotmpl b/charts/apps/piped/README_CONFIG.md.gotmpl similarity index 94% rename from charts/piped/README_CONFIG.md.gotmpl rename to charts/apps/piped/README_CONFIG.md.gotmpl index e93d80b..0360bf6 100644 --- a/charts/piped/README_CONFIG.md.gotmpl +++ b/charts/apps/piped/README_CONFIG.md.gotmpl @@ -6,4 +6,4 @@ {{ template "custom.custom.configuration.header" . }} N/A -{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/backend/deployment.yaml b/charts/apps/piped/templates/backend/deployment.yaml new file mode 100644 index 0000000..0c44548 --- /dev/null +++ b/charts/apps/piped/templates/backend/deployment.yaml @@ -0,0 +1,49 @@ +--- +{{- if .Values.backend.enabled -}} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "backend.names.fullname" . }} + {{- with (merge (.Values.backend.labels | default dict) (include "common.labels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + {{- with (merge (.Values.backend.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +spec: + revisionHistoryLimit: {{ .Values.backend.revisionHistoryLimit }} + replicas: {{ .Values.backend.replicas }} + {{- $strategy := default "Recreate" .Values.backend.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.backend.rollingUpdate }} + {{- if and (eq $strategy "RollingUpdate") (or .surge .unavailable) }} + rollingUpdate: + {{- with .unavailable }} + maxUnavailable: {{ . }} + {{- end }} + {{- with .surge }} + maxSurge: {{ . }} + {{- end }} + {{- end }} + {{- end }} + selector: + matchLabels: + {{- include "backend.labels.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with include ("backend.podAnnotations") . }} + annotations: + {{- . | nindent 8 }} + {{- end }} + labels: + {{- include "backend.labels.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- include "backend.controller.pod" . | nindent 6 }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/backend/lib/_container.tpl b/charts/apps/piped/templates/backend/lib/_container.tpl new file mode 100644 index 0000000..ad3d78c --- /dev/null +++ b/charts/apps/piped/templates/backend/lib/_container.tpl @@ -0,0 +1,54 @@ +{{- /* The main container included in the controller */ -}} +{{- define "backend.controller.mainContainer" -}} +- name: {{ include "backend.names.fullname" . }} + image: {{ printf "%s:%s" .Values.backend.image.repository (default .Chart.AppVersion .Values.backend.image.tag) | quote }} + imagePullPolicy: {{ .Values.backend.image.pullPolicy }} + {{- with .Values.backend.command }} + command: + {{- if kindIs "string" . }} + - {{ . }} + {{- else }} + {{ toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- with .Values.backend.args }} + args: + {{- if kindIs "string" . }} + - {{ . }} + {{- else }} + {{ toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- with .Values.backend.securityContext }} + securityContext: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.lifecycle }} + lifecycle: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.termination.messagePath }} + terminationMessagePath: {{ . }} + {{- end }} + {{- with .Values.termination.messagePolicy }} + terminationMessagePolicy: {{ . }} + {{- end }} + + {{- with .Values.backend.env }} + env: + {{- get (fromYaml (include "backend.controller.env_vars" $)) "env" | toYaml | nindent 4 -}} + {{- end }} + {{- if or .Values.backend.envFrom .Values.backend.secret }} + envFrom: + {{- with .Values.envFrom }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if .Values.secret }} + - secretRef: + name: {{ include "backend.names.fullname" . }} + {{- end }} + {{- end }} + {{- include "backend.controller.probes" . | trim | nindent 2 }} + ports: + {{- include "backend.controller.ports" . | trim | nindent 4 }} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/backend/lib/_env_vars.tpl b/charts/apps/piped/templates/backend/lib/_env_vars.tpl new file mode 100644 index 0000000..4b6fe2a --- /dev/null +++ b/charts/apps/piped/templates/backend/lib/_env_vars.tpl @@ -0,0 +1,43 @@ +{{/* +Environment variables used by containers. +*/}} +{{- define "backend.controller.env_vars" -}} + {{- $values := merge .Values.backend.env .Values.common_env -}} + {{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.env -}} + {{- $values = . -}} + {{- end -}} + {{- end -}} + + {{- with $values -}} + {{- $result := list -}} + {{- range $k, $v := . -}} + {{- $name := $k -}} + {{- $value := $v -}} + {{- if kindIs "int" $name -}} + {{- $name = required "environment variables as a list of maps require a name field" $value.name -}} + {{- end -}} + + {{- if kindIs "map" $value -}} + {{- if hasKey $value "value" -}} + {{- $envValue := $value.value | toString -}} + {{- $result = append $result (dict "name" $name "value" (tpl $envValue $)) -}} + {{- else if hasKey $value "valueFrom" -}} + {{- $result = append $result (dict "name" $name "valueFrom" $value.valueFrom) -}} + {{- else -}} + {{- $result = append $result (dict "name" $name "valueFrom" $value) -}} + {{- end -}} + {{- end -}} + {{- if not (kindIs "map" $value) -}} + {{- if kindIs "string" $value -}} + {{- $result = append $result (dict "name" $name "value" (tpl $value $)) -}} + {{- else if or (kindIs "float64" $value) (kindIs "bool" $value) -}} + {{- $result = append $result (dict "name" $name "value" ($value | toString)) -}} + {{- else -}} + {{- $result = append $result (dict "name" $name "value" $value) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- toYaml (dict "env" $result) | nindent 0 -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/backend/lib/_names.tpl b/charts/apps/piped/templates/backend/lib/_names.tpl new file mode 100644 index 0000000..ca15827 --- /dev/null +++ b/charts/apps/piped/templates/backend/lib/_names.tpl @@ -0,0 +1,111 @@ +{{/* Expand the name of the chart */}} +{{- define "backend.names.name" -}} + {{- $globalNameOverride := "" -}} + {{- if hasKey .Values "global" -}} + {{- $globalNameOverride = (default $globalNameOverride .Values.global.nameOverride) -}} + {{- end -}} + {{- default .Chart.Name (default .Values.nameOverride $globalNameOverride) | trunc 50 | trimSuffix "-" -}}-backend +{{- 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 "backend.names.fullname" -}} + {{- $name := include "backend.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 50 $name | trimSuffix "-" -}} +{{- end -}} + + +{{/* Create chart name and version as used by the chart label */}} +{{- define "backend.names.chart" -}} + {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 50 | trimSuffix "-" -}} +{{- end -}} + +{{/* Create the name of the ServiceAccount to use */}} +{{- define "backend.names.serviceAccountName" -}} + {{- if .Values.serviceAccount.create -}} + {{- default (include "backend.names.fullname" .) .Values.serviceAccount.name -}} + {{- else -}} + {{- default "default" .Values.serviceAccount.name -}} + {{- end -}} +{{- end -}} + +{{/* Return the properly cased version of the controller type */}} +{{- define "backend.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 -}} + +{{/* web labels shared across objects */}} +{{- define "backend.labels" -}} +helm.sh/chart: {{ include "backend.names.chart" . }} +{{ include "backend.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 "backend.labels.selectorLabels" -}} +app.kubernetes.io/name: {{ include "backend.names.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + + +{{/* Common annotations shared across objects */}} +{{- define "backend.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 "backend.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 ("backend.configmap") . | sha256sum) | nindent 0 -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/backend/lib/_pod.tpl b/charts/apps/piped/templates/backend/lib/_pod.tpl new file mode 100644 index 0000000..1f047dc --- /dev/null +++ b/charts/apps/piped/templates/backend/lib/_pod.tpl @@ -0,0 +1,105 @@ +{{- /* +The pod definition included in the controller. +*/ -}} +{{- define "backend.controller.pod" -}} + {{- with .Values.imagePullSecrets }} +imagePullSecrets: + {{- toYaml . | nindent 2 }} + {{- end }} +serviceAccountName: {{ include "backend.names.serviceAccountName" . }} +automountServiceAccountToken: {{ .Values.automountServiceAccountToken }} + {{- with .Values.podSecurityContext }} +securityContext: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.priorityClassName }} +priorityClassName: {{ . }} + {{- end }} + {{- with .Values.runtimeClassName }} +runtimeClassName: {{ . }} + {{- end }} + {{- with .Values.schedulerName }} +schedulerName: {{ . }} + {{- end }} + {{- with .Values.hostNetwork }} +hostNetwork: {{ . }} + {{- end }} + {{- with .Values.hostname }} +hostname: {{ . }} + {{- end }} + {{- if .Values.dnsPolicy }} +dnsPolicy: {{ .Values.dnsPolicy }} + {{- else if .Values.hostNetwork }} +dnsPolicy: ClusterFirstWithHostNet + {{- else }} +dnsPolicy: ClusterFirst + {{- end }} + {{- with .Values.dnsConfig }} +dnsConfig: + {{- toYaml . | nindent 2 }} + {{- end }} +enableServiceLinks: {{ .Values.enableServiceLinks }} + {{- with .Values.termination.gracePeriodSeconds }} +terminationGracePeriodSeconds: {{ . }} + {{- end }} + {{- if .Values.initContainers }} +initContainers: + {{- $initContainers := list }} + {{- range $index, $key := (keys .Values.initContainers | uniq | sortAlpha) }} + {{- $container := get $.Values.initContainers $key }} + {{- if not $container.name -}} + {{- $_ := set $container "name" $key }} + {{- end }} + {{- if $container.env -}} + {{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}} + {{- $newEnv := fromYaml (include "common.controller.env_vars" $) -}} + {{- $_ := unset $.ObjectValues "env" -}} + {{- $_ := set $container "env" $newEnv.env }} + {{- end }} + {{- $initContainers = append $initContainers $container }} + {{- end }} + {{- tpl (toYaml $initContainers) $ | nindent 2 }} + {{- end }} +containers: + {{- include "backend.controller.mainContainer" . | nindent 2 }} + {{- with .Values.additionalContainers }} + {{- $additionalContainers := list }} + {{- range $name, $container := . }} + {{- if not $container.name -}} + {{- $_ := set $container "name" $name }} + {{- end }} + {{- if $container.env -}} + {{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}} + {{- $newEnv := fromYaml (include "backend.controller.env_vars" $) -}} + {{- $_ := set $container "env" $newEnv.env }} + {{- $_ := unset $.ObjectValues "env" -}} + {{- end }} + {{- $additionalContainers = append $additionalContainers $container }} + {{- end }} + {{- tpl (toYaml $additionalContainers) $ | nindent 2 }} + {{- end }} + {{- with (include "backend.controller.volumes" . | trim) }} +volumes: + {{- nindent 2 . }} + {{- end }} + {{- with .Values.hostAliases }} +hostAliases: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.nodeSelector }} +nodeSelector: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.affinity }} +affinity: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.topologySpreadConstraints }} +topologySpreadConstraints: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.tolerations }} +tolerations: + {{- toYaml . | nindent 2 }} + {{- end }} +{{- end -}} diff --git a/charts/apps/piped/templates/backend/lib/_ports.tpl b/charts/apps/piped/templates/backend/lib/_ports.tpl new file mode 100644 index 0000000..e71e0c6 --- /dev/null +++ b/charts/apps/piped/templates/backend/lib/_ports.tpl @@ -0,0 +1,36 @@ +{{/* +Ports included by the controller. +*/}} +{{- define "backend.controller.ports" -}} + {{- $ports := list -}} + {{- range .Values.backend.service -}} + {{- if .enabled -}} + {{- range $name, $port := .ports -}} + {{- $_ := set $port "name" $name -}} + {{- $ports = mustAppend $ports $port -}} + {{- end }} + {{- end }} + {{- end }} + +{{/* export/render the list of ports */}} +{{- if $ports -}} +{{- range $_ := $ports }} +{{- if .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) }} + {{- end }} + containerPort: {{ .targetPort | default .port }} + {{- if .protocol }} + {{- if or ( eq .protocol "HTTP" ) ( eq .protocol "HTTPS" ) ( eq .protocol "TCP" ) }} + protocol: TCP + {{- else }} + protocol: {{ .protocol }} + {{- end }} + {{- else }} + protocol: TCP + {{- end }} +{{- end}} +{{- end -}} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/backend/lib/_probes.tpl b/charts/apps/piped/templates/backend/lib/_probes.tpl new file mode 100644 index 0000000..eabcb63 --- /dev/null +++ b/charts/apps/piped/templates/backend/lib/_probes.tpl @@ -0,0 +1,33 @@ +{{/* +Probes selection logic. +*/}} +{{- define "backend.controller.probes" -}} +{{- $primaryService := get .Values.backend.service (include "backend.service.primary" .) -}} +{{- $primaryPort := "" -}} +{{- if $primaryService -}} + {{- $primaryPort = get $primaryService.ports (include "backend.classes.service.ports.primary" (dict "serviceName" (include "backend.service.primary" .) "values" $primaryService)) -}} +{{- end -}} + +{{- range $probeName, $probe := .Values.probes }} + {{- if $probe.enabled -}} + {{- "" | nindent 0 }} + {{- $probeName }}Probe: + {{- if $probe.custom -}} + {{- $probe.spec | toYaml | nindent 2 }} + {{- else }} + {{- if and $primaryService $primaryPort -}} + {{- "tcpSocket:" | nindent 2 }} + {{- if $primaryPort.targetPort }} + {{- printf "port: %v" $primaryPort.targetPort | nindent 4 }} + {{- else}} + {{- printf "port: %v" $primaryPort.port | nindent 4 }} + {{- end }} + {{- printf "initialDelaySeconds: %v" $probe.spec.initialDelaySeconds | nindent 2 }} + {{- printf "failureThreshold: %v" $probe.spec.failureThreshold | nindent 2 }} + {{- printf "timeoutSeconds: %v" $probe.spec.timeoutSeconds | nindent 2 }} + {{- printf "periodSeconds: %v" $probe.spec.periodSeconds | nindent 2 }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/backend/lib/_service.tpl b/charts/apps/piped/templates/backend/lib/_service.tpl new file mode 100644 index 0000000..e5f4a08 --- /dev/null +++ b/charts/apps/piped/templates/backend/lib/_service.tpl @@ -0,0 +1,185 @@ +{{/* +Renders the Service objects required by the chart. +*/}} +{{- define "backend.service" -}} + {{- /* Generate named services as required */ -}} + {{- range $name, $service := .Values.backend.service }} + {{- if $service.enabled -}} + {{- $serviceValues := $service -}} + + {{/* set the default nameOverride to the service name */}} + {{- if and (not $serviceValues.nameOverride) (ne $name (include "backend.service.primary" $)) -}} + {{- $_ := set $serviceValues "nameOverride" $name -}} + {{ end -}} + + {{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}} + {{- include "backend.classes.service" $ }} + {{- end }} + {{- end }} +{{- end }} + +{{/* +Return the primary service object +*/}} +{{- define "backend.service.primary" -}} + {{- $enabledServices := dict -}} + {{- range $name, $service := .Values.backend.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 -}} + +{{/* +Return the primary port for a given Service object. +*/}} +{{- define "backend.classes.service.ports.primary" -}} + {{- $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 }} + + {{- $result := "" -}} + {{- range $name, $port := $enabledPorts -}} + {{- if and (hasKey $port "primary") $port.primary -}} + {{- $result = $name -}} + {{- end -}} + {{- end -}} + + {{- if not $result -}} + {{- $result = keys $enabledPorts | first -}} + {{- end -}} + {{- $result -}} +{{- end -}} + +{{/* +This saves the name of the service in a global variable +*/}} +{{- define "backend.servicename" -}} +{{- $values := .Values.backend.service -}} +{{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.service -}} + {{- $values = . -}} + {{- end -}} +{{ end -}} + +{{- $serviceName := include "backend.names.fullname" . -}} +{{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $serviceName = printf "%v-%v" $serviceName $values.nameOverride -}} +{{ end -}} +{{ $serviceName }} +{{- end -}} + + +{{/* +This template serves as a blueprint for all Service objects that are created. +*/}} +{{- define "backend.classes.service" -}} +{{- $values := .Values.backend.service -}} +{{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.service -}} + {{- $values = . -}} + {{- end -}} +{{ end -}} + +{{- $serviceName := include "backend.names.fullname" . -}} +{{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $serviceName = printf "%v-%v" $serviceName $values.nameOverride -}} +{{ end -}} +{{- $svcType := $values.type | default "" -}} +{{- $primaryPort := get $values.ports (include "backend.classes.service.ports.primary" (dict "values" $values)) }} +--- +apiVersion: v1 +kind: Service +metadata: + name: piped-backend + {{- with (merge ($values.labels | default dict) (include "backend.labels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + annotations: + {{- with (merge ($values.annotations | default dict) (include "backend.annotations" $ | fromYaml)) }} + {{ toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if (or (eq $svcType "ClusterIP") (empty $svcType)) }} + type: ClusterIP + {{- if $values.clusterIP }} + clusterIP: {{ $values.clusterIP }} + {{end}} + {{- else if eq $svcType "LoadBalancer" }} + type: {{ $svcType }} + {{- if $values.loadBalancerIP }} + loadBalancerIP: {{ $values.loadBalancerIP }} + {{- end }} + {{- if $values.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{ toYaml $values.loadBalancerSourceRanges | nindent 4 }} + {{- end -}} + {{- else }} + type: {{ $svcType }} + {{- end }} + {{- if $values.externalTrafficPolicy }} + externalTrafficPolicy: {{ $values.externalTrafficPolicy }} + {{- end }} + {{- if $values.sessionAffinity }} + sessionAffinity: {{ $values.sessionAffinity }} + {{- if $values.sessionAffinityConfig }} + sessionAffinityConfig: + {{ toYaml $values.sessionAffinityConfig | nindent 4 }} + {{- end -}} + {{- end }} + {{- with $values.externalIPs }} + externalIPs: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if $values.publishNotReadyAddresses }} + publishNotReadyAddresses: {{ $values.publishNotReadyAddresses }} + {{- end }} + {{- if $values.ipFamilyPolicy }} + ipFamilyPolicy: {{ $values.ipFamilyPolicy }} + {{- end }} + {{- with $values.ipFamilies }} + ipFamilies: + {{ 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 }} + selector: + {{- include "backend.labels.selectorLabels" . | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/backend/lib/_volumes.tpl b/charts/apps/piped/templates/backend/lib/_volumes.tpl new file mode 100644 index 0000000..e6993ce --- /dev/null +++ b/charts/apps/piped/templates/backend/lib/_volumes.tpl @@ -0,0 +1,68 @@ +{{/* +Volumes included by the controller. +*/}} +{{- define "backend.controller.volumes" -}} +{{- range $index, $persistence := .Values.persistence }} +{{- if $persistence.enabled }} +- name: {{ $index }} + {{- if eq (default "pvc" $persistence.type) "pvc" }} + {{- $pvcName := (include "common.names.fullname" $) -}} + {{- if $persistence.existingClaim }} + {{- /* Always prefer an existingClaim if that is set */}} + {{- $pvcName = $persistence.existingClaim -}} + {{- else -}} + {{- /* Otherwise refer to the PVC name */}} + {{- if $persistence.nameOverride -}} + {{- if not (eq $persistence.nameOverride "-") -}} + {{- $pvcName = (printf "%s-%s" (include "common.names.fullname" $) $persistence.nameOverride) -}} + {{- end -}} + {{- else -}} + {{- $pvcName = (printf "%s-%s" (include "common.names.fullname" $) $index) -}} + {{- end -}} + {{- end }} + persistentVolumeClaim: + claimName: {{ $pvcName }} + {{- else if or (eq $persistence.type "configMap") (eq $persistence.type "secret") }} + {{- $objectName := (required (printf "name not set for persistence item %s" $index) $persistence.name) }} + {{- $objectName = tpl $objectName $ }} + {{- if eq $persistence.type "configMap" }} + configMap: + name: {{ $objectName }} + {{- else }} + secret: + secretName: {{ $objectName }} + {{- end }} + {{- with $persistence.defaultMode }} + defaultMode: {{ . }} + {{- end }} + {{- with $persistence.items }} + items: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- else if eq $persistence.type "emptyDir" }} + {{- $emptyDir := dict -}} + {{- with $persistence.medium -}} + {{- $_ := set $emptyDir "medium" . -}} + {{- end -}} + {{- with $persistence.sizeLimit -}} + {{- $_ := set $emptyDir "sizeLimit" . -}} + {{- end }} + emptyDir: {{- $emptyDir | toYaml | nindent 4 }} + {{- else if eq $persistence.type "hostPath" }} + hostPath: + path: {{ required "hostPath not set" $persistence.hostPath }} + {{- with $persistence.hostPathType }} + type: {{ . }} + {{- end }} + {{- else if eq $persistence.type "nfs" }} + nfs: + server: {{ required "server not set" $persistence.server }} + path: {{ required "path not set" $persistence.path }} + {{- else if eq $persistence.type "custom" }} + {{- toYaml $persistence.volumeSpec | nindent 2 }} + {{- else }} + {{- fail (printf "Not a valid persistence.type (%s)" .Values.persistence.type) }} + {{- end }} +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/backend/service.yaml b/charts/apps/piped/templates/backend/service.yaml new file mode 100644 index 0000000..3dce526 --- /dev/null +++ b/charts/apps/piped/templates/backend/service.yaml @@ -0,0 +1 @@ +{{ include "backend.service" . | nindent 0 }} \ No newline at end of file diff --git a/charts/apps/piped/templates/common.yaml b/charts/apps/piped/templates/common.yaml new file mode 100644 index 0000000..bd7db60 --- /dev/null +++ b/charts/apps/piped/templates/common.yaml @@ -0,0 +1,13 @@ +--- +{{- include "common.values.setup" . }} + +{{- define "app-template.hardcodedValues" -}} + +# Set the nameOverride based on the release name if no override has been set +{{ if not .Values.global.nameOverride }} +global: + nameOverride: "{{ .Release.Name }}" +{{ end }} + +{{- end -}} +{{- $_ := mergeOverwrite .Values (include "app-template.hardcodedValues" . | fromYaml) -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/frontend/deployment.yaml b/charts/apps/piped/templates/frontend/deployment.yaml new file mode 100644 index 0000000..d7c0f46 --- /dev/null +++ b/charts/apps/piped/templates/frontend/deployment.yaml @@ -0,0 +1,49 @@ +--- +{{- if .Values.frontend.enabled -}} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "frontend.names.fullname" . }} + {{- with (merge (.Values.frontend.labels | default dict) (include "common.labels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + {{- with (merge (.Values.frontend.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +spec: + revisionHistoryLimit: {{ .Values.frontend.revisionHistoryLimit }} + replicas: {{ .Values.frontend.replicas }} + {{- $strategy := default "Recreate" .Values.frontend.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.frontend.rollingUpdate }} + {{- if and (eq $strategy "RollingUpdate") (or .surge .unavailable) }} + rollingUpdate: + {{- with .unavailable }} + maxUnavailable: {{ . }} + {{- end }} + {{- with .surge }} + maxSurge: {{ . }} + {{- end }} + {{- end }} + {{- end }} + selector: + matchLabels: + {{- include "frontend.labels.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with include ("frontend.podAnnotations") . }} + annotations: + {{- . | nindent 8 }} + {{- end }} + labels: + {{- include "frontend.labels.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- include "frontend.controller.pod" . | nindent 6 }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/frontend/lib/_container.tpl b/charts/apps/piped/templates/frontend/lib/_container.tpl new file mode 100644 index 0000000..0995de6 --- /dev/null +++ b/charts/apps/piped/templates/frontend/lib/_container.tpl @@ -0,0 +1,54 @@ +{{- /* The main container included in the controller */ -}} +{{- define "frontend.controller.mainContainer" -}} +- name: {{ include "frontend.names.fullname" . }} + image: {{ printf "%s:%s" .Values.frontend.image.repository (default .Chart.AppVersion .Values.frontend.image.tag) | quote }} + imagePullPolicy: {{ .Values.frontend.image.pullPolicy }} + {{- with .Values.frontend.command }} + command: + {{- if kindIs "string" . }} + - {{ . }} + {{- else }} + {{ toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- with .Values.frontend.args }} + args: + {{- if kindIs "string" . }} + - {{ . }} + {{- else }} + {{ toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- with .Values.frontend.securityContext }} + securityContext: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.lifecycle }} + lifecycle: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.termination.messagePath }} + terminationMessagePath: {{ . }} + {{- end }} + {{- with .Values.termination.messagePolicy }} + terminationMessagePolicy: {{ . }} + {{- end }} + + {{- with .Values.frontend.env }} + env: + {{- get (fromYaml (include "frontend.controller.env_vars" $)) "env" | toYaml | nindent 4 -}} + {{- end }} + {{- if or .Values.frontend.envFrom .Values.frontend.secret }} + envFrom: + {{- with .Values.envFrom }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if .Values.secret }} + - secretRef: + name: {{ include "frontend.names.fullname" . }} + {{- end }} + {{- end }} + {{- include "frontend.controller.probes" . | trim | nindent 2 }} + ports: + {{- include "frontend.controller.ports" . | trim | nindent 4 }} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/frontend/lib/_env_vars.tpl b/charts/apps/piped/templates/frontend/lib/_env_vars.tpl new file mode 100644 index 0000000..84ad387 --- /dev/null +++ b/charts/apps/piped/templates/frontend/lib/_env_vars.tpl @@ -0,0 +1,43 @@ +{{/* +Environment variables used by containers. +*/}} +{{- define "frontend.controller.env_vars" -}} + {{- $values := merge .Values.frontend.env .Values.common_env -}} + {{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.env -}} + {{- $values = . -}} + {{- end -}} + {{- end -}} + + {{- with $values -}} + {{- $result := list -}} + {{- range $k, $v := . -}} + {{- $name := $k -}} + {{- $value := $v -}} + {{- if kindIs "int" $name -}} + {{- $name = required "environment variables as a list of maps require a name field" $value.name -}} + {{- end -}} + + {{- if kindIs "map" $value -}} + {{- if hasKey $value "value" -}} + {{- $envValue := $value.value | toString -}} + {{- $result = append $result (dict "name" $name "value" (tpl $envValue $)) -}} + {{- else if hasKey $value "valueFrom" -}} + {{- $result = append $result (dict "name" $name "valueFrom" $value.valueFrom) -}} + {{- else -}} + {{- $result = append $result (dict "name" $name "valueFrom" $value) -}} + {{- end -}} + {{- end -}} + {{- if not (kindIs "map" $value) -}} + {{- if kindIs "string" $value -}} + {{- $result = append $result (dict "name" $name "value" (tpl $value $)) -}} + {{- else if or (kindIs "float64" $value) (kindIs "bool" $value) -}} + {{- $result = append $result (dict "name" $name "value" ($value | toString)) -}} + {{- else -}} + {{- $result = append $result (dict "name" $name "value" $value) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- toYaml (dict "env" $result) | nindent 0 -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/frontend/lib/_names.tpl b/charts/apps/piped/templates/frontend/lib/_names.tpl new file mode 100644 index 0000000..8439ca5 --- /dev/null +++ b/charts/apps/piped/templates/frontend/lib/_names.tpl @@ -0,0 +1,111 @@ +{{/* Expand the name of the chart */}} +{{- define "frontend.names.name" -}} + {{- $globalNameOverride := "" -}} + {{- if hasKey .Values "global" -}} + {{- $globalNameOverride = (default $globalNameOverride .Values.global.nameOverride) -}} + {{- end -}} + {{- default .Chart.Name (default .Values.nameOverride $globalNameOverride) | trunc 50 | trimSuffix "-" -}}-frontend +{{- 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 "frontend.names.fullname" -}} + {{- $name := include "frontend.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 50 $name | trimSuffix "-" -}} +{{- end -}} + + +{{/* Create chart name and version as used by the chart label */}} +{{- define "frontend.names.chart" -}} + {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 50 | trimSuffix "-" -}} +{{- end -}} + +{{/* Create the name of the ServiceAccount to use */}} +{{- define "frontend.names.serviceAccountName" -}} + {{- if .Values.serviceAccount.create -}} + {{- default (include "frontend.names.fullname" .) .Values.serviceAccount.name -}} + {{- else -}} + {{- default "default" .Values.serviceAccount.name -}} + {{- end -}} +{{- end -}} + +{{/* Return the properly cased version of the controller type */}} +{{- define "frontend.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 -}} + +{{/* web labels shared across objects */}} +{{- define "frontend.labels" -}} +helm.sh/chart: {{ include "frontend.names.chart" . }} +{{ include "frontend.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 "frontend.labels.selectorLabels" -}} +app.kubernetes.io/name: {{ include "frontend.names.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + + +{{/* Common annotations shared across objects */}} +{{- define "frontend.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 "frontend.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 ("frontend.configmap") . | sha256sum) | nindent 0 -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/frontend/lib/_pod.tpl b/charts/apps/piped/templates/frontend/lib/_pod.tpl new file mode 100644 index 0000000..66eca12 --- /dev/null +++ b/charts/apps/piped/templates/frontend/lib/_pod.tpl @@ -0,0 +1,101 @@ +{{- /* +The pod definition included in the controller. +*/ -}} +{{- define "frontend.controller.pod" -}} + {{- with .Values.imagePullSecrets }} +imagePullSecrets: + {{- toYaml . | nindent 2 }} + {{- end }} +serviceAccountName: {{ include "frontend.names.serviceAccountName" . }} +automountServiceAccountToken: {{ .Values.automountServiceAccountToken }} + {{- with .Values.podSecurityContext }} +securityContext: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.priorityClassName }} +priorityClassName: {{ . }} + {{- end }} + {{- with .Values.runtimeClassName }} +runtimeClassName: {{ . }} + {{- end }} + {{- with .Values.schedulerName }} +schedulerName: {{ . }} + {{- end }} + {{- with .Values.hostNetwork }} +hostNetwork: {{ . }} + {{- end }} + {{- with .Values.hostname }} +hostname: {{ . }} + {{- end }} + {{- if .Values.dnsPolicy }} +dnsPolicy: {{ .Values.dnsPolicy }} + {{- else if .Values.hostNetwork }} +dnsPolicy: ClusterFirstWithHostNet + {{- else }} +dnsPolicy: ClusterFirst + {{- end }} + {{- with .Values.dnsConfig }} +dnsConfig: + {{- toYaml . | nindent 2 }} + {{- end }} +enableServiceLinks: {{ .Values.enableServiceLinks }} + {{- with .Values.termination.gracePeriodSeconds }} +terminationGracePeriodSeconds: {{ . }} + {{- end }} + {{- if .Values.initContainers }} +initContainers: + {{- $initContainers := list }} + {{- range $index, $key := (keys .Values.initContainers | uniq | sortAlpha) }} + {{- $container := get $.Values.initContainers $key }} + {{- if not $container.name -}} + {{- $_ := set $container "name" $key }} + {{- end }} + {{- if $container.env -}} + {{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}} + {{- $newEnv := fromYaml (include "common.controller.env_vars" $) -}} + {{- $_ := unset $.ObjectValues "env" -}} + {{- $_ := set $container "env" $newEnv.env }} + {{- end }} + {{- $initContainers = append $initContainers $container }} + {{- end }} + {{- tpl (toYaml $initContainers) $ | nindent 2 }} + {{- end }} +containers: + {{- include "frontend.controller.mainContainer" . | nindent 2 }} + {{- with .Values.additionalContainers }} + {{- $additionalContainers := list }} + {{- range $name, $container := . }} + {{- if not $container.name -}} + {{- $_ := set $container "name" $name }} + {{- end }} + {{- if $container.env -}} + {{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}} + {{- $newEnv := fromYaml (include "frontend.controller.env_vars" $) -}} + {{- $_ := set $container "env" $newEnv.env }} + {{- $_ := unset $.ObjectValues "env" -}} + {{- end }} + {{- $additionalContainers = append $additionalContainers $container }} + {{- end }} + {{- tpl (toYaml $additionalContainers) $ | nindent 2 }} + {{- end }} + {{- with .Values.hostAliases }} +hostAliases: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.nodeSelector }} +nodeSelector: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.affinity }} +affinity: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.topologySpreadConstraints }} +topologySpreadConstraints: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.tolerations }} +tolerations: + {{- toYaml . | nindent 2 }} + {{- end }} +{{- end -}} diff --git a/charts/apps/piped/templates/frontend/lib/_ports.tpl b/charts/apps/piped/templates/frontend/lib/_ports.tpl new file mode 100644 index 0000000..4d78d15 --- /dev/null +++ b/charts/apps/piped/templates/frontend/lib/_ports.tpl @@ -0,0 +1,36 @@ +{{/* +Ports included by the controller. +*/}} +{{- define "frontend.controller.ports" -}} + {{- $ports := list -}} + {{- range .Values.frontend.service -}} + {{- if .enabled -}} + {{- range $name, $port := .ports -}} + {{- $_ := set $port "name" $name -}} + {{- $ports = mustAppend $ports $port -}} + {{- end }} + {{- end }} + {{- end }} + +{{/* export/render the list of ports */}} +{{- if $ports -}} +{{- range $_ := $ports }} +{{- if .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) }} + {{- end }} + containerPort: {{ .targetPort | default .port }} + {{- if .protocol }} + {{- if or ( eq .protocol "HTTP" ) ( eq .protocol "HTTPS" ) ( eq .protocol "TCP" ) }} + protocol: TCP + {{- else }} + protocol: {{ .protocol }} + {{- end }} + {{- else }} + protocol: TCP + {{- end }} +{{- end}} +{{- end -}} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/frontend/lib/_probes.tpl b/charts/apps/piped/templates/frontend/lib/_probes.tpl new file mode 100644 index 0000000..9bf08a6 --- /dev/null +++ b/charts/apps/piped/templates/frontend/lib/_probes.tpl @@ -0,0 +1,33 @@ +{{/* +Probes selection logic. +*/}} +{{- define "frontend.controller.probes" -}} +{{- $primaryService := get .Values.backend.service (include "frontend.service.primary" .) -}} +{{- $primaryPort := "" -}} +{{- if $primaryService -}} + {{- $primaryPort = get $primaryService.ports (include "frontend.classes.service.ports.primary" (dict "serviceName" (include "frontend.service.primary" .) "values" $primaryService)) -}} +{{- end -}} + +{{- range $probeName, $probe := .Values.probes }} + {{- if $probe.enabled -}} + {{- "" | nindent 0 }} + {{- $probeName }}Probe: + {{- if $probe.custom -}} + {{- $probe.spec | toYaml | nindent 2 }} + {{- else }} + {{- if and $primaryService $primaryPort -}} + {{- "tcpSocket:" | nindent 2 }} + {{- if $primaryPort.targetPort }} + {{- printf "port: %v" $primaryPort.targetPort | nindent 4 }} + {{- else}} + {{- printf "port: %v" $primaryPort.port | nindent 4 }} + {{- end }} + {{- printf "initialDelaySeconds: %v" $probe.spec.initialDelaySeconds | nindent 2 }} + {{- printf "failureThreshold: %v" $probe.spec.failureThreshold | nindent 2 }} + {{- printf "timeoutSeconds: %v" $probe.spec.timeoutSeconds | nindent 2 }} + {{- printf "periodSeconds: %v" $probe.spec.periodSeconds | nindent 2 }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/frontend/lib/_service.tpl b/charts/apps/piped/templates/frontend/lib/_service.tpl new file mode 100644 index 0000000..6322ae8 --- /dev/null +++ b/charts/apps/piped/templates/frontend/lib/_service.tpl @@ -0,0 +1,186 @@ +{{/* +Renders the Service objects required by the chart. +*/}} +{{- define "frontend.service" -}} + {{- /* Generate named services as required */ -}} + {{- range $name, $service := .Values.frontend.service }} + {{- if $service.enabled -}} + {{- $serviceValues := $service -}} + + {{/* set the default nameOverride to the service name */}} + {{- if and (not $serviceValues.nameOverride) (ne $name (include "frontend.service.primary" $)) -}} + {{- $_ := set $serviceValues "nameOverride" $name -}} + {{ end -}} + + {{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}} + {{- include "frontend.classes.service" $ }} + {{- end }} + {{- end }} +{{- end }} + +{{/* +Return the primary service object +*/}} +{{- define "frontend.service.primary" -}} + {{- $enabledServices := dict -}} + {{- range $name, $service := .Values.frontend.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 -}} + +{{/* +Return the primary port for a given Service object. +*/}} +{{- define "frontend.classes.service.ports.primary" -}} + {{- $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 }} + + {{- $result := "" -}} + {{- range $name, $port := $enabledPorts -}} + {{- if and (hasKey $port "primary") $port.primary -}} + {{- $result = $name -}} + {{- end -}} + {{- end -}} + + {{- if not $result -}} + {{- $result = keys $enabledPorts | first -}} + {{- end -}} + {{- $result -}} +{{- end -}} + +{{/* +This saves the name of the service in a global variable +*/}} +{{- define "frontend.servicename" -}} +{{- $values := .Values.frontend.service -}} +{{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.service -}} + {{- $values = . -}} + {{- end -}} +{{ end -}} + +{{- $serviceName := include "frontend.names.fullname" . -}} +{{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $serviceName = printf "%v-%v" $serviceName $values.nameOverride -}} +{{ end -}} +{{ $serviceName }} +{{- end -}} + + +{{/* +This template serves as a blueprint for all Service objects that are created +within the web. +*/}} +{{- define "frontend.classes.service" -}} +{{- $values := .Values.frontend.service -}} +{{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.service -}} + {{- $values = . -}} + {{- end -}} +{{ end -}} + +{{- $serviceName := include "frontend.names.fullname" . -}} +{{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $serviceName = printf "%v-%v" $serviceName $values.nameOverride -}} +{{ end -}} +{{- $svcType := $values.type | default "" -}} +{{- $primaryPort := get $values.ports (include "frontend.classes.service.ports.primary" (dict "values" $values)) }} +--- +apiVersion: v1 +kind: Service +metadata: + name: piped-frontend + {{- with (merge ($values.labels | default dict) (include "frontend.labels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + annotations: + {{- with (merge ($values.annotations | default dict) (include "frontend.annotations" $ | fromYaml)) }} + {{ toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if (or (eq $svcType "ClusterIP") (empty $svcType)) }} + type: ClusterIP + {{- if $values.clusterIP }} + clusterIP: {{ $values.clusterIP }} + {{end}} + {{- else if eq $svcType "LoadBalancer" }} + type: {{ $svcType }} + {{- if $values.loadBalancerIP }} + loadBalancerIP: {{ $values.loadBalancerIP }} + {{- end }} + {{- if $values.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{ toYaml $values.loadBalancerSourceRanges | nindent 4 }} + {{- end -}} + {{- else }} + type: {{ $svcType }} + {{- end }} + {{- if $values.externalTrafficPolicy }} + externalTrafficPolicy: {{ $values.externalTrafficPolicy }} + {{- end }} + {{- if $values.sessionAffinity }} + sessionAffinity: {{ $values.sessionAffinity }} + {{- if $values.sessionAffinityConfig }} + sessionAffinityConfig: + {{ toYaml $values.sessionAffinityConfig | nindent 4 }} + {{- end -}} + {{- end }} + {{- with $values.externalIPs }} + externalIPs: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if $values.publishNotReadyAddresses }} + publishNotReadyAddresses: {{ $values.publishNotReadyAddresses }} + {{- end }} + {{- if $values.ipFamilyPolicy }} + ipFamilyPolicy: {{ $values.ipFamilyPolicy }} + {{- end }} + {{- with $values.ipFamilies }} + ipFamilies: + {{ 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 }} + selector: + {{- include "frontend.labels.selectorLabels" . | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/frontend/service.yaml b/charts/apps/piped/templates/frontend/service.yaml new file mode 100644 index 0000000..7131919 --- /dev/null +++ b/charts/apps/piped/templates/frontend/service.yaml @@ -0,0 +1 @@ +{{ include "frontend.service" . | nindent 0 }} \ No newline at end of file diff --git a/charts/apps/piped/templates/ingress.yaml b/charts/apps/piped/templates/ingress.yaml new file mode 100644 index 0000000..1e1de5c --- /dev/null +++ b/charts/apps/piped/templates/ingress.yaml @@ -0,0 +1,228 @@ +--- +{{- if .Values.ingress.main.enabled }} + {{- $fullName := include "common.names.fullname" . -}} + {{- $ingressName := $fullName -}} + {{- $values := .Values.ingress.main -}} + + {{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.ingress -}} + {{- $values = . -}} + {{- end -}} + {{ end -}} + + {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $ingressName = printf "%v-%v" $ingressName $values.nameOverride -}} + {{- end -}} + + {{- $primaryService := .Values.frontend.service.main -}} + {{- $defaultServiceName := "piped-frontend" -}} + {{- $defaultServicePort := get $primaryService.ports (include "common.classes.service.ports.primary" (dict "values" $primaryService)) -}} + {{- $isStable := include "common.capabilities.ingress.isStable" . }} + --- + apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }} + kind: Ingress + metadata: + name: {{ $ingressName }} + {{- with (merge ($values.labels | default dict) (include "common.labels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + {{- with (merge ($values.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} + spec: + {{- if and $isStable $values.ingressClassName }} + ingressClassName: {{ $values.ingressClassName }} + {{- end }} + {{- if $values.tls }} + tls: + {{- range $values.tls }} + - hosts: + {{- range .hosts }} + - {{ tpl . $ | quote }} + {{- end }} + {{- if .secretName }} + secretName: {{ tpl .secretName $ | quote}} + {{- end }} + {{- end }} + {{- end }} + rules: + {{- range $values.hosts }} + - host: {{ tpl .host $ | quote }} + http: + paths: + {{- range .paths }} + {{- $service := $defaultServiceName -}} + {{- $port := $defaultServicePort.port -}} + {{- if .service -}} + {{- $service = default $service .service.name -}} + {{- $port = default $port .service.port -}} + {{- end }} + - path: {{ tpl .path $ | quote }} + {{- if $isStable }} + pathType: {{ default "Prefix" .pathType }} + {{- end }} + backend: + {{- if $isStable }} + service: + name: {{ $service }} + port: + number: {{ $port }} + {{- else }} + serviceName: {{ $service }} + servicePort: {{ $port }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} +--- +{{- if .Values.ingress.backend.enabled }} + {{- $fullName := include "common.names.fullname" . -}} + {{- $ingressName := $fullName -}} + {{- $values := .Values.ingress.backend -}} + + {{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.ingress -}} + {{- $values = . -}} + {{- end -}} + {{ end -}} + + {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $ingressName = printf "%v-%v" $ingressName $values.nameOverride -}} + {{- end -}} + + {{- $primaryService := .Values.ytproxy.service.main -}} + {{- $defaultServiceName := "piped-backend" -}} + {{- $defaultServicePort := get $primaryService.ports (include "common.classes.service.ports.primary" (dict "values" $primaryService)) -}} + {{- $isStable := include "common.capabilities.ingress.isStable" . }} + --- +apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }} +kind: Ingress +metadata: + name: {{ $ingressName }} + {{- with (merge ($values.labels | default dict) (include "common.labels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + {{- with (merge ($values.annotations | default dict) (include "common.annotations" $ | fromYaml) (include "backend.classes.ingress" $ | fromYaml)) }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and $isStable $values.ingressClassName }} + ingressClassName: {{ $values.ingressClassName }} + {{- end }} + {{- if $values.tls }} + tls: + {{- range $values.tls }} + - hosts: + {{- range .hosts }} + - {{ tpl . $ | quote }} + {{- end }} + {{- if .secretName }} + secretName: {{ tpl .secretName $ | quote}} + {{- end }} + {{- end }} + {{- end }} + rules: + {{- range $values.hosts }} + - host: {{ tpl .host $ | quote }} + http: + paths: + {{- range .paths }} + {{- $service := $defaultServiceName -}} + {{- $port := $defaultServicePort.port -}} + {{- if .service -}} + {{- $service = default $service .service.name -}} + {{- $port = default $port .service.port -}} + {{- end }} + - path: {{ tpl .path $ | quote }} + {{- if $isStable }} + pathType: {{ default "Prefix" .pathType }} + {{- end }} + backend: + {{- if $isStable }} + service: + name: {{ $service }} + port: + number: {{ $port }} + {{- else }} + serviceName: {{ $service }} + servicePort: {{ $port }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} +--- +{{- if .Values.ingress.ytproxy.enabled }} + {{- $fullName := include "common.names.fullname" . -}} + {{- $ingressName := $fullName -}} + {{- $values := .Values.ingress.ytproxy -}} + + {{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.ingress -}} + {{- $values = . -}} + {{- end -}} + {{ end -}} + + {{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $ingressName = printf "%v-%v" $ingressName $values.nameOverride -}} + {{- end -}} + + {{- $primaryService := .Values.ytproxy.service.main -}} + {{- $defaultServiceName := "piped-ytproxy" -}} + {{- $defaultServicePort := get $primaryService.ports (include "common.classes.service.ports.primary" (dict "values" $primaryService)) -}} + {{- $isStable := include "common.capabilities.ingress.isStable" . }} + --- + apiVersion: {{ include "common.capabilities.ingress.apiVersion" . }} + kind: Ingress + metadata: + name: {{ $ingressName }} + {{- with (merge ($values.labels | default dict) (include "common.labels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + {{- with (merge ($values.annotations | default dict) (include "common.annotations" $ | fromYaml) (include "ytproxy.classes.ingress" $ | fromYaml)) }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} + spec: + {{- if and $isStable $values.ingressClassName }} + ingressClassName: {{ $values.ingressClassName }} + {{- end }} + {{- if $values.tls }} + tls: + {{- range $values.tls }} + - hosts: + {{- range .hosts }} + - {{ tpl . $ | quote }} + {{- end }} + {{- if .secretName }} + secretName: {{ tpl .secretName $ | quote}} + {{- end }} + {{- end }} + {{- end }} + rules: + {{- range $values.hosts }} + - host: {{ tpl .host $ | quote }} + http: + paths: + {{- range .paths }} + {{- $service := $defaultServiceName -}} + {{- $port := $defaultServicePort.port -}} + {{- if .service -}} + {{- $service = default $service .service.name -}} + {{- $port = default $port .service.port -}} + {{- end }} + - path: {{ tpl .path $ | quote }} + {{- if $isStable }} + pathType: {{ default "Prefix" .pathType }} + {{- end }} + backend: + {{- if $isStable }} + service: + name: {{ $service }} + port: + number: {{ $port }} + {{- else }} + serviceName: {{ $service }} + servicePort: {{ $port }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/deployment.yaml b/charts/apps/piped/templates/ytproxy/deployment.yaml new file mode 100644 index 0000000..583f4b3 --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/deployment.yaml @@ -0,0 +1,49 @@ +--- +{{- if .Values.ytproxy.enabled -}} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "ytproxy.names.fullname" . }} + {{- with (merge (.Values.ytproxy.labels | default dict) (include "common.labels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + {{- with (merge (.Values.ytproxy.annotations | default dict) (include "common.annotations" $ | fromYaml)) }} + annotations: {{- toYaml . | nindent 4 }} + {{- end }} +spec: + revisionHistoryLimit: {{ .Values.ytproxy.revisionHistoryLimit }} + replicas: {{ .Values.ytproxy.replicas }} + {{- $strategy := default "Recreate" .Values.ytproxy.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.ytproxy.rollingUpdate }} + {{- if and (eq $strategy "RollingUpdate") (or .surge .unavailable) }} + rollingUpdate: + {{- with .unavailable }} + maxUnavailable: {{ . }} + {{- end }} + {{- with .surge }} + maxSurge: {{ . }} + {{- end }} + {{- end }} + {{- end }} + selector: + matchLabels: + {{- include "ytproxy.labels.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with include ("ytproxy.podAnnotations") . }} + annotations: + {{- . | nindent 8 }} + {{- end }} + labels: + {{- include "ytproxy.labels.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- include "ytproxy.controller.pod" . | nindent 6 }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/lib/_container.tpl b/charts/apps/piped/templates/ytproxy/lib/_container.tpl new file mode 100644 index 0000000..7ad863c --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/lib/_container.tpl @@ -0,0 +1,54 @@ +{{- /* The main container included in the controller */ -}} +{{- define "ytproxy.controller.mainContainer" -}} +- name: {{ include "ytproxy.names.fullname" . }} + image: {{ printf "%s:%s" .Values.ytproxy.image.repository (default .Chart.AppVersion .Values.ytproxy.image.tag) | quote }} + imagePullPolicy: {{ .Values.ytproxy.image.pullPolicy }} + {{- with .Values.ytproxy.command }} + command: + {{- if kindIs "string" . }} + - {{ . }} + {{- else }} + {{ toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- with .Values.ytproxy.args }} + args: + {{- if kindIs "string" . }} + - {{ . }} + {{- else }} + {{ toYaml . | nindent 4 }} + {{- end }} + {{- end }} + {{- with .Values.ytproxy.securityContext }} + securityContext: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.lifecycle }} + lifecycle: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.termination.messagePath }} + terminationMessagePath: {{ . }} + {{- end }} + {{- with .Values.termination.messagePolicy }} + terminationMessagePolicy: {{ . }} + {{- end }} + + {{- with .Values.ytproxy.env }} + env: + {{- get (fromYaml (include "ytproxy.controller.env_vars" $)) "env" | toYaml | nindent 4 -}} + {{- end }} + {{- if or .Values.ytproxy.envFrom .Values.ytproxy.secret }} + envFrom: + {{- with .Values.envFrom }} + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if .Values.secret }} + - secretRef: + name: {{ include "ytproxy.names.fullname" . }} + {{- end }} + {{- end }} + {{- include "ytproxy.controller.probes" . | trim | nindent 2 }} + ports: + {{- include "ytproxy.controller.ports" . | trim | nindent 4 }} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/lib/_env_vars.tpl b/charts/apps/piped/templates/ytproxy/lib/_env_vars.tpl new file mode 100644 index 0000000..e544622 --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/lib/_env_vars.tpl @@ -0,0 +1,43 @@ +{{/* +Environment variables used by containers. +*/}} +{{- define "ytproxy.controller.env_vars" -}} + {{- $values := merge .Values.ytproxy.env .Values.common_env -}} + {{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.env -}} + {{- $values = . -}} + {{- end -}} + {{- end -}} + + {{- with $values -}} + {{- $result := list -}} + {{- range $k, $v := . -}} + {{- $name := $k -}} + {{- $value := $v -}} + {{- if kindIs "int" $name -}} + {{- $name = required "environment variables as a list of maps require a name field" $value.name -}} + {{- end -}} + + {{- if kindIs "map" $value -}} + {{- if hasKey $value "value" -}} + {{- $envValue := $value.value | toString -}} + {{- $result = append $result (dict "name" $name "value" (tpl $envValue $)) -}} + {{- else if hasKey $value "valueFrom" -}} + {{- $result = append $result (dict "name" $name "valueFrom" $value.valueFrom) -}} + {{- else -}} + {{- $result = append $result (dict "name" $name "valueFrom" $value) -}} + {{- end -}} + {{- end -}} + {{- if not (kindIs "map" $value) -}} + {{- if kindIs "string" $value -}} + {{- $result = append $result (dict "name" $name "value" (tpl $value $)) -}} + {{- else if or (kindIs "float64" $value) (kindIs "bool" $value) -}} + {{- $result = append $result (dict "name" $name "value" ($value | toString)) -}} + {{- else -}} + {{- $result = append $result (dict "name" $name "value" $value) -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- toYaml (dict "env" $result) | nindent 0 -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/lib/_ingress.tpl b/charts/apps/piped/templates/ytproxy/lib/_ingress.tpl new file mode 100644 index 0000000..a520391 --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/lib/_ingress.tpl @@ -0,0 +1,19 @@ +{{/* +Renders the ingress objects required. +*/}} +{{- define "ytproxy.classes.ingress" -}} + {{- /* Generate named services as required */ -}} + {{- range $name, $service := .Values.ytproxy.service }} + {{- if $service.enabled -}} + {{- $serviceValues := $service -}} + + {{/* set the default nameOverride to the service name */}} + {{- if and (not $serviceValues.nameOverride) (ne $name (include "ytproxy.service.primary" $)) -}} + {{- $_ := set $serviceValues "nameOverride" $name -}} + {{ end -}} + + {{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}} + {{- include "ytproxy.classes.service" $ }} + {{- end }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/lib/_names.tpl b/charts/apps/piped/templates/ytproxy/lib/_names.tpl new file mode 100644 index 0000000..fb54283 --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/lib/_names.tpl @@ -0,0 +1,111 @@ +{{/* Expand the name of the chart */}} +{{- define "ytproxy.names.name" -}} + {{- $globalNameOverride := "" -}} + {{- if hasKey .Values "global" -}} + {{- $globalNameOverride = (default $globalNameOverride .Values.global.nameOverride) -}} + {{- end -}} + {{- default .Chart.Name (default .Values.nameOverride $globalNameOverride) | trunc 50 | trimSuffix "-" -}}-ytproxy +{{- 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 "ytproxy.names.fullname" -}} + {{- $name := include "ytproxy.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 50 $name | trimSuffix "-" -}} +{{- end -}} + + +{{/* Create chart name and version as used by the chart label */}} +{{- define "ytproxy.names.chart" -}} + {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 50 | trimSuffix "-" -}} +{{- end -}} + +{{/* Create the name of the ServiceAccount to use */}} +{{- define "ytproxy.names.serviceAccountName" -}} + {{- if .Values.serviceAccount.create -}} + {{- default (include "ytproxy.names.fullname" .) .Values.serviceAccount.name -}} + {{- else -}} + {{- default "default" .Values.serviceAccount.name -}} + {{- end -}} +{{- end -}} + +{{/* Return the properly cased version of the controller type */}} +{{- define "ytproxy.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 -}} + +{{/* web labels shared across objects */}} +{{- define "ytproxy.labels" -}} +helm.sh/chart: {{ include "ytproxy.names.chart" . }} +{{ include "ytproxy.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 "ytproxy.labels.selectorLabels" -}} +app.kubernetes.io/name: {{ include "ytproxy.names.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end -}} + + +{{/* Common annotations shared across objects */}} +{{- define "ytproxy.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 "ytproxy.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 ("ytproxy.configmap") . | sha256sum) | nindent 0 -}} + {{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/lib/_pod.tpl b/charts/apps/piped/templates/ytproxy/lib/_pod.tpl new file mode 100644 index 0000000..fde2d87 --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/lib/_pod.tpl @@ -0,0 +1,105 @@ +{{- /* +The pod definition included in the controller. +*/ -}} +{{- define "ytproxy.controller.pod" -}} + {{- with .Values.imagePullSecrets }} +imagePullSecrets: + {{- toYaml . | nindent 2 }} + {{- end }} +serviceAccountName: {{ include "ytproxy.names.serviceAccountName" . }} +automountServiceAccountToken: {{ .Values.automountServiceAccountToken }} + {{- with .Values.podSecurityContext }} +securityContext: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.priorityClassName }} +priorityClassName: {{ . }} + {{- end }} + {{- with .Values.runtimeClassName }} +runtimeClassName: {{ . }} + {{- end }} + {{- with .Values.schedulerName }} +schedulerName: {{ . }} + {{- end }} + {{- with .Values.hostNetwork }} +hostNetwork: {{ . }} + {{- end }} + {{- with .Values.hostname }} +hostname: {{ . }} + {{- end }} + {{- if .Values.dnsPolicy }} +dnsPolicy: {{ .Values.dnsPolicy }} + {{- else if .Values.hostNetwork }} +dnsPolicy: ClusterFirstWithHostNet + {{- else }} +dnsPolicy: ClusterFirst + {{- end }} + {{- with .Values.dnsConfig }} +dnsConfig: + {{- toYaml . | nindent 2 }} + {{- end }} +enableServiceLinks: {{ .Values.enableServiceLinks }} + {{- with .Values.termination.gracePeriodSeconds }} +terminationGracePeriodSeconds: {{ . }} + {{- end }} + {{- if .Values.initContainers }} +initContainers: + {{- $initContainers := list }} + {{- range $index, $key := (keys .Values.initContainers | uniq | sortAlpha) }} + {{- $container := get $.Values.initContainers $key }} + {{- if not $container.name -}} + {{- $_ := set $container "name" $key }} + {{- end }} + {{- if $container.env -}} + {{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}} + {{- $newEnv := fromYaml (include "common.controller.env_vars" $) -}} + {{- $_ := unset $.ObjectValues "env" -}} + {{- $_ := set $container "env" $newEnv.env }} + {{- end }} + {{- $initContainers = append $initContainers $container }} + {{- end }} + {{- tpl (toYaml $initContainers) $ | nindent 2 }} + {{- end }} +containers: + {{- include "ytproxy.controller.mainContainer" . | nindent 2 }} + {{- with .Values.additionalContainers }} + {{- $additionalContainers := list }} + {{- range $name, $container := . }} + {{- if not $container.name -}} + {{- $_ := set $container "name" $name }} + {{- end }} + {{- if $container.env -}} + {{- $_ := set $ "ObjectValues" (dict "env" $container.env) -}} + {{- $newEnv := fromYaml (include "ytproxy.controller.env_vars" $) -}} + {{- $_ := set $container "env" $newEnv.env }} + {{- $_ := unset $.ObjectValues "env" -}} + {{- end }} + {{- $additionalContainers = append $additionalContainers $container }} + {{- end }} + {{- tpl (toYaml $additionalContainers) $ | nindent 2 }} + {{- end }} + {{- with (include "ytproxy.controller.volumes" . | trim) }} +volumes: + {{- nindent 2 . }} + {{- end }} + {{- with .Values.hostAliases }} +hostAliases: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.nodeSelector }} +nodeSelector: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.affinity }} +affinity: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.topologySpreadConstraints }} +topologySpreadConstraints: + {{- toYaml . | nindent 2 }} + {{- end }} + {{- with .Values.tolerations }} +tolerations: + {{- toYaml . | nindent 2 }} + {{- end -}} +{{- end -}} diff --git a/charts/apps/piped/templates/ytproxy/lib/_ports.tpl b/charts/apps/piped/templates/ytproxy/lib/_ports.tpl new file mode 100644 index 0000000..ed16a83 --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/lib/_ports.tpl @@ -0,0 +1,36 @@ +{{/* +Ports included by the controller. +*/}} +{{- define "ytproxy.controller.ports" -}} + {{- $ports := list -}} + {{- range .Values.ytproxy.service -}} + {{- if .enabled -}} + {{- range $name, $port := .ports -}} + {{- $_ := set $port "name" $name -}} + {{- $ports = mustAppend $ports $port -}} + {{- end }} + {{- end }} + {{- end }} + +{{/* export/render the list of ports */}} +{{- if $ports -}} +{{- range $_ := $ports }} +{{- if .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) }} + {{- end }} + containerPort: {{ .targetPort | default .port }} + {{- if .protocol }} + {{- if or ( eq .protocol "HTTP" ) ( eq .protocol "HTTPS" ) ( eq .protocol "TCP" ) }} + protocol: TCP + {{- else }} + protocol: {{ .protocol }} + {{- end }} + {{- else }} + protocol: TCP + {{- end }} +{{- end}} +{{- end -}} +{{- end -}} +{{- end -}} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/lib/_probes.tpl b/charts/apps/piped/templates/ytproxy/lib/_probes.tpl new file mode 100644 index 0000000..658c687 --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/lib/_probes.tpl @@ -0,0 +1,33 @@ +{{/* +Probes selection logic. +*/}} +{{- define "ytproxy.controller.probes" -}} +{{- $primaryService := get .Values.backend.service (include "ytproxy.service.primary" .) -}} +{{- $primaryPort := "" -}} +{{- if $primaryService -}} + {{- $primaryPort = get $primaryService.ports (include "ytproxy.classes.service.ports.primary" (dict "serviceName" (include "ytproxy.service.primary" .) "values" $primaryService)) -}} +{{- end -}} + +{{- range $probeName, $probe := .Values.probes }} + {{- if $probe.enabled -}} + {{- "" | nindent 0 }} + {{- $probeName }}Probe: + {{- if $probe.custom -}} + {{- $probe.spec | toYaml | nindent 2 }} + {{- else }} + {{- if and $primaryService $primaryPort -}} + {{- "tcpSocket:" | nindent 2 }} + {{- if $primaryPort.targetPort }} + {{- printf "port: %v" $primaryPort.targetPort | nindent 4 }} + {{- else}} + {{- printf "port: %v" $primaryPort.port | nindent 4 }} + {{- end }} + {{- printf "initialDelaySeconds: %v" $probe.spec.initialDelaySeconds | nindent 2 }} + {{- printf "failureThreshold: %v" $probe.spec.failureThreshold | nindent 2 }} + {{- printf "timeoutSeconds: %v" $probe.spec.timeoutSeconds | nindent 2 }} + {{- printf "periodSeconds: %v" $probe.spec.periodSeconds | nindent 2 }} + {{- end }} + {{- end }} + {{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/lib/_service.tpl b/charts/apps/piped/templates/ytproxy/lib/_service.tpl new file mode 100644 index 0000000..b1f4a6a --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/lib/_service.tpl @@ -0,0 +1,186 @@ +{{/* +Renders the Service objects required by the chart. +*/}} +{{- define "ytproxy.service" -}} + {{- /* Generate named services as required */ -}} + {{- range $name, $service := .Values.ytproxy.service }} + {{- if $service.enabled -}} + {{- $serviceValues := $service -}} + + {{/* set the default nameOverride to the service name */}} + {{- if and (not $serviceValues.nameOverride) (ne $name (include "ytproxy.service.primary" $)) -}} + {{- $_ := set $serviceValues "nameOverride" $name -}} + {{ end -}} + + {{- $_ := set $ "ObjectValues" (dict "service" $serviceValues) -}} + {{- include "ytproxy.classes.service" $ }} + {{- end }} + {{- end }} +{{- end }} + +{{/* +Return the primary service object +*/}} +{{- define "ytproxy.service.primary" -}} + {{- $enabledServices := dict -}} + {{- range $name, $service := .Values.ytproxy.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 -}} + +{{/* +Return the primary port for a given Service object. +*/}} +{{- define "ytproxy.classes.service.ports.primary" -}} + {{- $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 }} + + {{- $result := "" -}} + {{- range $name, $port := $enabledPorts -}} + {{- if and (hasKey $port "primary") $port.primary -}} + {{- $result = $name -}} + {{- end -}} + {{- end -}} + + {{- if not $result -}} + {{- $result = keys $enabledPorts | first -}} + {{- end -}} + {{- $result -}} +{{- end -}} + +{{/* +This saves the name of the service in a global variable +*/}} +{{- define "ytproxy.servicename" -}} +{{- $values := .Values.ytproxy.service -}} +{{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.service -}} + {{- $values = . -}} + {{- end -}} +{{ end -}} + +{{- $serviceName := include "ytproxy.names.fullname" . -}} +{{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $serviceName = printf "%v-%v" $serviceName $values.nameOverride -}} +{{ end -}} +{{ $serviceName }} +{{- end -}} + + +{{/* +This template serves as a blueprint for all Service objects that are created +within the web. +*/}} +{{- define "ytproxy.classes.service" -}} +{{- $values := .Values.ytproxy.service -}} +{{- if hasKey . "ObjectValues" -}} + {{- with .ObjectValues.service -}} + {{- $values = . -}} + {{- end -}} +{{ end -}} + +{{- $serviceName := include "ytproxy.names.fullname" . -}} +{{- if and (hasKey $values "nameOverride") $values.nameOverride -}} + {{- $serviceName = printf "%v-%v" $serviceName $values.nameOverride -}} +{{ end -}} +{{- $svcType := $values.type | default "" -}} +{{- $primaryPort := get $values.ports (include "ytproxy.classes.service.ports.primary" (dict "values" $values)) }} +--- +apiVersion: v1 +kind: Service +metadata: + name: piped-ytproxy + {{- with (merge ($values.labels | default dict) (include "ytproxy.labels" $ | fromYaml)) }} + labels: {{- toYaml . | nindent 4 }} + {{- end }} + annotations: + {{- with (merge ($values.annotations | default dict) (include "ytproxy.annotations" $ | fromYaml)) }} + {{ toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if (or (eq $svcType "ClusterIP") (empty $svcType)) }} + type: ClusterIP + {{- if $values.clusterIP }} + clusterIP: {{ $values.clusterIP }} + {{end}} + {{- else if eq $svcType "LoadBalancer" }} + type: {{ $svcType }} + {{- if $values.loadBalancerIP }} + loadBalancerIP: {{ $values.loadBalancerIP }} + {{- end }} + {{- if $values.loadBalancerSourceRanges }} + loadBalancerSourceRanges: + {{ toYaml $values.loadBalancerSourceRanges | nindent 4 }} + {{- end -}} + {{- else }} + type: {{ $svcType }} + {{- end }} + {{- if $values.externalTrafficPolicy }} + externalTrafficPolicy: {{ $values.externalTrafficPolicy }} + {{- end }} + {{- if $values.sessionAffinity }} + sessionAffinity: {{ $values.sessionAffinity }} + {{- if $values.sessionAffinityConfig }} + sessionAffinityConfig: + {{ toYaml $values.sessionAffinityConfig | nindent 4 }} + {{- end -}} + {{- end }} + {{- with $values.externalIPs }} + externalIPs: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- if $values.publishNotReadyAddresses }} + publishNotReadyAddresses: {{ $values.publishNotReadyAddresses }} + {{- end }} + {{- if $values.ipFamilyPolicy }} + ipFamilyPolicy: {{ $values.ipFamilyPolicy }} + {{- end }} + {{- with $values.ipFamilies }} + ipFamilies: + {{ 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 }} + selector: + {{- include "ytproxy.labels.selectorLabels" . | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/lib/_volumes.tpl b/charts/apps/piped/templates/ytproxy/lib/_volumes.tpl new file mode 100644 index 0000000..87afe13 --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/lib/_volumes.tpl @@ -0,0 +1,64 @@ +{{/* +Volumes included by the controller. +*/}} +{{- define "ytproxy.controller.volumes" -}} +{{- range $index, $persistence := .Values.persistence }} +{{- if $persistence.enabled }} +- name: {{ $index }} + {{- if eq (default "pvc" $persistence.type) "pvc" }} + {{- $pvcName := (include "common.names.fullname" $) -}} + {{- if $persistence.existingClaim }} + {{- /* Always prefer an existingClaim if that is set */}} + {{- $pvcName = $persistence.existingClaim -}} + {{- else -}} + {{- /* Otherwise refer to the PVC name */}} + {{- if $persistence.nameOverride -}} + {{- if not (eq $persistence.nameOverride "-") -}} + {{- $pvcName = (printf "%s-%s" (include "common.names.fullname" $) $persistence.nameOverride) -}} + {{- end -}} + {{- else -}} + {{- $pvcName = (printf "%s-%s" (include "common.names.fullname" $) $index) -}} + {{- end -}} + {{- end }} + persistentVolumeClaim: + claimName: {{ $pvcName }} + {{- else if or (eq $persistence.type "configMap") (eq $persistence.type "secret") }} + {{- $objectName := (required (printf "name not set for persistence item %s" $index) $persistence.name) }} + {{- $objectName = tpl $objectName $ }} + {{- if eq $persistence.type "configMap" }} + configMap: + name: {{ $objectName }} + {{- else }} + secret: + secretName: {{ $objectName }} + {{- end }} + {{- with $persistence.defaultMode }} + defaultMode: {{ . }} + {{- end }} + {{- with $persistence.items }} + items: + {{- toYaml . | nindent 6 }} + {{- end }} + {{- else if eq $persistence.type "emptyDir" }} + {{- $emptyDir := dict -}} + {{- with $persistence.medium -}} + {{- $_ := set $emptyDir "medium" . -}} + {{- end -}} + {{- with $persistence.sizeLimit -}} + {{- $_ := set $emptyDir "sizeLimit" . -}} + {{- end }} + emptyDir: {{- $emptyDir | toYaml | nindent 4 }} + {{- else if eq $persistence.type "hostPath" }} + hostPath: + path: {{ required "hostPath not set" $persistence.hostPath }} + {{- with $persistence.hostPathType }} + type: {{ . }} + {{- end }} + {{- else if eq $persistence.type "custom" }} + {{- toYaml $persistence.volumeSpec | nindent 2 }} + {{- else }} + {{- fail (printf "Not a valid persistence.type (%s)" .Values.persistence.type) }} + {{- end }} +{{- end }} +{{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/apps/piped/templates/ytproxy/service.yaml b/charts/apps/piped/templates/ytproxy/service.yaml new file mode 100644 index 0000000..eefb8ee --- /dev/null +++ b/charts/apps/piped/templates/ytproxy/service.yaml @@ -0,0 +1 @@ +{{ include "ytproxy.service" . | nindent 0 }} \ No newline at end of file diff --git a/charts/apps/piped/values.yaml b/charts/apps/piped/values.yaml new file mode 100644 index 0000000..f8c9952 --- /dev/null +++ b/charts/apps/piped/values.yaml @@ -0,0 +1,184 @@ +--- +global: + # -- Set an override for the prefix of the fullname + nameOverride: + # -- Set the entire name definition + fullnameOverride: + # -- Set additional global labels. Helm templates can be used. + labels: { } + # -- Set additional global annotations. Helm templates can be used. + annotations: { } + +controller: + # -- enable the controller. + enabled: true + +serviceAccount: + create: false + + +frontend: + enabled: true + service: + main: + enabled: true + primary: true + type: ClusterIP + ports: + http: + enabled: true + primary: true + port: 80 + protocol: HTTP + + image: + # -- image repository + repository: 1337kavin/piped + # -- image tag + # @chart.appVersion + tag: + # -- image pull policy + pullPolicy: IfNotPresent + + command: "/bin/ash -c" + args: + - sed -i s/pipedapi.kavin.rocks/BACKEND_HOSTNAME/g /usr/share/nginx/html/assets/* && /docker-entrypoint.sh && nginx -g "daemon off;" + +backend: + enabled: true + service: + main: + enabled: true + primary: true + type: ClusterIP + ports: + http: + enabled: true + primary: true + port: 8080 + protocol: HTTP + + image: + # -- image repository + repository: 1337kavin/piped + # -- image tag + # @chart.appVersion + tag: + # -- image pull policy + pullPolicy: IfNotPresent + + + +ytproxy: + enabled: true + service: + main: + enabled: true + primary: true + type: ClusterIP + ports: + http: + enabled: true + primary: true + port: 8080 + protocol: HTTP + + + image: + # -- image repository + repository: 1337kavin/piped-proxy + # -- image tag + # @chart.appVersion + tag: + # -- image pull policy + pullPolicy: IfNotPresent + + +ingress: + main: + enabled: false + primary: false + hosts: + - host: chart-foo.local + paths: + - path: "/" + tls: [] + + backend: + enabled: false + primary: false + hosts: + - host: be.chart-foo.local + paths: + - path: "/" + tls: [] + + ytproxy: + enabled: false + primary: false + hosts: + - host: ytproxy.chart-foo.local + paths: + - path: "/" + tls: [] + + + +# -- Probe configuration +# -- [[ref]](https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/) +# @default -- See below +probes: + # -- Liveness probe configuration + # @default -- See below + liveness: + # -- Enable the liveness probe + enabled: true + # -- Set this to `true` if you wish to specify your own livenessProbe + custom: false + # -- The spec field contains the values for the default livenessProbe. + # If you selected `custom: true`, this field holds the definition of the livenessProbe. + # @default -- See below + spec: + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + + # -- Redainess probe configuration + # @default -- See below + readiness: + # -- Enable the readiness probe + enabled: true + # -- Set this to `true` if you wish to specify your own readinessProbe + custom: false + # -- The spec field contains the values for the default readinessProbe. + # If you selected `custom: true`, this field holds the definition of the readinessProbe. + # @default -- See below + spec: + initialDelaySeconds: 0 + periodSeconds: 10 + timeoutSeconds: 1 + failureThreshold: 3 + + # -- Startup probe configuration + # @default -- See below + startup: + # -- Enable the startup probe + enabled: true + # -- Set this to `true` if you wish to specify your own startupProbe + custom: false + # -- The spec field contains the values for the default startupProbe. + # If you selected `custom: true`, this field holds the definition of the startupProbe. + # @default -- See below + spec: + initialDelaySeconds: 0 + timeoutSeconds: 1 + ## This means it has a maximum of 5*30=150 seconds to start up before it fails + periodSeconds: 5 + failureThreshold: 30 + +termination: + gracePeriodSeconds: + + + diff --git a/charts/piped/.helmignore b/charts/piped/.helmignore deleted file mode 100644 index 4379e2b..0000000 --- a/charts/piped/.helmignore +++ /dev/null @@ -1,26 +0,0 @@ -# Patterns to ignore when building packages. -# This supports shell glob matching, relative path matching, and -# negation (prefixed with !). Only one pattern per line. -.DS_Store -# Common VCS dirs -.git/ -.gitignore -.bzr/ -.bzrignore -.hg/ -.hgignore -.svn/ -# Common backup files -*.swp -*.bak -*.tmp -*~ -# Various IDEs -.project -.idea/ -*.tmproj -.vscode/ -# OWNERS file for Kubernetes -OWNERS -# helm-docs templates -*.gotmpl diff --git a/charts/piped/Chart.yaml b/charts/piped/Chart.yaml deleted file mode 100644 index 53449a8..0000000 --- a/charts/piped/Chart.yaml +++ /dev/null @@ -1,42 +0,0 @@ -apiVersion: v2 -appVersion: 1.0.0 -description: An alternative privacy-friendly YouTube frontend which is efficient by design. -name: piped -version: 1.0.0 -kubeVersion: ">=1.19.0-0" -keywords: - - YouTube - - piped -home: https://github.com/TeamPiped/Piped-Kubernetes -icon: https://${CHARTNAME}.org/icon -sources: - - https://github.com/TeamPiped/Piped-Kubernetes - - https://github.com/TeamPiped/Piped-Docker - - https://github.com/TeamPiped/Piped -maintainers: - - name: samip5 - url: https://github.com/samip5 -dependencies: - - name: common - repository: https://bjw-s.github.io/helm-charts/ - version: 0.2.2 - - name: common - alias: frontend - repository: https://bjw-s.github.io/helm-charts/ - version: 0.2.2 - - name: common - alias: backend - repository: https://bjw-s.github.io/helm-charts/ - version: 0.2.2 - - name: common - alias: ytproxy - repository: https://bjw-s.github.io/helm-charts/ - version: 0.2.2 - - name: common - alias: varnish - repository: https://bjw-s.github.io/helm-charts/ - version: 0.2.2 -annotations: - artifacthub.io/changes: | - - kind: added - description: Initial version diff --git a/charts/piped/README.md b/charts/piped/README.md deleted file mode 100644 index 5bb88d1..0000000 --- a/charts/piped/README.md +++ /dev/null @@ -1,111 +0,0 @@ -# ${CHARTNAME} - -![Version: 1.0.0](https://img.shields.io/badge/Version-1.0.0-informational?style=flat-square) ![AppVersion: 1.0.0](https://img.shields.io/badge/AppVersion-1.0.0-informational?style=flat-square) - -${CHARTNAME} helm package - -**This chart is not maintained by the upstream project and any issues with the chart should be raised [here](https://github.com/samipsolutions/helm-charts/issues/new/choose)** - -## Source Code - -* - -## Requirements - -Kubernetes: `>=1.16.0-0` - -## Dependencies - -| Repository | Name | Version | -|------------|------|---------| -| https://library-charts.k8s-at-home.com | common | 4.0.0 | - -## TL;DR - -```console -helm repo add k8s-at-home https://helm.samipsolutions.fi/ -helm repo update -helm install ${CHARTNAME} k8s-at-home/${CHARTNAME} -``` - -## Installing the Chart - -To install the chart with the release name `${CHARTNAME}` - -```console -helm install ${CHARTNAME} k8s-at-home/${CHARTNAME} -``` - -## Uninstalling the Chart - -To uninstall the `${CHARTNAME}` deployment - -```console -helm uninstall ${CHARTNAME} -``` - -The command removes all the Kubernetes components associated with the chart **including persistent volumes** and deletes the release. - -## Configuration - -Read through the [values.yaml](./values.yaml) file. It has several commented out suggested values. -Other values may be used from the [values.yaml](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common/values.yaml) from the [common library](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common). - -Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. - -```console -helm install ${CHARTNAME} \ - --set env.TZ="America/New York" \ - k8s-at-home/${CHARTNAME} -``` - -Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. - -```console -helm install ${CHARTNAME} k8s-at-home/${CHARTNAME} -f values.yaml -``` - -## Custom configuration - -N/A - -## Values - -**Important**: When deploying an application Helm chart you can add more values from our common library chart [here](https://github.com/k8s-at-home/library-charts/tree/main/charts/stable/common) - -| Key | Type | Default | Description | -|-----|------|---------|-------------| -| env | object | See below | environment variables. See more environment variables in the [${CHARTNAME} documentation](https://${CHARTNAME}.org/docs). | -| env.TZ | string | `"UTC"` | Set the container timezone | -| image.pullPolicy | string | `"IfNotPresent"` | image pull policy | -| image.repository | string | `"${CHARTNAME}/${CHARTNAME}"` | image repository | -| image.tag | string | chart.appVersion | image tag | -| ingress.main | object | See values.yaml | Enable and configure ingress settings for the chart under this key. | -| persistence | object | See values.yaml | Configure persistence settings for the chart under this key. | -| service | object | See values.yaml | Configures service settings for the chart. | - -## Changelog - -### Version 1.0.0 - -#### Added - -- Initial version - -#### Changed - -N/A - -#### Fixed - -N/A - -## Support - -- See the [Docs](https://docs.k8s-at-home.com/our-helm-charts/getting-started/) -- Open an [issue](https://github.com/samipsolutions/helm-charts/issues/new/choose) -- Ask a [question](https://github.com/k8s-at-home/organization/discussions) -- Join our [Discord](https://discord.gg/sTMX7Vh) community - ----------------------------------------------- -Autogenerated from chart metadata using [helm-docs v1.5.0](https://github.com/norwoodj/helm-docs/releases/v1.5.0) diff --git a/charts/piped/templates/NOTES.txt b/charts/piped/templates/NOTES.txt deleted file mode 100644 index 90f7b65..0000000 --- a/charts/piped/templates/NOTES.txt +++ /dev/null @@ -1 +0,0 @@ -{{- include "common.notes.defaultNotes" . -}} diff --git a/charts/piped/templates/common.yaml b/charts/piped/templates/common.yaml deleted file mode 100644 index 81a8414..0000000 --- a/charts/piped/templates/common.yaml +++ /dev/null @@ -1,11 +0,0 @@ -{{ $components := list "frontend" "backend" "ytproxy" "varnish" }} -{{- range $components -}} - {{- include "common.values.setup" (index $.Subcharts .) }} - {{- with (index $.Values .) }} - {{- with .image }} - {{- $_ := set . "tag" (default $.Chart.AppVersion .tag) -}} - {{- end -}} - {{- include "common.all" (index $.Subcharts .) }} - {{- end -}} -{{- end -}} - diff --git a/charts/piped/values.yaml b/charts/piped/values.yaml deleted file mode 100644 index 364c435..0000000 --- a/charts/piped/values.yaml +++ /dev/null @@ -1,77 +0,0 @@ -# -# IMPORTANT NOTE -# -# This chart inherits from bjw-s common lib chart. You can check the default values/options here: -# https://github.com/bjw-s/helm-charts/tree/main/charts/library/common -# - -image: - # -- image repository - repository: ${CHARTNAME}/${CHARTNAME} - # -- image tag - # @default -- chart.appVersion - tag: - # -- image pull policy - pullPolicy: IfNotPresent - -# -- environment variables. See more environment variables in the [${CHARTNAME} documentation](https://${CHARTNAME}.org/docs). -# @default -- See below -env: - # -- Set the container timezone - TZ: UTC - -# -- Configures service settings for the chart. -# @default -- See values.yaml -service: - main: - ports: - http: - port: 1880 - -ingress: - # -- Enable and configure ingress settings for the chart under this key. - # @default -- See values.yaml - main: - enabled: false - -# -- Configure persistence settings for the chart under this key. -# @default -- See values.yaml -persistence: {} - # data: - # enabled: false - # mountPath: /data - -frontend: - image: - repository: 1337kavin/piped-frontend - # -- image tag - # @default -- chart.appVersion - tag: - # -- image pull policy - pullPolicy: Always - -ytproxy: - image: - repository: 1337kavin/ytproxy - # -- image tag - # @default -- chart.appVersion - tag: - # -- image pull policy - pullPolicy: Always - -backend: - image: - repository: 1337kavin/piped - # -- image tag - # @default -- chart.appVersion - tag: - # -- image pull policy - pullPolicy: Always - service: - main: - ports: - http: - enabled: true - config: - PORT: 8080 - HTTP_WORKERS: 2