Skip to content

Commit

Permalink
feat: ✨ input validation using schema
Browse files Browse the repository at this point in the history
  • Loading branch information
mloiseleur committed Sep 16, 2024
1 parent 2dc2253 commit cf703c7
Show file tree
Hide file tree
Showing 13 changed files with 1,861 additions and 337 deletions.
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
### More

- [ ] Yes, I updated the tests accordingly
- [ ] Yes, I updated the schema accordingly
- [ ] Yes, I ran `make test` and all the tests passed

<!--
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ jobs:
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Check if values schema is up-to-date
uses: losisin/helm-values-schema-json-action@v1
with:
input: traefik/values.yaml
output: traefik/values.schema.json
fail-on-diff: true

- name: Lint
run: make lint

Expand Down
13 changes: 13 additions & 0 deletions .schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Required
input:
- traefik/values.yaml

draft: 2020
indent: 4
output: traefik/values.schema.json

schemaRoot:
id: https://traefik.io/traefik-helm-chart.schema.json
title: Traefik Proxy Helm Chart
description: The Cloud Native Application Proxy
additionalProperties: true
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ docs:
test-install:
docker run ${DOCKER_ARGS} --network=host --env GIT_SAFE_DIR="true" --entrypoint /bin/sh --rm -v $(CURDIR):/charts -v $(HOME)/.kube:/root/.kube -w /charts $(IMAGE_CHART_TESTING) /charts/hack/ct.sh install


# Requires to install schema generation plugin beforehand
# $ helm plugin install https://github.com/losisin/helm-values-schema-json.git
schema:
helm schema

changelog:
@echo "== Updating Changelogs..."
@docker run -it --rm -v $(CURDIR):/data $(IMAGE_HELM_CHANGELOG)
Expand Down
72 changes: 7 additions & 65 deletions traefik/Guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,77 +4,19 @@ This document outlines the guidelines for developing, managing and extending the

This Helm Chart is documented using field description from comments with [helm-docs](https://github.com/norwoodj/helm-docs).

Optionality
All non-critical features (Features not mandatory to starting Traefik) in the helm chart must be optional. All non-critical features should be disabled (commented out) in the values.yaml file. All optional non-critical features should be disabled (commented out) in the values.yaml file, and have a comment # (Optional) in the line above. This allows minimal configuration, and ease of extension.
It comes with a JSON schema generated from values with [helm schema](https://github.com/losisin/helm-values-schema-json) plugin.

## Feature Example

```yaml
image:
# -- Traefik image host registry
registry: docker.io
logs:
general:
# -- Set [logs format](https://doc.traefik.io/traefik/observability/logs/#format)
format: # @schema enum:["common", "json", null]; type:[string, null]; default: "common"
```
This feature is expected and therefore is defined clearly in the values.yaml file.
## Optional Feature Example
```yaml
# storage:
# controlNode:
# type: emptyDir
```

This feature is optional, non-critical, and therefore is commented out by default in the values.yaml file.

To allow this, template blocks that use this need to recursively test for existence of values before using them:

```yaml
{{- if .Values.storage}}
{{- if .Values.storage.controlNode }}
//code
{{ .Values.storage.controlNode.type }}
{{- end }}
{{- end }}
```

The non-critical feature defaults should be populated so that they can be enabled by simply uncommenting the section in the values.yaml file.

## Optional Non-Critical Feature Example

```yaml
# storage:
# controlNode:
# type: emptyDir
# # (Optional)
# # volume: 1Gi
```

The volume option is clearly optional, and non-critical. It is commented out (apart from the storage section comment block), and is also preceded by a comment of # (Optional) in the preceding line. This facilitates configuration, when the storage section is uncommented, the optional features are still disabled by default.

Similar to non-critical features, these options need to be tested for existence before use in the template.

Note
There can be optional values in critical features. These should just be added as an uncommented non-critical feature:

```yaml
image:
name: traefik
tag: 2.0.0
# (Optional)
# pullPolicy: IfNotPresent
```

Also, the first value under the primary value key does not require an optional comment:

```yaml
# ports:
# http: 80
# # (Optional)
# # https: 443
```

This is because if the main subkey is not defined, the entirety of the feature is optional.
Documention is on the first comment, starting with `# --`
Specific instructions for schema, when needed, are done with the inline comment starting with `# @schema`.

## Whitespace

Expand Down
Loading

0 comments on commit cf703c7

Please sign in to comment.