From 74d49b39707bd7c1d146d5c547dc1c84154ffb3c Mon Sep 17 00:00:00 2001 From: Chi-En Wu Date: Thu, 23 Apr 2020 15:26:05 +0800 Subject: [PATCH] docs: add description about `common.metadata` --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 650eb18..5fc0690 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ It provides utilities that reflect best practices of Kubernetes chart developmen * [`common.serviceMonitor.secret`](#commonservicemonitorsecret) - [Partial Objects](#partial-objects) * [`common.container`](#commoncontainer) + * [`common.metadata`](#commonmetadata) * [`common.pod.template`](#commonpodtemplate) @@ -882,6 +883,47 @@ spec: +### `common.metadata` + +The `common.metadata` helper generates value for the `metadata:` section of a Kubernetes resource. + +This takes a list of two values: + +- `$top`, the top context +- [optional] the template name of the overrides + +It generates standard labels and a name field. + +Example template: + +```yaml +metadata: + {{- include "common.metadata" (list .) | nindent 2 }} + +## The following is the same as above: +# metadata: +# {{- include "common.metadata" (list . "mychart.metadata") | nindent 2 }} +# {{- define "mychart.metadata" -}} +# {{- end -}} +``` + +Example output: + +```yaml +metadata: + labels: + app.kubernetes.io/instance: release-name + app.kubernetes.io/managed-by: Helm + app.kubernetes.io/name: mychart + app.kubernetes.io/version: 1.16.0 + helm.sh/chart: mychart-0.1.0 + name: release-name-mychart +``` + +Most of the common templates that define a resource type (e.g. `common.configMap` or `common.cronJob`) use this to generate the metadata, which means they inherit the same `labels` and `name` fields. + + + ### `common.pod.template` The `common.pod.template` template accepts a list of three values: