From 83b73d870a0419d7eec008ab20a390b4d95cf216 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20B=C3=A4hler?= Date: Wed, 10 Feb 2021 12:27:38 +0100 Subject: [PATCH] Helm 3.5.* Compatibility (#33) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Oliver Bähler --- charts/manifests/Chart.yaml | 10 +++- charts/manifests/README.md | 4 +- charts/manifests/README.md.gotmpl | 2 +- charts/manifests/templates/Quickstart.md | 16 +++--- charts/manifests/templates/README.md | 52 +++++++---------- .../manifests/templates/manifests/README.md | 30 +++++++++- .../manifests/templates/manifests/_bundle.tpl | 52 +++++++++-------- .../templates/manifests/_cronjob.tpl | 24 ++++---- .../templates/manifests/_daemonset.tpl | 22 ++++---- .../templates/manifests/_deployment.tpl | 24 ++++---- .../manifests/_horizontalPodAutoscaler.tpl | 30 +++++----- .../templates/manifests/_ingress.tpl | 50 ++++++++--------- charts/manifests/templates/manifests/_job.tpl | 16 +++--- .../templates/manifests/_networkPolicy.tpl | 56 +++++++++---------- .../manifests/_persistentVolumeClaim.tpl | 20 +++---- charts/manifests/templates/manifests/_pod.tpl | 18 +++--- .../manifests/_podDisruptionBudget.tpl | 8 +-- .../templates/manifests/_service.tpl | 52 +++++++++-------- .../templates/manifests/_serviceAccount.tpl | 38 ++++++------- .../templates/manifests/_serviceMonitor.tpl | 38 ++++++------- .../templates/manifests/_statefulset.tpl | 32 +++++------ .../manifests/templates/_bundleExtras.tpl | 14 ++--- .../manifests/templates/_containerTpl.tpl | 2 +- .../templates/manifests/templates/_jobTpl.tpl | 2 +- .../templates/manifests/templates/_podTpl.tpl | 2 +- .../templates/manifests/templates/_pvcTpl.tpl | 4 +- charts/manifests/templates/utils/_common.tpl | 13 ----- charts/manifests/templates/utils/_intern.tpl | 8 +++ .../templates/values/manifests/_service.yaml | 5 ++ 29 files changed, 322 insertions(+), 322 deletions(-) diff --git a/charts/manifests/Chart.yaml b/charts/manifests/Chart.yaml index 3e01ed06..1a17a9c4 100644 --- a/charts/manifests/Chart.yaml +++ b/charts/manifests/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: manifests description: "Bedag's Manifest chart. Library full of basic kubernetes manifests." type: library -version: 0.4.11 +version: 0.5.0 icon: "https://www.bedag.ch/wGlobal/wGlobal/layout/images/logo.svg" keywords: - Bedag @@ -19,7 +19,11 @@ dependencies: repository: "https://buttahtoast.github.io/helm-charts/" annotations: artifacthub.io/containsSecurityUpdates: "false" - artifacthub.io/prerelease: "true" + artifacthub.io/prerelease: "false" artifacthub.io/license: Apache-2.0 artifacthub.io/changes: | - - add newlines to prevent parse errors + - "[Added]: Support explicit chart.bundle template, for easier bundle declartion including documentation." + - "[Added]: Check were possible relevant YAML if it has any .Error field. Throw fail if detected." + - "[Changed]: Improved/Changed documentation with changed functionality/workflow." + - "[Fixed]: Handle empty Bundle Context causing Problems with Helm 3.5 (Function returned wrongly rendered YAML)" + - "[Removed]: Removed dedicated Values function for each manifest instead calling directly within the manifest" diff --git a/charts/manifests/README.md b/charts/manifests/README.md index ffeabb73..075949bd 100644 --- a/charts/manifests/README.md +++ b/charts/manifests/README.md @@ -1,6 +1,6 @@ # Manifests Library -![Version: 0.4.11](https://img.shields.io/badge/Version-0.4.11-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) +![Version: 0.5.0](https://img.shields.io/badge/Version-0.5.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) This library's purpose is to have more flexibility as chart author but at the same time have kubernetes manifests managed in a central library. This way you can avoid big surprises when Kubernetes has breaking changes in any of their APIs. Currently we support a base set of resources. Resources may be added as soon as we see or get a request that there's a need for it. This chart is still under development and testing, since it's rather complex. Feel free to use it. Our goal is to get it as reliable as possible. @@ -36,7 +36,7 @@ Major Changes to functions are documented with the version affected. **Before up | **Manifest** | **Chart Version** | **Change/Description** | **Commits/PRs** | | :----------- | :---------------- | :--------------------- | :-------------- | -||||| +| template/persistentvolumeclaim | `0.5.0` | Since all manifests/templates are lowercase, the persistentVolumeClaim template was also lowercased to have a cleaner library. The template is no longer callable via `bedag-lib.template.persistentVolumeClaim` but moved to `bedag-lib.template.persistentvolumeclaim`. | * [PR 33](https://github.com/bedag/helm-charts/pull/33) | ## Source Code diff --git a/charts/manifests/README.md.gotmpl b/charts/manifests/README.md.gotmpl index aa9bcc45..2a898bba 100644 --- a/charts/manifests/README.md.gotmpl +++ b/charts/manifests/README.md.gotmpl @@ -38,7 +38,7 @@ Major Changes to functions are documented with the version affected. **Before up | **Manifest** | **Chart Version** | **Change/Description** | **Commits/PRs** | | :----------- | :---------------- | :--------------------- | :-------------- | -||||| +| template/persistentvolumeclaim | `0.5.0` | Since all manifests/templates are lowercase, the persistentVolumeClaim template was also lowercased to have a cleaner library. The template is no longer callable via `bedag-lib.template.persistentVolumeClaim` but moved to `bedag-lib.template.persistentvolumeclaim`. | * [PR 33](https://github.com/bedag/helm-charts/pull/33) | {{/* diff --git a/charts/manifests/templates/Quickstart.md b/charts/manifests/templates/Quickstart.md index 7c9d581d..1e1f4791 100644 --- a/charts/manifests/templates/Quickstart.md +++ b/charts/manifests/templates/Quickstart.md @@ -41,8 +41,8 @@ It's difficult to quickstart with this project unless you already have a deeper Now it's time to get started with actually using the Manifests library. Let's create a new file `new-charts/templates/bundle.yaml` and add the basic Bundle structure ([Read More on Bundles](./manifests/README.md#bundles)). Let's also add our first bundle resource of type `statefulset` ``` - {{- include "bedag-lib.manifest.bundle" (dict "bundle" (fromYaml (include "new-chart.bundle" $)) "context" $) | nindent 0 }} - {{- define "new-chart.bundle" -}} + {{- include "bedag-lib.manifest.bundle" $ | nindent 0 }} + {{- define "chart.bundle" -}} resources: - type: "statefulset" values: {{ toYaml $.Values.frontend | nindent 6 }} @@ -75,8 +75,8 @@ It's difficult to quickstart with this project unless you already have a deeper Now it's your turn. Implement the logic you need on manifest basis and add many more manifests. We are going to add a service with you, then it's up to you. The `new-charts/templates/bundle.yaml` looks now like this: ``` - {{- include "bedag-lib.manifest.bundle" (dict "bundle" (fromYaml (include "new-chart.bundle" $)) "context" $) | nindent 0 }} - {{- define "new-chart.bundle" -}} + {{- include "bedag-lib.manifest.bundle" $ | nindent 0 }} + {{- define "chart.bundle" -}} resources: - type: "statefulset" values: {{ toYaml $.Values.frontend | nindent 6 }} @@ -105,8 +105,8 @@ It's difficult to quickstart with this project unless you already have a deeper 2. Just overwrite what's necessary. We want to give each end user of our charts as much freedom as possible. You should always consider a user's inputs. This is mainly required for slice inputs, since maps are merged. With slices, entire lists are overwritten. ``` - {{- include "bedag-lib.manifest.bundle" (dict "bundle" (fromYaml (include "new-chart.bundle" $)) "context" $) | nindent 0 }} - {{- define "new-chart.bundle" -}} + {{- include "bedag-lib.manifest.bundle" $ | nindent 0 }} + {{- define "chart.bundle" -}} resources: - type: "statefulset" values: {{ toYaml $.Values.frontend | nindent 6 }} @@ -130,7 +130,7 @@ It's difficult to quickstart with this project unless you already have a deeper 3. ExtraResources are always welcome :) ``` - {{- define "new-chart.bundle" -}} + {{- define "chart.bundle" -}} resources: {{- if $.Values.extraResources }} {{- toYaml $.Values.extraResources | nindent 2 }} @@ -147,5 +147,5 @@ It's difficult to quickstart with this project unless you already have a deeper 4. Sometimes you might encounter errors. Most of the time the source of errors will be a malformed bundle YAML. To check how your YAML looks, you can do something like this and then `helm template` it: ``` - test: | {{- include "bedag-lib.manifest.bundle" (dict "bundle" (fromYaml (include "new-chart.bundle" $)) "context" $) | nindent 2 }} + test: | {{- include "bedag-lib.manifest.bundle" $ | nindent 2 }} ``` diff --git a/charts/manifests/templates/README.md b/charts/manifests/templates/README.md index 88d73b4c..e093f30f 100644 --- a/charts/manifests/templates/README.md +++ b/charts/manifests/templates/README.md @@ -122,22 +122,6 @@ First i am creating the main file (do whatever structure you like, just make sur **templates/manifests/_serviceMonitor.yaml** ``` -{{/* - We need a dedicated resource for the values for this manifests. This is mainly to ensure - to functionality of the manifest within a bundle. If you want to implement it the same way as - shown is up to. The function should just return the default values for the manifest, overwritten - by the .values field and superoverwritten by the .overwrites field. - Make Sure: - * Has **bedag-lib.manifest** as prefix - * Manifest is written in all lower case (**servicemonitor**) - * Has **values** as suffix - -*/}} -{{- define "bedag-lib.manifest.servicemonitor.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.mergedValues" (dict "type" "serviceMonitor" "root" .)) "context" .context) -}} -{{- end }} - - {{/* Here's the heart of our manifest. Basically here you design what's going to be returned as manifest. Make Sure: @@ -147,38 +131,40 @@ First i am creating the main file (do whatever structure you like, just make sur {{- define "bedag-lib.manifest.servicemonitor" -}} {{- if .context -}} {{- $context := .context -}} - {{- $serviceMonitor := (fromYaml (include "bedag-lib.manifest.servicemonitor.values" .)) -}} - {{- if $serviceMonitor.enabled -}} - {{- if $serviceMonitor.apiVersion -}} + {{- $serviceMonitor := mergeOverwrite (fromYaml (include "bedag-lib.values.servicemonitor" $)).serviceMonitor (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $serviceMonitor) }} + {{- if $serviceMonitor.enabled -}} + {{- if $serviceMonitor.apiVersion -}} apiVersion: {{ $serviceMonitor.apiVersion }} - {{- else -}} + {{- else -}} apiVersion: monitoring.coreos.com/v1 - {{- end }} + {{- end }} kind: ServiceMonitor metadata: name: {{ include "bedag-lib.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $serviceMonitor.labels "context" $context)| nindent 4 }} - {{- if $serviceMonitor.namespace }} + {{- if $serviceMonitor.namespace }} namespace: {{ $serviceMonitor.namespace }} - {{- end }} + {{- end }} spec: - {{- if $serviceMonitor.additionalFields }} - {{- toYaml $serviceMonitor.additionalFields | nindent 2 }} - {{- end }} + {{- if $serviceMonitor.additionalFields }} + {{- toYaml $serviceMonitor.additionalFields | nindent 2 }} + {{- end }} selector: matchLabels: endpoints: {{- include "lib.utils.strings.template" (dict "value" $serviceMonitor.endpoints "context" $context) | nindent 4 }} namespaceSelector: matchNames: - {{- if $serviceMonitor.namespaceSelector }} - {{- if kindIs "slice" $serviceMonitor.namespaceSelector }} - {{- toYaml $serviceMonitor.namespaceSelector | nindent 6 }} - {{- else }} + {{- if $serviceMonitor.namespaceSelector }} + {{- if kindIs "slice" $serviceMonitor.namespaceSelector }} + {{- toYaml $serviceMonitor.namespaceSelector | nindent 6 }} + {{- else }} - {{ $serviceMonitor.namespaceSelector }} - {{- end }} - {{- else }} + {{- end }} + {{- else }} - {{ $context.Release.Namespace }} - {{- end }} + {{- end }} + {{- end }} {{- end }} {{- else }} {{- fail "Template requires '.context' as arguments" }} diff --git a/charts/manifests/templates/manifests/README.md b/charts/manifests/templates/manifests/README.md index 82c75a83..895a9cc1 100644 --- a/charts/manifests/templates/manifests/README.md +++ b/charts/manifests/templates/manifests/README.md @@ -45,11 +45,37 @@ We recommend creating a dedicated template within your chart just for the bundle {{/* Bundle Inclusion */}} -{{- include "bedag-lib.manifest.bundle" (dict "bundle" (fromYaml (include "chart.bundle" $)) "context" $) | nindent 0 }} +{{- include "bedag-lib.manifest.bundle" (dict "bundle" (fromYaml (include "custom.bundle" $)) "context" $) | nindent 0 }} {{/* Bundle Definition */}} +{{- define "custom.bundle" -}} +name: "frontend" +common: + commonLabels: + "custom-chart-label": "1" +resources: + {{- if .Values.extraResources }} + {{- toYaml .Values.extraResources | nindent 2 }} + {{- end }} + - type: "statefulset" + values: {{ toYaml .Values.statefulset | nindent 6 }} + overwrites: + {{- if .Release.IsInstall }} + replicaCount: 1 + {{- end }} + - type: "service" + name: "headless" + values {{ toYaml .Values.service | nindent 6 }} +{{- end }} +``` +### Explicit Bundle + +If you have a single bundle, you can just declare the bundle with `chart.bundle` to keep complexity lower. Like this: + +``` +{{- include "bedag-lib.manifest.bundle" $ | nindent 0 }} {{- define "chart.bundle" -}} name: "frontend" common: @@ -71,6 +97,8 @@ resources: {{- end }} ``` +Recommended if you just need one bundle in your chart. + ## Resource Types All manifests below are supported as **type**. Refer to the examples below to see how it is done. There's only one extra resource available with bundles. diff --git a/charts/manifests/templates/manifests/_bundle.tpl b/charts/manifests/templates/manifests/_bundle.tpl index 84f62aa8..83ab9ff7 100644 --- a/charts/manifests/templates/manifests/_bundle.tpl +++ b/charts/manifests/templates/manifests/_bundle.tpl @@ -15,34 +15,40 @@ See the License for the specific language governing permissions and limitations under the License. */}} - {{- define "bedag-lib.manifest.bundle" -}} {{- $manifestPath := "bedag-lib.manifest." -}} - {{- if and .context (kindIs "map" .context) .bundle (kindIs "map" .bundle) -}} - {{- $context := mergeOverwrite .context (default dict (fromYaml (include "lib.utils.dicts.parentAppend" .bundle.common))) -}} - {{- if $.bundle.name }} - {{- $_ := set $context "bundlename" $.bundle.name -}} - {{- end }} - {{- $_ := set $context "Bundle" $.bundle.resources -}} - {{- if .bundle.resources -}} - {{- range .bundle.resources -}} - {{- $type := required "Missing required field '.type' for resource in bundle" .type | lower }} - {{- $manifest := (cat $manifestPath $type | nospace) -}} - {{- if and (eq $type "raw") .manifest }} + {{- $bundle := (default dict .bundle) }} + {{- $i_context := (default . .context) }} + {{- if not $bundle }} + {{- $bundle = (fromYaml (include "chart.bundle" $i_context)) }} + {{- end -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" .) }} + {{- if and (kindIs "map" $i_context) (include "bedag-lib.utils.intern.noYamlError" $i_context) (kindIs "map" $bundle) (include "bedag-lib.utils.intern.noYamlError" $bundle) -}} + {{- $context := mergeOverwrite $i_context (dict "Values" (default dict $bundle.common)) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $context) }} + {{- if $bundle.name }} + {{- $_ := set $context "bundlename" $bundle.name -}} + {{- end }} + {{- $_ := set $context "Bundle" $bundle.resources -}} + {{- if $bundle.resources -}} + {{- range $bundle.resources -}} + {{- $type := required "Missing required field '.type' for resource in bundle" .type | lower }} + {{- $manifest := (cat $manifestPath $type | nospace) -}} + {{- if and (eq $type "raw") .manifest }} ---{{- include "lib.utils.strings.template" (dict "value" .manifest "context" $context) | nindent 0 }} - {{- else }} - {{- $v_params := set . "context" $context }} - {{- $values := (fromYaml (include (cat $manifest ".values" | nospace) $v_params)) }} - {{- $parameters := (dict "type" $type "values" $values "name" (default "" .name) "fullname" (default "" .fullname) "context" $context) }} - {{- $resource := include $manifest $parameters }} - {{- if $resource }} + {{- else }} + {{- $parameters := (dict "name" (default "" .name) "fullname" (default "" .fullname) "values" (default dict .values) "overwrites" (default dict .overwrites) "context" $context) }} + {{- $resource := include $manifest $parameters }} + {{- if $resource }} ---{{- $resource | nindent 0 }} - {{- include "bedag-lib.template.bundleExtras" $parameters | nindent 0 -}} + {{- include "bedag-lib.template.bundleExtras" $parameters | nindent 0 -}} + {{- end -}} + {{- end -}} {{- end -}} - {{- end -}} - {{- end -}} - {{- else }} - {{- fail "Missing Keys or Wrong YAML structure!" }} + {{- else }} + {{- fail "Missing Keys or Wrong YAML structure!" }} + {{- end }} + {{- end }} {{- end }} {{- end -}} {{- end -}} diff --git a/charts/manifests/templates/manifests/_cronjob.tpl b/charts/manifests/templates/manifests/_cronjob.tpl index f9e5a882..e4628344 100644 --- a/charts/manifests/templates/manifests/_cronjob.tpl +++ b/charts/manifests/templates/manifests/_cronjob.tpl @@ -15,30 +15,27 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.cronjob.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "cronjob" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.cronjob" -}} {{- if .context }} {{- $context := .context -}} - {{- $cronjob := (fromYaml (include "bedag-lib.manifest.cronjob.values" .)) -}} - {{- if $cronjob.enabled }} + {{- $cronjob := mergeOverwrite (fromYaml (include "bedag-lib.values.cronjob" $)).cronjob (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $cronjob) }} + {{- if $cronjob.enabled }} kind: CronJob - {{- if $cronjob.apiVersion }} + {{- if $cronjob.apiVersion }} apiVersion: {{ $cronjob.apiVersion }} - {{- else }} + {{- else }} apiVersion: batch/v1beta1 - {{- end }} + {{- end }} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $cronjob.labels "context" $context)| nindent 4 }} - {{- if $cronjob.annotations }} + {{- if $cronjob.annotations }} annotations: - {{- range $anno, $val := $cronjob.annotations }} - {{- $anno | nindent 4 }}: {{ $val | quote }} + {{- range $anno, $val := $cronjob.annotations }} + {{- $anno | nindent 4 }}: {{ $val | quote }} + {{- end }} {{- end }} - {{- end }} spec: concurrencyPolicy: {{ $cronjob.concurrencyPolicy }} failedJobsHistoryLimit: {{ $cronjob.failedJobsHistoryLimit }} @@ -47,6 +44,7 @@ spec: successfulJobsHistoryLimit: {{ $cronjob.successfulJobsHistoryLimit }} suspend: {{ $cronjob.suspend }} jobTemplate: {{- include "bedag-lib.template.job" (set . "job" $cronjob) | nindent 4 }} + {{- end }} {{- end }} {{- end }} {{- end -}} diff --git a/charts/manifests/templates/manifests/_daemonset.tpl b/charts/manifests/templates/manifests/_daemonset.tpl index 0a2ae42b..a9e13ff6 100644 --- a/charts/manifests/templates/manifests/_daemonset.tpl +++ b/charts/manifests/templates/manifests/_daemonset.tpl @@ -15,20 +15,17 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.daemonset.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "daemonset" "root" .)) "context" .context) }} -{{- end }} - {{- define "bedag-lib.manifest.daemonset" -}} {{- if .context -}} {{- $context := .context -}} - {{- $daemonset := (fromYaml (include "bedag-lib.manifest.daemonset.values" .)) -}} + {{- $daemonset := mergeOverwrite (fromYaml (include "bedag-lib.values.daemonset" $)).daemonset (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $daemonset) }} kind: DaemonSet - {{- if $daemonset.apiVersion }} + {{- if $daemonset.apiVersion }} apiVersion: {{ $daemonset.apiVersion }} - {{- else }} + {{- else }} apiVersion: apps/v1 - {{- end }} + {{- end }} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $daemonset.labels "context" $context)| nindent 4 }} @@ -39,13 +36,14 @@ spec: matchLabels: {{- include "lib.utils.strings.template" (dict "value" (default (include "lib.utils.common.selectorLabels" $context) $daemonset.selectorLabels) "context" $context) | nindent 6 }} template: {{- include "bedag-lib.template.pod" (set . "pod" $daemonset) | nindent 4 }} updateStrategy: - {{- $updateStrategy := (default "RollingUpdate" $daemonset.updateStrategy) }} + {{- $updateStrategy := (default "RollingUpdate" $daemonset.updateStrategy) }} type: {{ $updateStrategy | quote }} - {{- if (eq "OnDelete" $updateStrategy) }} + {{- if (eq "OnDelete" $updateStrategy) }} rollingUpdate: null - {{- else if $daemonset.rollingUpdatemaxUnavailable }} + {{- else if $daemonset.rollingUpdatemaxUnavailable }} rollingUpdate: maxUnavailable: {{ $daemonset.rollingUpdatemaxUnavailable }} + {{- end }} {{- end }} -{{- end -}} + {{- end -}} {{- end -}} diff --git a/charts/manifests/templates/manifests/_deployment.tpl b/charts/manifests/templates/manifests/_deployment.tpl index 616fbecd..7e64ad08 100644 --- a/charts/manifests/templates/manifests/_deployment.tpl +++ b/charts/manifests/templates/manifests/_deployment.tpl @@ -15,33 +15,31 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.deployment.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "deployment" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.deployment" -}} {{- if .context -}} {{- $context := .context -}} - {{- $deployment := (fromYaml (include "bedag-lib.manifest.deployment.values" .)) -}} + {{- $deployment := mergeOverwrite (fromYaml (include "bedag-lib.values.deployment" $)).deployment (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $deployment) }} kind: Deployment - {{- if $deployment.apiVersion }} + {{- if $deployment.apiVersion }} apiVersion: {{ $deployment.apiVersion }} - {{- else }} + {{- else }} apiVersion: apps/v1 - {{- end }} + {{- end }} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $deployment.labels "context" $context)| nindent 4 }} spec: - {{- with $deployment.strategy }} + {{- with $deployment.strategy }} strategy: {{ toYaml . | nindent 4 }} - {{- end }} + {{- end }} replicas: {{ default "1" $deployment.replicaCount }} selector: matchLabels: {{- include "lib.utils.strings.template" (dict "value" (default (include "lib.utils.common.selectorLabels" $context) $deployment.selectorLabels) "context" $context) | nindent 6 }} - {{- if $deployment.deploymentExtras }} - {{- toYaml $deployment.deploymentExtras | nindent 2 }} - {{- end }} + {{- if $deployment.deploymentExtras }} + {{- toYaml $deployment.deploymentExtras | nindent 2 }} + {{- end }} template: {{- include "bedag-lib.template.pod" (set . "pod" $deployment) | nindent 4 }} + {{- end }} {{- end }} {{- end -}} diff --git a/charts/manifests/templates/manifests/_horizontalPodAutoscaler.tpl b/charts/manifests/templates/manifests/_horizontalPodAutoscaler.tpl index 40f0ce0a..98507ef4 100644 --- a/charts/manifests/templates/manifests/_horizontalPodAutoscaler.tpl +++ b/charts/manifests/templates/manifests/_horizontalPodAutoscaler.tpl @@ -22,37 +22,38 @@ limitations under the License. {{- define "bedag-lib.manifest.horizontalpodautoscaler" -}} {{- if .context }} {{- $context := .context -}} - {{- $hpa := (fromYaml (include "bedag-lib.manifest.horizontalpodautoscaler.values" .)) -}} - {{- if and $hpa.enabled (or $hpa.targetCPUUtilizationPercentage $hpa.targetMemoryUtilizationPercentage $hpa.metrics) -}} + {{- $hpa := mergeOverwrite (fromYaml (include "bedag-lib.values.horizontalpodautoscaler" $)).autoscaling (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $hpa) }} + {{- if and $hpa.enabled (or $hpa.targetCPUUtilizationPercentage $hpa.targetMemoryUtilizationPercentage $hpa.metrics) -}} kind: HorizontalPodAutoscaler - {{- if $hpa.apiVersion -}} + {{- if $hpa.apiVersion -}} apiVersion: {{ $hpa.apiVersion }} - {{- else }} + {{- else }} apiVersion: autoscaling/v2beta2 - {{- end }} + {{- end }} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $hpa.labels "context" $context) | nindent 4 }} spec: - {{- if and $hpa.behavior (kindIs "map" $hpa.behavior) }} + {{- if and $hpa.behavior (kindIs "map" $hpa.behavior) }} behavior: {{ toYaml $hpa.behavior | nindent 4 }} - {{- end }} + {{- end }} metrics: - {{- if $hpa.targetCPUUtilizationPercentage }} + {{- if $hpa.targetCPUUtilizationPercentage }} - type: Resource resource: name: cpu targetAverageUtilization: {{ $hpa.targetCPUUtilizationPercentage }} - {{- end }} - {{- if $hpa.targetMemoryUtilizationPercentage }} + {{- end }} + {{- if $hpa.targetMemoryUtilizationPercentage }} - type: Resource resource: name: memory targetAverageUtilization: {{ $hpa.targetMemoryUtilizationPercentage }} - {{- end }} - {{- if and $hpa.metrics (kindIs "slice" $hpa.metrics) }} - {{- toYaml $hpa.metrics | nindent 4}} - {{- end }} + {{- end }} + {{- if and $hpa.metrics (kindIs "slice" $hpa.metrics) }} + {{- toYaml $hpa.metrics | nindent 4}} + {{- end }} scaleTargetRef: {{- if $hpa.scaleTargetRef }} {{- toYaml $hpa.scaleTargetRef | nindent 4 }} @@ -65,6 +66,7 @@ spec: minReplicas: {{ $hpa.minReplicas }} {{- end }} maxReplicas: {{ $hpa.maxReplicas }} + {{- end }} {{- end }} {{- else }} {{- fail "Template requires '.context' as arguments" }} diff --git a/charts/manifests/templates/manifests/_ingress.tpl b/charts/manifests/templates/manifests/_ingress.tpl index e4b2048f..6b5b50e7 100644 --- a/charts/manifests/templates/manifests/_ingress.tpl +++ b/charts/manifests/templates/manifests/_ingress.tpl @@ -15,55 +15,52 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.ingress.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "ingress" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.ingress" -}} {{- if .context -}} {{- $context := .context -}} - {{- $ingress := (fromYaml (include "bedag-lib.manifest.ingress.values" .)) -}} - {{- if and $ingress.enabled $ingress.hosts -}} + {{- $ingress := mergeOverwrite (fromYaml (include "bedag-lib.values.ingress" $)).ingress (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $ingress) }} + {{- if and $ingress.enabled $ingress.hosts -}} kind: Ingress - {{- if $ingress.apiVersion -}} + {{- if $ingress.apiVersion -}} apiVersion: {{ $ingress.apiVersion }} - {{- else -}} - {{- if semverCompare ">=1.19-0" (include "lib.utils.common.capabilities" $context) }} + {{- else -}} + {{- if semverCompare ">=1.19-0" (include "lib.utils.common.capabilities" $context) }} apiVersion: networking.k8s.io/v1 - {{- else if semverCompare ">=1.14-0" (include "lib.utils.common.capabilities" $context) }} + {{- else if semverCompare ">=1.14-0" (include "lib.utils.common.capabilities" $context) }} apiVersion: networking.k8s.io/v1beta1 - {{- else }} + {{- else }} apiVersion: extensions/v1beta1 + {{- end }} {{- end }} - {{- end }} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $ingress.labels "context" $context)| nindent 4 }} - {{- if $ingress.annotations }} + {{- if $ingress.annotations }} annotations: - {{- range $anno, $val := $ingress.annotations }} - {{- $anno | nindent 4 }}: {{ $val | quote }} + {{- range $anno, $val := $ingress.annotations }} + {{- $anno | nindent 4 }}: {{ $val | quote }} + {{- end }} {{- end }} - {{- end }} spec: - {{- if and $ingress.backend (kindIs "map" $ingress.backend) }} + {{- if and $ingress.backend (kindIs "map" $ingress.backend) }} backend: {{- toYaml $ingress.backend | nindent 4 }} - {{- end }} - {{- if semverCompare ">=1.18-0" (include "lib.utils.common.capabilities" $context) -}} - {{- if and $ingress.ingressClass (kindIs "string" $ingress.ingressClass) }} + {{- end }} + {{- if semverCompare ">=1.18-0" (include "lib.utils.common.capabilities" $context) -}} + {{- if and $ingress.ingressClass (kindIs "string" $ingress.ingressClass) }} ingressClassName: {{ $ingress.ingressClass }} + {{- end }} {{- end }} - {{- end }} - {{- if $ingress.tls }} + {{- if $ingress.tls }} tls: - {{- range $ingress.tls }} + {{- range $ingress.tls }} - hosts: - {{- range .hosts }} + {{- range .hosts }} - {{ . | quote }} - {{- end }} + {{- end }} secretName: {{ default "" .secretName }} + {{- end }} {{- end }} - {{- end }} rules: {{- range $ingress.hosts }} - host: {{ required "Field .host required for ingress manifest" .host | quote }} @@ -107,6 +104,7 @@ spec: {{- end }} {{- end }} {{- end }} + {{- end }} {{- end }} {{- else }} {{- fail "Template requires '.context' as argument" }} diff --git a/charts/manifests/templates/manifests/_job.tpl b/charts/manifests/templates/manifests/_job.tpl index 42f23966..acea0b6e 100644 --- a/charts/manifests/templates/manifests/_job.tpl +++ b/charts/manifests/templates/manifests/_job.tpl @@ -15,22 +15,20 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.job.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "job" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.job" -}} {{- if .context -}} {{- $context := .context -}} - {{- $job := (fromYaml (include "bedag-lib.manifest.job.values" .)) -}} - {{- if $job.enabled }} + {{- $job := mergeOverwrite (fromYaml (include "bedag-lib.values.job" $)).job (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $job) }} + {{- if $job.enabled }} kind: Job - {{- if $job.apiVersion }} + {{- if $job.apiVersion }} apiVersion: {{ $job.apiVersion }} - {{- else }} + {{- else }} apiVersion: batch/v1 - {{- end }} + {{- end }} {{- include "bedag-lib.template.job" (set . "job" $job) | nindent 0 }} + {{- end }} {{- end }} {{- end }} {{- end -}} diff --git a/charts/manifests/templates/manifests/_networkPolicy.tpl b/charts/manifests/templates/manifests/_networkPolicy.tpl index af7fb0a2..e9eb48ec 100644 --- a/charts/manifests/templates/manifests/_networkPolicy.tpl +++ b/charts/manifests/templates/manifests/_networkPolicy.tpl @@ -15,65 +15,63 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.networkpolicy.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "networkPolicy" "root" .)) "context" .context) }} -{{- end }} - {{- define "bedag-lib.manifest.networkpolicy" -}} {{- if .context -}} {{- $context := .context -}} - {{- $networkPolicy := (fromYaml (include "bedag-lib.manifest.networkpolicy.values" .)) -}} - {{- if $networkPolicy.enabled }} + {{- $networkPolicy := mergeOverwrite (fromYaml (include "bedag-lib.values.networkpolicy" $)).networkPolicy (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $networkPolicy) }} + {{- if $networkPolicy.enabled }} kind: NetworkPolicy - {{- if $networkPolicy.apiVersion }} + {{- if $networkPolicy.apiVersion }} apiVersion: {{ $networkPolicy.apiVersion }} - {{- else }} + {{- else }} apiVersion: networking.k8s.io/v1 - {{- end }} + {{- end }} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $networkPolicy.labels "context" $context)| nindent 4 }} spec: podSelector: matchLabels: {{- include "lib.utils.strings.template" (dict "value" (default (include "lib.utils.common.selectorLabels" $context) $networkPolicy.selector) "context" $context) | nindent 6 }} - {{- if or $networkPolicy.ingress $networkPolicy.egress}} + {{- if or $networkPolicy.ingress $networkPolicy.egress}} policyTypes: - {{- if and $networkPolicy.ingress (kindIs "slice" $networkPolicy.ingress) }} + {{- if and $networkPolicy.ingress (kindIs "slice" $networkPolicy.ingress) }} - Ingress - {{- end }} - {{- if and $networkPolicy.egress (kindIs "slice" $networkPolicy.egress) }} + {{- end }} + {{- if and $networkPolicy.egress (kindIs "slice" $networkPolicy.egress) }} - Egress + {{- end }} {{- end }} - {{- end }} - {{- if and $networkPolicy.ingress (kindIs "slice" $networkPolicy.ingress) }} + {{- if and $networkPolicy.ingress (kindIs "slice" $networkPolicy.ingress) }} ingress: - {{- range $networkPolicy.ingress }} + {{- range $networkPolicy.ingress }} - from: - {{- if .ipBlock }} + {{- if .ipBlock }} - ipBlock: {{- toYaml .ipBlock | nindent 10 }} - {{- end }} - {{- if .namespaceSelector }} + {{- end }} + {{- if .namespaceSelector }} - namespaceSelector: matchLabels: {{- include "lib.utils.strings.template" (dict "value" .namespaceSelector "context" $context) | nindent 12 }} - {{- end }} - {{- if .podSelector }} + {{- end }} + {{- if .podSelector }} - podSelector: matchLabels: {{- include "lib.utils.strings.template" (dict "value" .podSelector "context" $context) | nindent 12 }} - {{- end }} - {{- if .ports }} + {{- end }} + {{- if .ports }} ports: {{- toYaml .ports | nindent 8 }} + {{- end }} {{- end }} {{- end }} - {{- end }} - {{- if and $networkPolicy.egress (kindIs "slice" $networkPolicy.egress) }} + {{- if and $networkPolicy.egress (kindIs "slice" $networkPolicy.egress) }} egress: - {{- range $networkPolicy.egress }} + {{- range $networkPolicy.egress }} - to: - {{- if .ipBlock }} + {{- if .ipBlock }} - ipBlock: {{- toYaml .ipBlock | nindent 10 }} - {{- end }} - {{- if .ports }} + {{- end }} + {{- if .ports }} ports: {{- toYaml .ports | nindent 8 }} + {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/charts/manifests/templates/manifests/_persistentVolumeClaim.tpl b/charts/manifests/templates/manifests/_persistentVolumeClaim.tpl index 7b2e4c8a..997a6ff5 100644 --- a/charts/manifests/templates/manifests/_persistentVolumeClaim.tpl +++ b/charts/manifests/templates/manifests/_persistentVolumeClaim.tpl @@ -15,24 +15,22 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.persistentvolumeclaim.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "persistentvolumeclaim" "key" "pvc" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.persistentvolumeclaim" -}} {{- if .context -}} {{- $context := .context -}} - {{- $pvc := (fromYaml (include "bedag-lib.manifest.persistentvolumeclaim.values" .)) -}} - {{- if $pvc.enabled -}} + {{- $pvc := mergeOverwrite (fromYaml (include "bedag-lib.values.persistentvolumeclaim" $)).pvc (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $pvc) }} + {{- if $pvc.enabled -}} kind: PersistentVolumeClaim - {{- if $pvc.apiVersion }} + {{- if $pvc.apiVersion }} apiVersion: {{ $pvc.apiVersion }} - {{- else }} + {{- else }} apiVersion: v1 + {{- end }} + {{- include "bedag-lib.template.persistentvolumeclaim" (set . "pvc" $pvc) | nindent 0 }} {{- end }} - {{- include "bedag-lib.template.persistentVolumeClaim" (set . "pvc" $pvc) | nindent 0 }} + {{- else }} + {{- fail "Template requires '.context' as arguments" }} {{- end }} - {{- else }} - {{- fail "Template requires '.context' as arguments" }} {{- end }} {{- end }} diff --git a/charts/manifests/templates/manifests/_pod.tpl b/charts/manifests/templates/manifests/_pod.tpl index db8bda14..45b305e0 100644 --- a/charts/manifests/templates/manifests/_pod.tpl +++ b/charts/manifests/templates/manifests/_pod.tpl @@ -15,23 +15,21 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.pod.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "pod" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.pod" -}} {{- if .context -}} {{- $context := .context -}} - {{- $pod := (fromYaml (include "bedag-lib.manifest.pod.values" .)) -}} + {{- $pod := mergeOverwrite (fromYaml (include "bedag-lib.values.pod" $)).pod (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $pod) }} kind: Pod - {{- if $pod.apiVersion }} + {{- if $pod.apiVersion }} apiVersion: {{ $pod.apiVersion }} - {{- else }} + {{- else }} apiVersion: v1 + {{- end }} + {{- $podTpl := fromYaml (include "bedag-lib.template.pod" (set . "pod" $pod)) }} + {{- $_ := set $podTpl.metadata "name" (include "bedag-lib.utils.common.fullname" .) }} + {{- toYaml $podTpl | nindent 0 }} {{- end }} - {{- $podTpl := fromYaml (include "bedag-lib.template.pod" (set . "pod" $pod)) }} - {{- $_ := set $podTpl.metadata "name" (include "bedag-lib.utils.common.fullname" .) }} - {{- toYaml $podTpl | nindent 0 }} {{- else }} {{- fail "Template requires '.context' as arguments" }} {{- end }} diff --git a/charts/manifests/templates/manifests/_podDisruptionBudget.tpl b/charts/manifests/templates/manifests/_podDisruptionBudget.tpl index fcd1083a..806790b2 100644 --- a/charts/manifests/templates/manifests/_podDisruptionBudget.tpl +++ b/charts/manifests/templates/manifests/_podDisruptionBudget.tpl @@ -15,14 +15,11 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.poddisruptionbudget.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "podDisruptionBudget" "key" "pdb" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.poddisruptionbudget" -}} {{- if .context -}} {{- $context := .context -}} - {{- $pdb := (fromYaml (include "bedag-lib.manifest.poddisruptionbudget.values" .)) -}} + {{- $pdb := mergeOverwrite (fromYaml (include "bedag-lib.values.poddisruptionbudget" $)).pdb (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $pdb) }} {{- if $pdb.enabled -}} kind: PodDisruptionBudget {{- if $pdb.apiVersion }} @@ -46,6 +43,7 @@ spec: {{- end }} selector: matchLabels: {{- include "lib.utils.strings.template" (dict "value" (default (include "lib.utils.common.selectorLabels" $context) $pdb.selectorLabels) "context" $context) | nindent 6 }} + {{- end }} {{- end }} {{- end }} {{- end -}} diff --git a/charts/manifests/templates/manifests/_service.tpl b/charts/manifests/templates/manifests/_service.tpl index fb774e22..4d2a627c 100644 --- a/charts/manifests/templates/manifests/_service.tpl +++ b/charts/manifests/templates/manifests/_service.tpl @@ -15,58 +15,56 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.service.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "service" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.service" -}} {{- if .context -}} {{- $context := .context -}} - {{- $svc := (fromYaml (include "bedag-lib.manifest.service.values" .)) -}} - {{- if $svc.enabled -}} + {{- $svc := mergeOverwrite (fromYaml (include "bedag-lib.values.service" $)).service (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $svc) }} + {{- if $svc.enabled -}} kind: Service - {{- if $svc.apiVersion }} + {{- if $svc.apiVersion }} apiVersion: {{ $svc.apiVersion }} - {{- else }} + {{- else }} apiVersion: v1 - {{- end }} + {{- end }} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $svc.labels "context" $context)| nindent 4 }} - {{- if $svc.annotations }} + {{- if $svc.annotations }} annotations: - {{- range $anno, $val := $svc.annotations }} - {{- $anno | nindent 4 }}: {{ $val | quote }} + {{- range $anno, $val := $svc.annotations }} + {{- $anno | nindent 4 }}: {{ $val | quote }} + {{- end }} {{- end }} - {{- end }} spec: - {{- $type := (default "ClusterIP" $svc.type) }} + {{- $type := (default "ClusterIP" $svc.type) }} type: {{ $type }} - {{- if eq $type "LoadBalancer" }} - {{- if $svc.loadBalancerIP }} + {{- if eq $type "LoadBalancer" }} + {{- if $svc.loadBalancerIP }} loadBalancerIP: {{ $svc.loadBalancerIP }} - {{- end }} - {{- if $svc.loadBalancerSourceRanges }} + {{- end }} + {{- if $svc.loadBalancerSourceRanges }} loadBalancerSourceRanges: {{- toYaml $svc.loadBalancerSourceRanges | nindent 4 }} + {{- end }} {{- end }} - {{- end }} - {{- if and (eq $type "ClusterIP") $svc.clusterIP }} + {{- if and (eq $type "ClusterIP") $svc.clusterIP }} clusterIP: {{ $svc.clusterIP }} - {{- end }} + {{- end }} ports: - name: {{ include "lib.utils.strings.toDns1123" (default "http" $svc.portName) }} port: {{ default 80 $svc.port }} protocol: {{ default "TCP" $svc.protocol }} targetPort: {{ include "lib.utils.strings.toDns1123" (default "http" $svc.targetPort) }} - {{- if and (or (eq $type "NodePort") (eq $type "LoadBalancer")) (not (empty $svc.nodePort)) }} + {{- if and (or (eq $type "NodePort") (eq $type "LoadBalancer")) (not (empty $svc.nodePort)) }} nodePort: {{ $svc.nodePort }} - {{- else if eq $type "ClusterIP" }} + {{- else if eq $type "ClusterIP" }} nodePort: null - {{- end }} - {{- if and $svc.extraPorts (kindIs "slice" $svc.extraPorts) }} - {{- toYaml $svc.extraPorts | nindent 4 }} - {{- end }} + {{- end }} + {{- if and $svc.extraPorts (kindIs "slice" $svc.extraPorts) }} + {{- toYaml $svc.extraPorts | nindent 4 }} + {{- end }} selector: {{- include "lib.utils.strings.template" (dict "value" (default (include "lib.utils.common.selectorLabels" $context) $svc.selector) "context" $context) | nindent 4 }} + {{- end }} {{- end }} {{- else }} {{- fail "Template requires '.context' as arguments" }} diff --git a/charts/manifests/templates/manifests/_serviceAccount.tpl b/charts/manifests/templates/manifests/_serviceAccount.tpl index fc2b6a1e..560d8bea 100644 --- a/charts/manifests/templates/manifests/_serviceAccount.tpl +++ b/charts/manifests/templates/manifests/_serviceAccount.tpl @@ -15,41 +15,39 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.serviceaccount.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "serviceAccount" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.serviceaccount" -}} {{- if .context -}} {{- $context := .context -}} - {{- $serviceAccount := (fromYaml (include "bedag-lib.manifest.serviceaccount.values" .)) -}} - {{- if $serviceAccount.create -}} + {{- $serviceAccount := mergeOverwrite (fromYaml (include "bedag-lib.values.serviceaccount" $)).serviceAccount (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $serviceAccount) }} + {{- if $serviceAccount.create -}} kind: ServiceAccount - {{- if $serviceAccount.apiVersion }} + {{- if $serviceAccount.apiVersion }} apiVersion: {{ $serviceAccount.apiVersion }} - {{- else }} + {{- else }} apiVersion: v1 - {{- end }} + {{- end }} metadata: name: {{ include "bedag-lib.utils.common.serviceAccountName" (dict "sa" $serviceAccount "context" $context) }} labels: {{- include "lib.utils.common.labels" (dict "labels" $serviceAccount.labels "context" $context)| nindent 4 }} - {{- if $serviceAccount.annotations }} + {{- if $serviceAccount.annotations }} annotations: - {{- range $anno, $val := $serviceAccount.annotations }} - {{- $anno | nindent 4 }}: {{ $val | quote }} + {{- range $anno, $val := $serviceAccount.annotations }} + {{- $anno | nindent 4 }}: {{ $val | quote }} + {{- end }} {{- end }} - {{- end }} - {{- if (kindIs "bool" $serviceAccount.automountServiceAccountToken) }} + {{- if (kindIs "bool" $serviceAccount.automountServiceAccountToken) }} automountServiceAccountToken: {{ $serviceAccount.automountServiceAccountToken }} - {{- end }} - {{- if and $serviceAccount.secrets (kindIs "slice" $serviceAccount.secrets) }} + {{- end }} + {{- if and $serviceAccount.secrets (kindIs "slice" $serviceAccount.secrets) }} secrets: {{ toYaml $serviceAccount.secrets | nindent 2 }} - {{- end }} - {{- if or (and $serviceAccount.imagePullSecrets (kindIs "slice" $serviceAccount.imagePullSecrets)) $serviceAccount.globalPullSecrets }} - {{- if $serviceAccount.globalPullSecrets }} + {{- end }} + {{- if or (and $serviceAccount.imagePullSecrets (kindIs "slice" $serviceAccount.imagePullSecrets)) $serviceAccount.globalPullSecrets }} + {{- if $serviceAccount.globalPullSecrets }} imagePullSecrets: {{- include "lib.utils.globals.imagePullSecrets" (dict "pullSecrets" $serviceAccount.imagePullSecrets "context" $context)| nindent 2 }} - {{- else }} + {{- else }} imagePullSecrets: {{ toYaml $serviceAccount.imagePullSecrets | nindent 2 }} + {{- end }} {{- end }} {{- end }} {{- end }} diff --git a/charts/manifests/templates/manifests/_serviceMonitor.tpl b/charts/manifests/templates/manifests/_serviceMonitor.tpl index 3783093d..cac5a299 100644 --- a/charts/manifests/templates/manifests/_serviceMonitor.tpl +++ b/charts/manifests/templates/manifests/_serviceMonitor.tpl @@ -15,44 +15,42 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.servicemonitor.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "servicemonitor" "root" .)) "context" .context) -}} -{{- end }} - {{- define "bedag-lib.manifest.servicemonitor" -}} {{- if .context -}} {{- $context := .context -}} - {{- $serviceMonitor := (fromYaml (include "bedag-lib.manifest.servicemonitor.values" .)) -}} - {{- if $serviceMonitor.enabled -}} - {{- if $serviceMonitor.apiVersion -}} + {{- $serviceMonitor := mergeOverwrite (fromYaml (include "bedag-lib.values.servicemonitor" $)).serviceMonitor (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $serviceMonitor) }} + {{- if $serviceMonitor.enabled -}} + {{- if $serviceMonitor.apiVersion -}} apiVersion: {{ $serviceMonitor.apiVersion }} - {{- else -}} + {{- else -}} apiVersion: monitoring.coreos.com/v1 - {{- end }} + {{- end }} kind: ServiceMonitor metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $serviceMonitor.labels "context" $context)| nindent 4 }} - {{- if $serviceMonitor.namespace }} + {{- if $serviceMonitor.namespace }} namespace: {{- include "lib.utils.strings.template" (dict "value" $serviceMonitor.namespace "context" $context) }} - {{- end }} + {{- end }} spec: - {{- if $serviceMonitor.additionalFields }} - {{- toYaml $serviceMonitor.additionalFields | nindent 2 }} - {{- end }} + {{- if $serviceMonitor.additionalFields }} + {{- toYaml $serviceMonitor.additionalFields | nindent 2 }} + {{- end }} selector: matchLabels: {{- include "lib.utils.strings.template" (dict "value" (default (include "lib.utils.common.selectorLabels" $context) $serviceMonitor.selector) "context" $context) | nindent 6 }} endpoints: {{- include "lib.utils.strings.template" (dict "value" $serviceMonitor.endpoints "context" $context) | nindent 4 }} namespaceSelector: matchNames: - {{- if $serviceMonitor.namespaceSelector }} - {{- if kindIs "slice" $serviceMonitor.namespaceSelector }} - {{- toYaml $serviceMonitor.namespaceSelector | nindent 6 }} - {{- else }} + {{- if $serviceMonitor.namespaceSelector }} + {{- if kindIs "slice" $serviceMonitor.namespaceSelector }} + {{- toYaml $serviceMonitor.namespaceSelector | nindent 6 }} + {{- else }} - {{ $serviceMonitor.namespaceSelector }} + {{- end }} + {{- else }} + - {{ $context.Release.Namespace }} {{- end }} - {{- else }} - - {{ $context.Release.Namespace }} {{- end }} {{- end }} {{- end }} diff --git a/charts/manifests/templates/manifests/_statefulset.tpl b/charts/manifests/templates/manifests/_statefulset.tpl index c845d70d..392f9078 100644 --- a/charts/manifests/templates/manifests/_statefulset.tpl +++ b/charts/manifests/templates/manifests/_statefulset.tpl @@ -15,45 +15,43 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.manifest.statefulset.values" -}} - {{- include "lib.utils.strings.template" (dict "value" (include "bedag-lib.utils.common.mergedValues" (dict "type" "statefulset" "root" .)) "context" .context) }} -{{- end }} - {{- define "bedag-lib.manifest.statefulset" -}} {{- if .context -}} {{- $context := .context -}} - {{- $statefulset := (fromYaml (include "bedag-lib.manifest.statefulset.values" .)) -}} + {{- $statefulset := mergeOverwrite (fromYaml (include "bedag-lib.values.statefulset" $)).statefulset (default dict .values) (default dict .overwrites) -}} + {{- if (include "bedag-lib.utils.intern.noYamlError" $statefulset) }} kind: StatefulSet - {{- if $statefulset.apiVersion }} + {{- if $statefulset.apiVersion }} apiVersion: {{ $statefulset.apiVersion }} - {{- else }} + {{- else }} apiVersion: apps/v1 - {{- end }} + {{- end }} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} labels: {{- include "lib.utils.common.labels" (dict "labels" $statefulset.labels "context" $context)| nindent 4 }} spec: podManagementPolicy: {{ default "OrderedReady" $statefulset.podManagementPolicy }} updateStrategy: - {{- $updateStrategy := (default "RollingUpdate" $statefulset.updateStrategy) }} + {{- $updateStrategy := (default "RollingUpdate" $statefulset.updateStrategy) }} type: {{ $updateStrategy | quote }} - {{- if (eq "OnDelete" $updateStrategy) }} + {{- if (eq "OnDelete" $updateStrategy) }} rollingUpdate: null - {{- else if $statefulset.rollingUpdatePartition }} + {{- else if $statefulset.rollingUpdatePartition }} rollingUpdate: partition: {{ $statefulset.rollingUpdatePartition }} - {{- end }} + {{- end }} replicas: {{ default "1" $statefulset.replicaCount }} selector: matchLabels: {{- include "lib.utils.strings.template" (dict "value" (default (include "lib.utils.common.selectorLabels" $context) $statefulset.selectorLabels) "context" $context) | nindent 6 }} serviceName: {{ default (include "bedag-lib.utils.common.fullname" .) $statefulset.serviceName }} - {{- if $statefulset.statefulsetExtras }} - {{- toYaml $statefulset.statefulsetExtras | nindent 2 }} - {{- end }} + {{- if $statefulset.statefulsetExtras }} + {{- toYaml $statefulset.statefulsetExtras | nindent 2 }} + {{- end }} template: {{- include "bedag-lib.template.pod" (set . "pod" $statefulset) | nindent 4 }} - {{- if and $statefulset.volumeClaimTemplates (kindIs "slice" $statefulset.volumeClaimTemplates) }} + {{- if and $statefulset.volumeClaimTemplates (kindIs "slice" $statefulset.volumeClaimTemplates) }} volumeClaimTemplates: {{- toYaml $statefulset.volumeClaimTemplates | nindent 4 }} - {{- end }} + {{- end }} + {{- end }} {{- else }} {{- fail "Template requires '.context' as arguments" }} {{- end }} diff --git a/charts/manifests/templates/manifests/templates/_bundleExtras.tpl b/charts/manifests/templates/manifests/templates/_bundleExtras.tpl index 4b981142..9183c01d 100644 --- a/charts/manifests/templates/manifests/templates/_bundleExtras.tpl +++ b/charts/manifests/templates/manifests/templates/_bundleExtras.tpl @@ -16,21 +16,21 @@ limitations under the License. */}} {{- define "bedag-lib.template.bundleExtras" -}} - {{- if and .values .context }} - {{- if .values.serviceAccount }} - {{- if and .values.serviceAccount.enabled .values.serviceAccount.create }} ----{{- include "bedag-lib.manifest.serviceaccount" (dict "values" .values.serviceAccount "context" .context) | nindent 0 }} + {{- if and $.values (include "bedag-lib.utils.intern.noYamlError" $.values) $.context (include "bedag-lib.utils.intern.noYamlError" $.context) -}} + {{- if $.values.serviceAccount }} + {{- if and $.values.serviceAccount.enabled $.values.serviceAccount.create }} +---{{- include "bedag-lib.manifest.serviceaccount" (dict "values" $.values.serviceAccount "context" $.context) | nindent 0 }} {{- end }} {{- end }} - {{- if .values.environment }} - {{- $environment := .values.environment }} + {{- if $.values.environment }} + {{- $environment := $.values.environment }} {{- if (include "bedag-lib.utils.environment.hasSecrets" $environment) }} --- apiVersion: v1 kind: Secret metadata: name: {{ include "bedag-lib.utils.common.fullname" . }}-env - labels: {{- include "lib.utils.common.labels" (dict "labels" .values.labels "context" .context)| nindent 4 }} + labels: {{- include "lib.utils.common.labels" (dict "labels" $.values.labels "context" $.context)| nindent 4 }} type: Opaque data: {{- range $environment }} diff --git a/charts/manifests/templates/manifests/templates/_containerTpl.tpl b/charts/manifests/templates/manifests/templates/_containerTpl.tpl index 6488b734..845bb933 100644 --- a/charts/manifests/templates/manifests/templates/_containerTpl.tpl +++ b/charts/manifests/templates/manifests/templates/_containerTpl.tpl @@ -17,7 +17,7 @@ limitations under the License. */}} {{- define "bedag-lib.template.container" -}} {{- $values := (mergeOverwrite (fromYaml (include "bedag-lib.values.template.container" .)) .container) -}} - {{- if and $values .context -}} + {{- if and $values (include "bedag-lib.utils.intern.noYamlError" $values) .context (include "bedag-lib.utils.intern.noYamlError" .context) -}} {{- $context := .context -}} name: {{ default $context.Chart.Name $values.containerName }} image: {{ include "lib.utils.globals.image" (dict "image" $values "context" $context "default" (default $context.Chart.AppVersion .default)) }} diff --git a/charts/manifests/templates/manifests/templates/_jobTpl.tpl b/charts/manifests/templates/manifests/templates/_jobTpl.tpl index 150e08b4..0c183289 100644 --- a/charts/manifests/templates/manifests/templates/_jobTpl.tpl +++ b/charts/manifests/templates/manifests/templates/_jobTpl.tpl @@ -17,7 +17,7 @@ limitations under the License. */}} {{- define "bedag-lib.template.job" -}} {{- $values := mergeOverwrite (fromYaml (include "bedag-lib.values.template.job" .)) .job -}} - {{- if and $values .context -}} + {{- if and $values (include "bedag-lib.utils.intern.noYamlError" $values) .context (include "bedag-lib.utils.intern.noYamlError" .context) -}} {{- $context := .context }} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} diff --git a/charts/manifests/templates/manifests/templates/_podTpl.tpl b/charts/manifests/templates/manifests/templates/_podTpl.tpl index 1a59745d..2e3737a5 100644 --- a/charts/manifests/templates/manifests/templates/_podTpl.tpl +++ b/charts/manifests/templates/manifests/templates/_podTpl.tpl @@ -17,7 +17,7 @@ limitations under the License. */}} {{- define "bedag-lib.template.pod" -}} {{- $values := mergeOverwrite (fromYaml (include "bedag-lib.values.template.pod" .)) .pod -}} - {{- if and $values .context -}} + {{- if and $values (include "bedag-lib.utils.intern.noYamlError" $values) .context (include "bedag-lib.utils.intern.noYamlError" .context) -}} {{- $context := .context -}} metadata: labels: {{- include "lib.utils.common.labels" (dict "labels" $values.podLabels "versionUnspecific" "true" "context" $context)| nindent 4 }} diff --git a/charts/manifests/templates/manifests/templates/_pvcTpl.tpl b/charts/manifests/templates/manifests/templates/_pvcTpl.tpl index d48a704a..5398ea0a 100644 --- a/charts/manifests/templates/manifests/templates/_pvcTpl.tpl +++ b/charts/manifests/templates/manifests/templates/_pvcTpl.tpl @@ -15,9 +15,9 @@ See the License for the specific language governing permissions and limitations under the License. */}} -{{- define "bedag-lib.template.persistentVolumeClaim" -}} +{{- define "bedag-lib.template.persistentvolumeclaim" -}} {{- $values := mergeOverwrite (fromYaml (include "bedag-lib.values.template.pvc" .)) .pvc -}} - {{- if and $values .context -}} + {{- if and $values (include "bedag-lib.utils.intern.noYamlError" $values) .context (include "bedag-lib.utils.intern.noYamlError" .context) -}} {{- $context := .context -}} metadata: name: {{ include "bedag-lib.utils.common.fullname" . }} diff --git a/charts/manifests/templates/utils/_common.tpl b/charts/manifests/templates/utils/_common.tpl index 1bb42221..6d45688a 100644 --- a/charts/manifests/templates/utils/_common.tpl +++ b/charts/manifests/templates/utils/_common.tpl @@ -49,16 +49,3 @@ limitations under the License. {{- fail "Template requires '.context' as arguments" }} {{- end }} {{- end -}} - -{{/* - Sprig Template - MergedValues -*/}} -{{- define "bedag-lib.utils.common.mergedValues" -}} - {{- if and .type .root -}} - {{- $tpl := cat "bedag-lib.values." (.type | lower) | nospace -}} - {{- $defaultValues := default dict (get (fromYaml (include $tpl .root.context)) ((default .type .key) | toString)) -}} - {{- toYaml (mergeOverwrite $defaultValues (default dict .root.values) (default dict .root.overwrites)) -}} - {{- else -}} - {{- fail "Template requires '.type' and '.root' as arguments" -}} - {{- end -}} -{{- end -}} diff --git a/charts/manifests/templates/utils/_intern.tpl b/charts/manifests/templates/utils/_intern.tpl index 364c1cfa..517d5a16 100644 --- a/charts/manifests/templates/utils/_intern.tpl +++ b/charts/manifests/templates/utils/_intern.tpl @@ -18,3 +18,11 @@ limitations under the License. {{- define "bedag-lib.utils.intern.docLink" -}} https://github.com/bedag/helm-charts/tree/master/charts/manifests/templates/manifests/README.md {{- end }} + +{{- define "bedag-lib.utils.intern.noYamlError" -}} + {{- if $.Error -}} + {{- fail $.Error -}} + {{- else -}} + {{- true -}} + {{- end -}} +{{- end -}} diff --git a/charts/manifests/templates/values/manifests/_service.yaml b/charts/manifests/templates/values/manifests/_service.yaml index 16020c11..5f2f74a2 100644 --- a/charts/manifests/templates/values/manifests/_service.yaml +++ b/charts/manifests/templates/values/manifests/_service.yaml @@ -43,6 +43,11 @@ # @default -- http targetPort: "" + ## Service Protocol + # {{ $_.path }}protocol -- Configure Service Port Protocol + # @default -- TCP + protocol: "" + ## Service Extra Ports # {{ $_.path }}extraPorts -- Add additional ports to the service extraPorts: []