From 53a15f9f5c611b97a6290b0db21aec3730de027d Mon Sep 17 00:00:00 2001 From: Thomas Jungbauer Date: Tue, 9 Jul 2024 15:07:56 +0200 Subject: [PATCH 1/3] added tpl library chart as base for future import --- charts/tpl/Chart.yaml | 13 +++ charts/tpl/README.md | 103 +++++++++++++++++++++++ charts/tpl/README.md.gotmpl | 49 +++++++++++ charts/tpl/templates/_job_sleeptimer.tpl | 26 ++++++ charts/tpl/templates/_labels.tpl | 51 +++++++++++ charts/tpl/templates/_nodeSelector.tpl | 18 ++++ charts/tpl/templates/_resources.tpl | 66 +++++++++++++++ charts/tpl/templates/_serviceAccount.tpl | 26 ++++++ charts/tpl/templates/_tolerations.tpl | 29 +++++++ charts/tpl/templates/test/example.yaml | 14 +++ charts/tpl/values-example.yaml | 41 +++++++++ charts/tpl/values.yaml | 1 + 12 files changed, 437 insertions(+) create mode 100644 charts/tpl/Chart.yaml create mode 100644 charts/tpl/README.md create mode 100644 charts/tpl/README.md.gotmpl create mode 100644 charts/tpl/templates/_job_sleeptimer.tpl create mode 100644 charts/tpl/templates/_labels.tpl create mode 100644 charts/tpl/templates/_nodeSelector.tpl create mode 100644 charts/tpl/templates/_resources.tpl create mode 100644 charts/tpl/templates/_serviceAccount.tpl create mode 100644 charts/tpl/templates/_tolerations.tpl create mode 100644 charts/tpl/templates/test/example.yaml create mode 100644 charts/tpl/values-example.yaml create mode 100644 charts/tpl/values.yaml diff --git a/charts/tpl/Chart.yaml b/charts/tpl/Chart.yaml new file mode 100644 index 00000000..b3d39296 --- /dev/null +++ b/charts/tpl/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: tpl +description: A library that shall collect certain templats to reuse them among different charts. +version: 1.0.7 +home: https://github.com/redhat-cop/helm-charts/tree/main/charts/tpl +maintainers: + - name: tjungbauer + email: tjungbau@redhat.com + url: https://blog.stderr.at/ +keywords: + - templates + - helper + - subchart diff --git a/charts/tpl/README.md b/charts/tpl/README.md new file mode 100644 index 00000000..d6ed78fc --- /dev/null +++ b/charts/tpl/README.md @@ -0,0 +1,103 @@ + + +# tpl + + [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) + + ![Version: 1.0.7](https://img.shields.io/badge/Version-1.0.7-informational?style=flat-square) + + + + ## Description + + A library that shall collect certain templats to reuse them among different charts. + +This Helm Chart is a library of reusable template, like tolerations or resources. +Instead of defining them in other Charts multiple times, it is possible to simply include the template. + +The template "tpl.sleeptimer" is a simple template that can be used for Job to print our a timer. + +## Dependencies + +This chart has the following dependencies: + +| Repository | Name | Version | +|------------|------|---------| + +No dependencies + +## Maintainers + +| Name | Email | Url | +| ---- | ------ | --- | +| tjungbauer | | | + +## Sources +Source: + +Source code: https://github.com/redhat-cop/helm-charts/tree/main/charts/tpl + +## Values + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| nodeSelector.key | string | `"node-role.kubernetes.io/infra"` | | +| nodeSelector.value | string | `""` | | +| resources | object | `{"limits":{"cpu":8,"ephemeral-storage":500,"memory":16},"requests":{"cpu":4,"ephemeral-storage":50,"memory":8}}` | If you want to define resources
Example include: {{- if .Values.resources }} {{ include "tpl.resources" .Values.resources | indent 0 }} {{- end }} | +| tolerations | list | `[{"effect":"NoSchedule","key":"infra","operator":"Equal","tolerationSeconds":600,"value":"reserved"},{"effect":"NoSchedule","key":"infra","operator":"Equal","tolerationSeconds":600,"value":"reserved"}]` | If you want this component to only run on specific nodes, you can configure tolerations of tainted nodes.
Example include: {{- if .Values.tolerations }} {{ include "tpl.tolerations" .Values.tolerations | indent 0 }} {{- end }} | + +## Example values + +```yaml +--- +# Examples values file + +tolerations: + - effect: NoSchedule + key: infra + operator: Equal + value: reserved + tolerationSeconds: 600 + - effect: NoSchedule + key: infra + operator: Equal + value: reserved + tolerationSeconds: 600 + +resources: + requests: + cpu: 4 + memory: 8 + ephemeral-storage: 50 + limits: + cpu: 8 + memory: 16 + ephemeral-storage: 500 + +nodeSelector: + key: node-role.kubernetes.io/infra + value: '' +``` + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```console +helm install my-release repo/> +``` + +The command deploys the chart on the Kubernetes cluster in the default configuration. + +## Uninstalling the Chart + +To uninstall/delete the my-release deployment: + +```console +helm delete my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +---------------------------------------------- +Autogenerated from chart metadata using [helm-docs v1.12.0](https://github.com/norwoodj/helm-docs/releases/v1.12.0) diff --git a/charts/tpl/README.md.gotmpl b/charts/tpl/README.md.gotmpl new file mode 100644 index 00000000..7a931deb --- /dev/null +++ b/charts/tpl/README.md.gotmpl @@ -0,0 +1,49 @@ +{{ template "doc.header" . }} + +This Helm Chart is a library of reusable template, like tolerations or resources. +Instead of defining them in other Charts multiple times, it is possible to simply include the template. + +The template "tpl.sleeptimer" is a simple template that can be used for Job to print our a timer. + +{{ template "doc.deps" . }} + +No dependencies + +{{ template "doc.maintainer_and_sources" . }} + +{{ template "doc.values" . }} + +## Example values + +```yaml +--- +# Examples values file + +tolerations: + - effect: NoSchedule + key: infra + operator: Equal + value: reserved + tolerationSeconds: 600 + - effect: NoSchedule + key: infra + operator: Equal + value: reserved + tolerationSeconds: 600 + +resources: + requests: + cpu: 4 + memory: 8 + ephemeral-storage: 50 + limits: + cpu: 8 + memory: 16 + ephemeral-storage: 500 + +nodeSelector: + key: node-role.kubernetes.io/infra + value: '' +``` + +{{ template "doc.footer" . }} diff --git a/charts/tpl/templates/_job_sleeptimer.tpl b/charts/tpl/templates/_job_sleeptimer.tpl new file mode 100644 index 00000000..381b16cd --- /dev/null +++ b/charts/tpl/templates/_job_sleeptimer.tpl @@ -0,0 +1,26 @@ +{{/* +Create a sleeptimer for Jobs. +This has no input parameters. It just prints our the below while loop. + +{{ include "tpl.sleeptimer" . -}} +*/}} +{{- define "tpl.sleeptimer" -}} +sleep_timer={{ .sleeptimer | default 20 }} + +SLEEPER_TMP=1 +SLEEPER_MOD=10 + +while [[ $SLEEPER_TMP -le "$sleep_timer" ]]; do + if (( $SLEEPER_TMP % 10 == 0 )) + then + echo -n "$SLEEPER_MOD" + SLEEPER_MOD=$(($SLEEPER_MOD+10)) + else + echo -n "." + fi + sleep 1 + SLEEPER_TMP=$(($SLEEPER_TMP+1)) +done +{{- end -}} + + diff --git a/charts/tpl/templates/_labels.tpl b/charts/tpl/templates/_labels.tpl new file mode 100644 index 00000000..692268c5 --- /dev/null +++ b/charts/tpl/templates/_labels.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "tpl.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "tpl.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "tpl.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "tpl.labels" -}} +helm.sh/chart: {{ include "tpl.chart" . }} +{{ include "tpl.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "tpl.selectorLabels" -}} +app.kubernetes.io/name: {{ include "tpl.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/charts/tpl/templates/_nodeSelector.tpl b/charts/tpl/templates/_nodeSelector.tpl new file mode 100644 index 00000000..c1f295e3 --- /dev/null +++ b/charts/tpl/templates/_nodeSelector.tpl @@ -0,0 +1,18 @@ +{{/* +Set a nodeSelctor + +Example for resources in the values-file: + nodeSelector: + key: node-role.kubernetes.io/infra + value: '' + +{{ include "tpl.nodeSelector" . -}} +*/}} + +{{- define "tpl.nodeSelector" -}} + {{- if .nodeSelector }} + nodeSelector: + matchLabels: + {{ .nodeSelector.key }}: {{ .nodeSelector.value | quote }} + {{- end }} +{{- end -}} diff --git a/charts/tpl/templates/_resources.tpl b/charts/tpl/templates/_resources.tpl new file mode 100644 index 00000000..61e691fb --- /dev/null +++ b/charts/tpl/templates/_resources.tpl @@ -0,0 +1,66 @@ +{{/* +Return the range of resources if defined. + +Example for resources in the values-file: + resources: + requests: + cpu: 4 + memory: 8Gi + ephemeral-storage: 50Mi + limits: + cpu: 8 + memory: 16Gi + ephemeral-storage: 500Mi + +{{ include "tpl.resources" . -}} +*/}} + +{{- define "tpl.resources" -}} +resources: + {{- if .limits }} + limits: + {{- if .limits.cpu }} + cpu: {{ .limits.cpu }} + {{- end }} + {{- if .limits.memory }} + {{- $memory := include "appendUnit" .limits.memory }} + memory: {{ $memory }} + {{- end }} + {{- if index .limits "ephemeral-storage" }} + {{- $ephemeral_storage := include "appendUnit" (index .limits "ephemeral-storage") }} + ephemeral-storage: {{ $ephemeral_storage }} + {{- end }} + {{- end }} + {{- if .requests }} + requests: + {{- if .requests.cpu }} + cpu: {{ .requests.cpu }} + {{- end }} + {{- if .requests.memory }} + {{- $memory := include "appendUnit" .requests.memory }} + memory: {{ $memory }} + {{- end }} + {{- if index .requests "ephemeral-storage" }} + {{- $ephemeral_storage := include "appendUnit" (index .requests "ephemeral-storage") }} + ephemeral-storage: {{ $ephemeral_storage }} + {{- end }} + {{- end }} +{{- end -}} + +{{/* +Append the unit Gi if it is not set for memory or storage +*/}} +{{- define "appendUnit" -}} +{{/* Treat the value as a string */}} +{{- $val := printf "%v" . -}} + {{- if not (hasSuffix "Gi" $val) -}} + {{- if not (hasSuffix "Mi" $val) -}} + {{- printf "%sGi" $val -}} + {{- else -}} + {{ $val -}} + {{- end -}} + {{- else -}} + {{ $val -}} + {{- end -}} +{{- end -}} + diff --git a/charts/tpl/templates/_serviceAccount.tpl b/charts/tpl/templates/_serviceAccount.tpl new file mode 100644 index 00000000..1aeeb67b --- /dev/null +++ b/charts/tpl/templates/_serviceAccount.tpl @@ -0,0 +1,26 @@ +{{/* +Create the name of the service account to use. +If not set use "temp-serviceaccount" to ensure +that templating works and does not break at some point +*/}} +{{- define "tpl.serviceAccountName" -}} + {{- if .Values.serviceAccount.create }} + {{- default .Values.serviceAccount.name }} + {{- else }} + {{- default "temp-serviceaccount" }} + {{- end }} +{{- end }} + + +{{/* +Create the name of the service account to use. +If not set use "temp-serviceaccount" to ensure +that templating works and does not break at some point +*/}} +{{- define "tpl.serviceAccount" -}} + {{- if .create }} + {{- default .name }} + {{- else }} + {{- default "temp-serviceaccount" }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/charts/tpl/templates/_tolerations.tpl b/charts/tpl/templates/_tolerations.tpl new file mode 100644 index 00000000..734d6a6f --- /dev/null +++ b/charts/tpl/templates/_tolerations.tpl @@ -0,0 +1,29 @@ +{{/* +Return the range of tolerations if defined. + +Example for infrastructure nodes in the values-file: + tolerations: + - effect: NoSchedule + key: infra + operator: Equal + value: reserved + - effect: NoSchedule + key: infra + operator: Equal + value: reserved + +{{ include "tpl.tolerations" . -}} +*/}} + +{{- define "tpl.tolerations" -}} +tolerations: + {{- range . }} + - key: "{{ .key }}" + operator: "{{ .operator }}" + value: "{{ .value }}" + effect: "{{ .effect }}" + {{- if .tolerationSeconds }} + tolerationSeconds: {{ .tolerationSeconds }} + {{- end }} + {{- end }} +{{- end -}} diff --git a/charts/tpl/templates/test/example.yaml b/charts/tpl/templates/test/example.yaml new file mode 100644 index 00000000..ae0eeaf0 --- /dev/null +++ b/charts/tpl/templates/test/example.yaml @@ -0,0 +1,14 @@ +{{- /* Set tolerations */}} +{{- if .Values.tolerations }} +{{ include "tpl.tolerations" .Values.tolerations | indent 0 }} +{{- end }} + +{{- /* Set resources */}} +{{- if .Values.resources }} +{{ include "tpl.resources" .Values.resources | indent 0 }} +{{- end }} + +{{- /* Set nodeSelector */}} +{{- if .Values.nodeSelector }} +{{- include "tpl.nodeSelector" .Values | indent 0 }} +{{- end }} diff --git a/charts/tpl/values-example.yaml b/charts/tpl/values-example.yaml new file mode 100644 index 00000000..0c45c119 --- /dev/null +++ b/charts/tpl/values-example.yaml @@ -0,0 +1,41 @@ +--- +# Examples values file + +# -- If you want this component to only run on specific nodes, you can +# configure tolerations of tainted nodes. +#
+# Example include: +# {{- if .Values.tolerations }} +# {{ include "tpl.tolerations" .Values.tolerations | indent 0 }} +# {{- end }} +tolerations: + - effect: NoSchedule + key: infra + operator: Equal + value: reserved + tolerationSeconds: 600 + - effect: NoSchedule + key: infra + operator: Equal + value: reserved + tolerationSeconds: 600 + +# -- If you want to define resources +#
+# Example include: +# {{- if .Values.resources }} +# {{ include "tpl.resources" .Values.resources | indent 0 }} +# {{- end }} +resources: + requests: + cpu: 4 + memory: 8 + ephemeral-storage: 50 + limits: + cpu: 8 + memory: 16 + ephemeral-storage: 500 + +nodeSelector: + key: node-role.kubernetes.io/infra + value: '' \ No newline at end of file diff --git a/charts/tpl/values.yaml b/charts/tpl/values.yaml new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/charts/tpl/values.yaml @@ -0,0 +1 @@ +--- From a114db0b68268ea177daeac83986ee0b25d4e876 Mon Sep 17 00:00:00 2001 From: Thomas Jungbauer <25078868+tjungbauer@users.noreply.github.com> Date: Fri, 12 Jul 2024 13:11:53 +0200 Subject: [PATCH 2/3] Update charts/tpl/README.md Co-authored-by: Cansu <31902747+ckavili@users.noreply.github.com> --- charts/tpl/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/tpl/README.md b/charts/tpl/README.md index d6ed78fc..1f58061a 100644 --- a/charts/tpl/README.md +++ b/charts/tpl/README.md @@ -10,7 +10,7 @@ ## Description - A library that shall collect certain templats to reuse them among different charts. + A library that shall collect certain templates to reuse them among different charts. This Helm Chart is a library of reusable template, like tolerations or resources. Instead of defining them in other Charts multiple times, it is possible to simply include the template. From 497473626f223a1b872ab703476fe396474f6395 Mon Sep 17 00:00:00 2001 From: Thomas Jungbauer <25078868+tjungbauer@users.noreply.github.com> Date: Fri, 12 Jul 2024 13:12:02 +0200 Subject: [PATCH 3/3] Update charts/tpl/Chart.yaml Co-authored-by: Cansu <31902747+ckavili@users.noreply.github.com> --- charts/tpl/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/tpl/Chart.yaml b/charts/tpl/Chart.yaml index b3d39296..b37ab8ce 100644 --- a/charts/tpl/Chart.yaml +++ b/charts/tpl/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: tpl -description: A library that shall collect certain templats to reuse them among different charts. +description: A library that shall collect certain templates to reuse them among different charts. version: 1.0.7 home: https://github.com/redhat-cop/helm-charts/tree/main/charts/tpl maintainers: