Skip to content

Commit

Permalink
feat: generated Helm documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Zadkiel AHARONIAN <hello@zadkiel.fr>
  • Loading branch information
aslafy-z committed Jul 25, 2024
1 parent 63b7619 commit 27ef4ff
Show file tree
Hide file tree
Showing 24 changed files with 1,337 additions and 983 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,17 @@ 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
uses: losisin/helm-docs-github-action@v1
with:
output-file: README.md
template-files: README.md.gotmpl
fail-on-diff: true
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/norwoodj/helm-docs
rev: v1.14.2
hooks:
- id: helm-docs-built
args:
- --chart-to-generate=application
- --template-files=./README.md.gotmpl
- --output-file=./../README.md
- --sort-values-order=file
994 changes: 435 additions & 559 deletions README.md

Large diffs are not rendered by default.

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

# 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: 12 additions & 3 deletions application/templates/backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,25 @@ kind: Backup
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 }}
{{- 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
2 changes: 1 addition & 1 deletion application/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ metadata:
name: {{ template "application.name" . }}
namespace: {{ include "application.namespace" . }}
labels:
{{- include "application.labels" . | nindent 4 }}
{{- include "application.labels" $ | nindent 4 }}
{{- if .Values.ingress.additionalLabels }}
{{ toYaml .Values.ingress.additionalLabels | indent 4 }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion application/templates/networkpolicy.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.networkPolicy.additionalLabels }}
{{ toYaml .Values.networkPolicy.additionalLabels | indent 4 }}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion application/templates/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
labels:
{{- include "application.labels" . | nindent 4 }}
{{- include "application.labels" $ | nindent 4 }}
name: {{ template "application.name" . }}
namespace: {{ include "application.namespace" . }}
spec:
Expand Down
Loading

0 comments on commit 27ef4ff

Please sign in to comment.