Files
common/README.md
Konstantin Grachev c9f4c7eeb4
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
fix: use oci in templates
2023-06-18 16:55:08 +03:00

195 lines
4.3 KiB
Markdown

## Getting Started
### Adding Repository
The following command allows you to download and install all the charts from our repository:
```shell
$ helm repo add hahow oci://cr.grachevko.ru/helm/chart
```
### Adding Dependency
To use the library chart, `common` should be listed in `dependencies` field in your `Chart.yaml`:
```yaml
dependencies:
- name: common
version: 0.4.1
repository: oci://cr.grachevko.ru/helm/chart
```
Once you have defined dependencies, you should run the following command to download this chart into your `charts/`
directory:
```shell
$ helm dep build
```
### Using Starter
The best way to get started is to use the [`create` script](create.sh) to generate a new chart.
You can fetch that script, and then execute it locally:
```shell
$ curl https://git.grachevko.ru/helm/common/raw/branch/master/create.sh | bash -s -- mychart
```
Now, there is a chart in `./mychart`. You can edit it and create your own templates.
## Partial Objects
When writing Kubernetes resources, you may find the following helpers useful to construct parts of the spec.
### `common.chart`
The `common.chart` helper prints the chart name and version, escaped to be legal in a Kubernetes label field.
Example template:
```yaml
helm.sh/chart: { { include "common.chart" . } }
```
For the chart `foo` with version `1.2.3-beta.55+1234`, this will render:
```yaml
helm.sh/chart: foo-1.2.3-beta.55_1234
```
(Note that `+` is an illegal character in label values)
### `common.fullname`
The `common.fullname` template generates a name suitable for the `name:` field in Kubernetes metadata. It is used like
this:
```yaml
name: { { include "common.fullname" . } }
```
This prints the value of `{{ .Release.Name }}-{{ .Chart.Name }}` by default, but can be overridden
with `.Values. fullnameOverride`:
```yaml
fullnameOverride: some-name
```
Example output:
```yaml
---
# with the values above
name: some-name
---
# the default, for release "release-name" and chart "mychart"
name: release-name-mychart
```
Output of this function is truncated at 63 characters, which is the maximum length of name.
### `common.labels`
`common.selectorLabels` prints the standard set of labels.
Example usage:
```
{{ include "common.labels" . }}
```
Example output:
```yaml
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
```
### `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.name`
The `common.name` template generates a name suitable for the `app.kubernetes.io/name` label. It is used like this:
```yaml
app.kubernetes.io/name: { { include "common.name" . } }
```
This prints the value of `{{ .Chart.Name }}` by default, but can be overridden with `.Values.nameOverride`:
```yaml
nameOverride: some-name
```
Example output:
```yaml
---
# with the values above
app.kubernetes.io/name: some-name
---
# the default, for chart "mychart"
app.kubernetes.io/name: mychart
```
Output of this function is truncated at 63 characters, which is the maximum length of name.
### `common.selectorLabels`
`common.selectorLabels` prints the standard set of selector labels.
Example usage:
```
{{ include "common.selectorLabels" . }}
```
Example output:
```yaml
app.kubernetes.io/instance: release-name
app.kubernetes.io/name: mychart
```