library
by Buttahtoast
Buttahtoast Helm Library
About this chart
Buttahtoast Library
This is our take on a library Chart. It contains simple functions which are (will be) used across all of our charts. Feel free the add or improve the existing templates. This Chart is still under development/testing. Feel free to use it, if you find any issues with it, please create an issue/PR. We will try to get bugs fixed as soon as possible!
Homepage: https://github.com/buttahtoast/helm-charts/tree/master/charts/library
Maintainers
| Name | Url | |
|---|---|---|
| oliverbaehler | [email protected] | |
| chifu1234 | [email protected] |
Install Chart
Since this chart is of type library it can only be used as dependency for other charts. Just add it in your chart dependencies section:
dependencies:
- name: library
version: 1.0.0
repository: https://buttahtoast.github.io/helm-charts/
If the chart is within this Github helm repository, you can reference it as local dependency
dependencies:
- name: library
version: ">=1.0.0"
repository: "file://../library"
Major Changes
Major Changes to functions are documented with the version affected. Before upgrading the dependency version, check this section out!
| Template | Chart Version | Change/Description | Commits/PRs |
|---|---|---|---|
$.Values.kubecapabilities | 1.0.0 | $.Values.kubecapabilities moved to $.Values.global.kubecapabilities. Without mapping these values the kubeCapabilities no longer works. | Pull Request |
| All string, list, globals and dict templates | 0.3.0 | Added for each template category the category as template name path. (eg. all string templates = lib.utils.strings.*). | Pull Request |
Templates
The available template functions are grouped by Data Type or Usage. Each describing how the template is called, what
it should do and what it should return. NOTICE We had to use single { in the examples, because helm-docs tries to
parse the file and that causes some issues. So don't forget to add a pair of {}.
Template Index
- Common
- Fullname
- Chart
- SelectorLabels
- DefaultLabels
- CommonLabels
- Labels
- KubeCapabilities
- Strings
- Template
- Stringify
- ToDns1123
- Lists
- HasValueByKey
- GetValueByKey
- MergeList
- MergeListOnKey
- ExceptionList
- Dictionaries
- ParentAppend
- PrintYamlStructure
- Get
- Set
- Unset
- Merge
- Extras
- Environment
- Java Proxy
- ExtraResources
- Errors
- fail
- unmarshalingError
- params
- Types
- validate
Common
Making use of all the common templates enable the following keys:
- All Common Values can be found here
Fullname
Extended Function to return a fullname.
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
./.context- Inherited Root Context (Required). Make sure global variables are accessible through the context..name- Define a custom name, without prefix. The given value will appended to an evaluated prefix. Becomes suffix of the$.Values.fullnameOverrideproperty, if set. Can also be set through.context.name..fullname- Define a custom fullname. The given value will be returned as name. Is overwritten by the$.Values.fullnameOverrideproperty, if set. Can also be set through.context.fullname..prefix- Define a custom Prefix for the fullname. (Defaults to$.Release.Name)
Keys
This function enables the following keys on the values scope:
## Overwrite Name Template
# nameOverride -- Overwrite "lib.internal.common.name" output
nameOverride: ""
## Overwrite Fullname Template
# fullnameOverride -- Overwrite `lib.utils.common.fullname` output
fullnameOverride: ""
Returns
String
Usage
{- include "lib.utils.common.fullname" $) }
Chart
Chart Name
Returns
String
Usage
{- include "lib.internal.common.chart" $) }
SelectorLabels
This template will return the default selectorLabels (Useable for Match/Selector Labels). In addition there is the option to overwrite these labels. If no selectorLabels are defined, the following labels are set:
app.kubernetes.io/name: { include "lib.utils.common.name" . }
app.kubernetes.io/instance: { .Release.Name }
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
.- Inherited Root Context (Required). Make sure global variables are accessible through the context.
Keys
This function enables the following keys on the values scope:
## Selector Labels
# selectorLabels -- Define default [selectorLabels](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/)
selectorLabels: {}
Returns
YAML Structure, String
Usage
{- include "lib.utils.common.selectorLabels" $) }
DefaultLabels
This template represents the default templates. It includes the SelectorLabel template and sets the Application Version.
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
.- Inherited Root Context (Required). Make sure global variables are accessible through the context.
Returns
YAML Structure, String
Usage
{- include "lib.utils.common.defaultLabels" $) }
OverwriteLabels
This template allows to define overwritting labels. Overwrite labels overwrite the default labels (DefaultLabels Template). By Using this template
the key .Values.overwriteLabels is considered in your value structure. If the key has values and is type map the values are used
as common labels.
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
.- Inherited Root Context (Required). Make sure global variables are accessible through the context.
Keys
This function enables the following keys on the values scope:
## Overwrite Labels
# overwriteLabels -- Overwrites default labels, but not resource specific labels and common labels
overwriteLabels: {}
Returns
YAML Structure, String
Usage
{- include "lib.utils.common.overwriteLabels" $) }
CommonLabels
This template allows to define common labels. Common labels are appended to the base labels (no merge). By Using this template
the key .Values.commonLabels is considered in your value structure. If the key has values and is type map the values are used
as common labels.
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
.- Inherited Root Context (Required). Make sure global variables are accessible through the context.
Keys
This function enables the following keys on the values scope:
## Common Labels
# commonLabels -- Common Labels are added to each kubernetes resource manifest. But will not be added to resources rendered by the common chart (eg. JMX Exporter)
commonLabels: {}
## Overwrite Labels
# overwriteLabels -- Overwrites default labels, but not resource specific labels and common labels
overwriteLabels: {}
Returns
YAML Structure, String
Usage
{- include "lib.utils.common.commonLabels" $) }
Labels
This template wraps around all the other label templates. Therefor all their functionalities are available with this template. In addition it's possible to pass labels, which overwrite the result of all the label templates.
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
./.context- Inherited Root Context (Required)..labels- Labels which overwrite the resulting labels of all the other label templates..versionUnspecific- Removes the version label. Useful when you don't want your resource to be changed on version update (Spec Change).
Keys
This function enables the following keys on the values scope:
## Common Labels
# commonLabels -- Common Labels are added to each kubernetes resource manifest. But will not be added to resources rendered by the common chart (eg. JMX Exporter)
commonLabels: {}
## Overwrite Labels
# overwriteLabels -- Overwrites default labels, but not resource specific labels and common labels
overwriteLabels: {}
Returns
YAML Structure, String
Usage
{- include "lib.utils.common.labels" (dict "labels" (dict "custom.label" "value" "custom.label/2" "value") "context" $) }
KubeCapabilities
This template allows to define a custom KubeCapabilities Version (replaces $.Capabilities.KubeVersion.GitVersion). This might be useful when
trying to test the chart or having client versions that differ from the server version.
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
.- Inherited Root Context (Required). Make sure global variables are accessible through the context.
Keys
This function enables the following keys on the values scope:
## Version Capabilities
# kubeCapabilities -- Overwrite the Kube GitVersion
# @default -- `$.Capabilities.KubeVersion.GitVersion`
kubeCapabilities: "1.19.0"
Returns
String
Usage
{- if semverCompare ">=1.19-0" (include "lib.utils.common.capabilities" $) }
apiVersion: networking.k8s.io/v1
{- else if semverCompare ">=1.14-0" (include "lib.utils.common.capabilities" $context) -}
apiVersion: networking.k8s.io/v1beta1
{- else -}
Globals
Making use of all the global functions enable the following global keys.
- All Global Values can be found here
Strings
Template
This function allows to render String/Map input with the go template engine. Since the go template engine doesn't directly accept maps, maps are dumped in YAML format. If you want to reuse the returned value, you need to use the fromYaml function. If you have a multiline YAML, but you want to render it as part of the YAML Structure, use +|. This YAML multiline indicator will be replaced by \n.
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
.value- Content you want to template. If a Go Struct, it will be dumped to YAML, since the tpl function only allows strings (Required)..extraValues- Extra values you want to make available for the template function. Can be accessed through $.extraVars (Optional).extraValuesKey- Key which is used to publish.extraValues. Extra Value can be accessed through$.(.extraValuesKey)if set (Optional).context- Inherited Root Context (Required).
Returns
YAML Structure, String
Usage
{ include "lib.utils.strings.template" (dict "value" .Values.path.to.the.Value "context" $ "extraValues" $extraValues) }
or
{ $structure := fromYaml (include "lib.utils.strings.template" (dict "value" .Values.path.to.the.Value "context" $)) }
Stringify
This function allows to pass a list and create a single string, with a specific delimiter
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
.list- Expects input of type slice. If not given as slice, nothing will be returned (Required)..context- Inherited Root Context (Required)..delimiter- Chose the delimiter between each list object (Optional, Defaults to " ").
Returns
String
Usage
{ include "lib.utils.strings.stringify" ( dict "list" (default (list 1 2 3) .Values.someList) "delimiter" ", " "context" $) }
ToDns1123
Converts the given string into DNS1123 accepted format. The format has the following conditions:
a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is 'a-z0-9?(.a-z0-9?)*'). And should be maximum 63 characters long.
If the input is not of type string, it's returned as is.
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
.- The input you want to process by this function
Returns
String (1:1 return if not given as string)
Usage
{ include "lib.utils.strings.toDns1123" "my-string" }
Lists
HasValueByKey
Loops through subdicts in a given lists checking the given key for the given value. if matched, true is returned.
Arguments
If an as required marked argument is missing, the template engine will fail intentionally.
Deploy library with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has library on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartlibrary is pinned at v3.0.0-rc.3 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply