Skip to content

Commit

Permalink
Helm 3.5.* Compatibility (#33)
Browse files Browse the repository at this point in the history
Signed-off-by: Oliver Bähler <[email protected]>
  • Loading branch information
oliverbaehler authored Feb 10, 2021
1 parent b090218 commit 83b73d8
Show file tree
Hide file tree
Showing 29 changed files with 322 additions and 322 deletions.
10 changes: 7 additions & 3 deletions charts/manifests/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
4 changes: 2 additions & 2 deletions charts/manifests/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion charts/manifests/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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) |


{{/*
Expand Down
16 changes: 8 additions & 8 deletions charts/manifests/templates/Quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand Down Expand Up @@ -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 }}
Expand All @@ -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 }}
Expand All @@ -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 }}
```
52 changes: 19 additions & 33 deletions charts/manifests/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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" }}
Expand Down
30 changes: 29 additions & 1 deletion charts/manifests/templates/manifests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
52 changes: 29 additions & 23 deletions charts/manifests/templates/manifests/_bundle.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
24 changes: 11 additions & 13 deletions charts/manifests/templates/manifests/_cronjob.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 -}}
22 changes: 10 additions & 12 deletions charts/manifests/templates/manifests/_daemonset.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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 -}}
Loading

0 comments on commit 83b73d8

Please sign in to comment.