Skip to content

Commit

Permalink
feat: generated Helm documentation (#335)
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <noreply@github.com>
  • Loading branch information
aslafy-z authored Sep 30, 2024
1 parent d8f82d0 commit 31904e3
Show file tree
Hide file tree
Showing 25 changed files with 1,347 additions and 980 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,19 @@ jobs:
with:
charts: application
unittest-version: v0.5.x

check-helm-docs:
name: Check Helm Docs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{github.event.pull_request.head.sha}}
- name: Run helm-docs and check diff
# TODO: Move to upstream once https://github.com/losisin/helm-docs-github-action/pull/270 is merged
uses: losisin/helm-docs-github-action@0f2a7b456e9e4393faa24d4d2e1636bdb0a5b9b9
with:
output-file: ./README.md
template-files: ./README.md.gotmpl
sort-values-order: file
fail-on-diff: true
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
repos:
- repo: https://github.com/norwoodj/helm-docs
rev: v1.14.2
hooks:
- id: helm-docs-built
args:
- --chart-search-root=.
- --values-file=values.yaml
- --output-file=./../README.md
- --template-files=./README.md.gotmpl
- --sort-values-order=file
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
SHELL := /bin/bash

VERSION ?= 0.0.1
install-hooks:
command -v pre-commit 2>&1 >/dev/null || pip install pre-commit
pre-commit install

bump-chart:
sed -i "s/^version:.*/version: $(VERSION)/" application/Chart.yaml
@test -n "$(VERSION)" || (echo "VERSION environment variable is not set"; exit 1)
sed -i 's/^version: [0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}/version: $(VERSION)/' application/Chart.yaml

build-docs: install-hooks
# Running helm-docs-built twice to ensure that the generated docs are up-to-date
pre-commit run helm-docs-built --all-files || true
pre-commit run helm-docs-built --all-files
993 changes: 434 additions & 559 deletions README.md

Large diffs are not rendered by default.

168 changes: 168 additions & 0 deletions README.md.gotmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# Application

Generic helm chart for applications which:

- are stateless
- creates only namespace scoped resources (e.g. it doesn't need CRB - Cluster Role Bindings)
- don't need privileged containers
- don't call the underlying Kubernetes API or use the underlying etcd as a database by defining custom resources
- run either as deployment, job or cronjob

## Installing the Chart

To install the chart with the release name `my-application` in namespace `test`:

```shell
helm repo add stakater https://stakater.github.io/stakater-charts
helm repo update
helm install my-application stakater/application --namespace test
```

## Uninstall the Chart

To uninstall the chart:

```shell
helm delete --namespace test my-application
```

{{ template "chart.valuesSection" . }}

{{ template "helm-docs.versionFooter" . }}

## Naming convention for ConfigMap, Secret, SealedSecret and ExternalSecret

Name format of ConfigMap, Secret, SealedSecret and ExternalSecret is `{{`{{ template "application.name" $ }}-{{ $nameSuffix }}`}}` then:

- `{{`{{ template "application.name" }}`}}` is a helper function that outputs `.Values.applicationName` if exist else return chart name as output
- `nameSuffix` is the each key in `secret.files`, `configMap.files`, `sealedSecret.files` and `externalSecret.files`

For example if we have following values file:

```yaml
applicationName: helloworld # {{`{{ template "application.name" $ }}`}}

configMap:
files:
config: # {{`{{ $nameSuffix }}`}}
key: value
```

then the configmap name will be named `helloworld-config`.

## Consuming environment variable in application chart

In order to use environment variable in deployment or cronjob, you will have to provide environment variable in *key/value* pair in `env` value. where key being environment variable key and value varies in different scenarios

- For simple key/value environment variable, just provide `value: <value>`

```yaml
env:
KEY:
value: MY_VALUE
```

- To get environement variable value from **ConfigMap**

Suppose we have a configmap created from application chart

```yaml
applicationName: my-application
configMap:
enabled: true
files:
application-config:
LOG: DEBUG
VERBOSE: v1
```

To get environment variable value from above created configmap, we will need to add following

```yaml
env:
APP_LOG_LEVEL:
valueFrom:
configMapKeyRef:
name: my-application-appication-config
key: LOG
```

To get all environment variables key/values from **ConfigMap**, where configmap key being key of environment variable and value being value

```yaml
envFrom:
application-config-env:
type: configmap
nameSuffix: application-config
```

You can either provide `nameSuffix` which means name added after prefix `<applicationName>-` or static name with `name` of configmap.

- To get environment variable value from **Secret**

Suppose we have secret created from application chart

```yaml
applicationName: my-application
secret:
enabled: true
files:
db-credentials:
PASSWORD: skljd#2Qer!!
USER: postgres
```

To get environment variable value from above created secret, we will need to add following

```yaml
env:
KEY:
valueFrom:
secretKeyRef:
name: my-application-db-credentials
key: USER
```

To get environement variable value from **Secret**, where secret key being key of environment variable and value being value

```yaml
envFrom:
database-credentials:
type: secret
nameSuffix: db-credentials
```
you can either provide `nameSuffix` which means name added after prefix `<applicationName>-` or static name with `name` of secret

**Note:** first key after `envFrom` is just used to uniquely identify different objects in `envFrom` block. Make sure to keep it unique and relevant

## Configuring probes

To disable liveness or readiness probe, set value of `enabled` to `false`.

```yaml
livenessProbe:
enabled: false
```

By default probe handler type is `httpGet`. You just need to override `port` and `path` as per your need.

```yaml
livenessProbe:
enabled: true
httpGet:
path: '/path'
port: 8080
```

In order to use `exec` handler, you can define field `livenessProbe.exec` in your values.yaml.

```yaml
livenessProbe:
enabled: true
exec:
command:
- cat
- /tmp/healthy
```
4 changes: 2 additions & 2 deletions application/templates/alertmanagerconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ metadata:
name: {{ template "application.name" . }}
namespace: {{ include "application.namespace" . }}
labels:
{{- include "application.labels" . | nindent 4 }}
{{- include "application.labels" $ | nindent 4 }}
{{ toYaml .Values.alertmanagerConfig.selectionLabels | indent 4 }}
spec:
{{- if .Values.alertmanagerConfig.spec.route }}
route:
{{ toYaml .Values.alertmanagerConfig.spec.route | indent 6 }}
{{- end -}}
{{- if .Values.alertmanagerConfig.spec.receivers }}
receivers:
receivers:
{{ toYaml .Values.alertmanagerConfig.spec.receivers | indent 6 }}
{{- end -}}
{{- if .Values.alertmanagerConfig.spec.inhibitRules }}
Expand Down
15 changes: 11 additions & 4 deletions application/templates/backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ metadata:
name: {{ printf "%s-backup" .Values.applicationName | trunc 63 | quote }}
namespace: {{ .Values.backup.namespace | default ( include "application.namespace" . ) | quote }}
labels:
{{- include "application.labels" . | nindent 4 }}
{{- include "application.labels" $ | nindent 4 }}
{{- if .Values.backup.additionalLabels }}
{{ toYaml .Values.backup.additionalLabels | indent 4 }}
{{- end }}
{{- if .Values.backup.annotations }}
annotations:
{{ toYaml .Values.backup.annotations | indent 4 }}
{{- end }}
spec:
labelSelector:
matchLabels:
app.kubernetes.io/part-of: {{ include "application.name" . }}
includedNamespaces:
- {{ include "application.namespace" . }}
defaultVolumesToRestic: {{ .Values.backup.defaultVolumesToRestic | default true }}
snapshotVolumes: {{ .Values.backup.snapshotVolumes | default true }}
defaultVolumesToRestic: {{ .Values.backup.defaultVolumesToRestic }}
snapshotVolumes: {{ .Values.backup.snapshotVolumes }}
storageLocation: {{ .Values.backup.storageLocation | quote }}
ttl: {{ .Values.backup.ttl | default "1h0m0s" }}
ttl: {{ .Values.backup.ttl }}
{{- if .Values.backup.includedResources }}
includedResources:
{{ toYaml .Values.backup.includedResources | indent 4 }}
Expand Down
4 changes: 2 additions & 2 deletions application/templates/certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: {{ template "application.name" . }}-certificate
namespace: {{ include "application.namespace" . }}
labels:
{{- include "application.labels" . | nindent 4 }}
{{- include "application.labels" $ | nindent 4 }}
{{- if .Values.certificate.additionalLabels }}
{{ toYaml .Values.certificate.additionalLabels | indent 4 }}
{{- end }}
Expand All @@ -23,7 +23,7 @@ spec:
subject:
{{ include "application.tplvalues.render" ( dict "value" .Values.certificate.subject "context" $ ) | indent 4 }}
commonName: {{ include "application.tplvalues.render" ( dict "value" .Values.certificate.commonName "context" $ ) }}
{{- if .Values.certificate.isCA }}
{{- if .Values.certificate.isCA }}
isCA: {{ .Values.certificate.isCA }}
{{- end }}
usages:
Expand Down
8 changes: 4 additions & 4 deletions application/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
labels:
{{- include "application.labels" . | nindent 4 }}
{{- include "application.labels" $ | nindent 4 }}
{{- if .Values.deployment.additionalLabels }}
{{ toYaml .Values.deployment.additionalLabels | indent 4 }}
{{- end }}
Expand All @@ -14,7 +14,7 @@ metadata:
{{- if .Values.deployment.annotations }}
{{ toYaml .Values.deployment.annotations | indent 4 }}
{{- end }}
{{- if .Values.deployment.reloadOnChange }}
{{- if .Values.deployment.reloadOnChange }}
reloader.stakater.com/auto: "true"
{{- end }}
name: {{ template "application.name" . }}
Expand Down Expand Up @@ -211,7 +211,7 @@ spec:
{{- toYaml .Values.deployment.startupProbe.grpc | nindent 12 }}
{{- end }}
{{- end }}
{{- if .Values.deployment.livenessProbe.enabled }}
{{- if .Values.deployment.livenessProbe.enabled }}
livenessProbe:
failureThreshold: {{ .Values.deployment.livenessProbe.failureThreshold }}
periodSeconds: {{ .Values.deployment.livenessProbe.periodSeconds }}
Expand All @@ -232,7 +232,7 @@ spec:
{{- toYaml .Values.deployment.livenessProbe.grpc | nindent 12 }}
{{- end }}
{{- end }}
{{- if .Values.deployment.readinessProbe.enabled }}
{{- if .Values.deployment.readinessProbe.enabled }}
readinessProbe:
failureThreshold: {{ .Values.deployment.readinessProbe.failureThreshold }}
periodSeconds: {{ .Values.deployment.readinessProbe.periodSeconds }}
Expand Down
2 changes: 1 addition & 1 deletion application/templates/endpointmonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: {{ template "application.name" . }}
namespace: {{ include "application.namespace" . }}
labels:
{{- include "application.labels" . | nindent 4 }}
{{- include "application.labels" $ | nindent 4 }}
{{- if .Values.endpointMonitor.additionalLabels }}
{{ toYaml .Values.endpointMonitor.additionalLabels | indent 4 }}
{{- end }}
Expand Down
21 changes: 11 additions & 10 deletions application/templates/externalsecrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ metadata:
namespace: {{ include "application.namespace" $ }}
labels:
{{- include "application.labels" $ | nindent 4 }}
{{- if $.Values.externalSecret.additionalLabels }}
{{ toYaml $.Values.externalSecret.additionalLabels | indent 4 }}
{{- end }}
{{- if $.Values.externalSecret.annotations }}
annotations:
{{ toYaml $.Values.externalSecret.annotations | indent 4 }}
{{- end }}
spec:
refreshInterval: {{ $.Values.externalSecret.refreshInterval }}
{{- if and (not $data.data) (not $data.dataFrom) }}
Expand All @@ -25,27 +32,21 @@ spec:
- extract:
{{ toYaml $data.dataFrom | indent 6 }}
{{- end }}
{{- if $data.secretStore }}
secretStoreRef:
name: {{ $data.secretStore.name }}
kind: {{ $data.secretStore.kind | default "SecretStore" }}
{{- else }}
secretStoreRef:
name: {{ $.Values.externalSecret.secretStore.name }}
kind: {{ $.Values.externalSecret.secretStore.kind | default "SecretStore" }}
{{- end}}
name: {{ default $.Values.externalSecret.secretStore.name ($data.secretStore).name }}
kind: {{ default $.Values.externalSecret.secretStore.kind ($data.secretStore).kind }}
target:
name: {{ template "application.name" $ }}-{{ $nameSuffix }}
template:
type: {{ $data.type | default "Opaque" }}
{{- if or $data.annotations $data.labels}}
metadata:
{{- if $data.annotations }}
annotations:
annotations:
{{ toYaml $data.annotations | indent 10 }}
{{- end }}
{{- if $data.labels }}
labels:
labels:
{{ toYaml $data.labels | indent 10 }}
{{- end }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion application/templates/forecastle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
name: {{ template "application.name" . }}
namespace: {{ include "application.namespace" . }}
labels:
{{- include "application.labels" . | nindent 4 }}
{{- include "application.labels" $ | nindent 4 }}
{{- if .Values.forecastle.additionalLabels }}
{{ toYaml .Values.forecastle.additionalLabels | indent 4 }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion application/templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
name: {{ template "application.name" . }}
namespace: {{ include "application.namespace" . }}
labels:
{{- include "application.labels" . | nindent 4 }}
{{- include "application.labels" $ | nindent 4 }}
{{- with .Values.autoscaling.additionalLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
Expand Down
Loading

0 comments on commit 31904e3

Please sign in to comment.