-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #554 from tjungbauer/main
Importing TPL lib for future imports
- Loading branch information
Showing
12 changed files
with
437 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v2 | ||
name: tpl | ||
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: | ||
- name: tjungbauer | ||
email: [email protected] | ||
url: https://blog.stderr.at/ | ||
keywords: | ||
- templates | ||
- helper | ||
- subchart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 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. | ||
|
||
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 | <[email protected]> | <https://blog.stderr.at/> | | ||
|
||
## 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 <br /> 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. <br /> 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/<chart-name>> | ||
``` | ||
|
||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" . }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -}} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -}} |
Oops, something went wrong.