Skip to content

Commit 4eae9ec

Browse files
committed
HIP: warn template function
Signed-off-by: Philipp Stehle <[email protected]>
1 parent 0158df7 commit 4eae9ec

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

hips/hip-9999.md

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
hip: 9999
3+
title: "Add `warn` template function"
4+
authors: ["Philipp Stehle <[email protected]>"]
5+
created: "2022-12-09"
6+
type: "feature"
7+
status: "draft"
8+
---
9+
10+
## Abstract
11+
12+
When authoring charts it can be useful to warn users, when they deviate from best practices.
13+
E.g. when using a deprecated value or using the `latest` tag for images.
14+
15+
There are already means to do this in Helm, for example by using the `NOTES.txt` feature, but they all come with drawbacks.
16+
Also, as long as there is no standard way to produce warnings, it is hard to build tools around this.
17+
18+
This HIP proposes the addition of a `warn` template function, that Chart authors can use to signal warnings to Helm.
19+
It also includes several proposals of how Helm could make this available to the Chart consumers.
20+
21+
## Motivation
22+
23+
Some reasons why chart authors might want to produce warnings:
24+
25+
- They have deprecated functionality, which they plan to remove later. E.g. we have recently renamed our `timeout` value to `timeoutSeconds`. Until the next major release we, will fallback to `timeout` if `timeoutSeconds` is not present. To ensure a smooth transition to the next major release, it would be helpful if we could warn our users ahead of time.
26+
- For backward compatibility, they allow that continue to allow setting they know are sub-optimal.
27+
- To ease non-productive (dev) setups, some settings that should not be used for productive environment might be allowed anyway, but produce a warning. E.g. using a replica count of `1`, which of course can't be used, if high availability is a concern.
28+
29+
Some ways how users could want to consume warnings:
30+
31+
- Via cli output
32+
- In automated PR validation (validation fails, if the PR introduces a new warning)
33+
34+
## Specification
35+
36+
### Creating Warnings
37+
38+
Add a new template function called `warn`, with one of the following semantics (looking for feedback, which one we should go for):
39+
40+
1. `warn` takes a single string argument, describing the Warning.
41+
1. `warn` takes a two arguments: a category (`depreaction`, `security`, `misc`, etc.) and a description:
42+
The categories would be pre-defined by Helm
43+
1. `warn` takes 1 or more arguments and interprets the first argument as a `printf` style string.
44+
1. `warn` takes 2 or more arguments, combining alternative 2 and 3.
45+
46+
### Consuming Warnings
47+
48+
There can be multiple ways to consume warnings for users, the most straight forward would be printing them to the console.
49+
50+
Other ways could be:
51+
52+
- add a `--fail-on-warning` flag to `template`, `install`, `upgrade` and `lint` (causing helm to exit with non-zero on warnings)
53+
- add a `--warning-output` flag that would produce a machine readable (e.g. `yaml` or `json`) collection of warning on the filesystem for further processing.
54+
- Expose the warnings to SDK users as Go-structs
55+
56+
De-duplication: Helm could detect the same warning occuring multiple times and de-duplicate them, e.g. the following template:
57+
58+
```plain
59+
{{ warn "my warning" }}
60+
{{ warn "my warning" }}
61+
```
62+
63+
Would produce the following output:
64+
65+
```plain
66+
[WARNING]: my warning (occurred 2 times)
67+
```
68+
69+
Also, in the long term we should consolidate all other sources of warnings, e.g.:
70+
71+
- [Usage of deprecated Charts](https://github.com/helm/helm/blob/v3.10.2/cmd/helm/install.go#L227-L229)
72+
- Usage of depreacted Kubernetes API object
73+
- Helm Lint warnings
74+
75+
and provide them through a common interface (i.e. in machine readable form).
76+
77+
## Backwards compatibility
78+
79+
Following [HIP-0004](https://github.com/helm/community/blob/main/hips/hip-0004.md#specification)
80+
81+
- exported Go APIs will remain compatible:
82+
This might be of concern, we just need to keep it in mind while implementing. Should be possible to do this non-breaking.
83+
- CLI commands and flags:
84+
No existing flags will be changed.
85+
- CLI output:
86+
Will not change, unless the `warn` feature is used by a chart author and therefore actively opting into the feature.
87+
- File formats:
88+
No change required.
89+
- Charts:
90+
No change required.
91+
- Templates (commands, functions, syntax, and variables):
92+
Only adding new functionality
93+
94+
## Security implications
95+
96+
As this allows for automatic scanning for (security) warnings, a malicious actor might be enabled to automatically scan for Helm Charts with flaws, putting users at risk. On the other hand, it also enables to users to do the same and therefore might even increase security.
97+
98+
## How to teach this
99+
100+
For chart authors: Document the `warn` funcion with example use-cases.
101+
For chart consumers: Document how to consume warnings.
102+
103+
## Reference implementation
104+
105+
[PoC PR to helm/helm](https://github.com/helm/helm/pull/11619)
106+
107+
## Rejected ideas
108+
109+
- Use `NOTES.txt` to produce warnings. This has several drawbacks:
110+
- Harder to consume for users, as there is no standardized way to transport warnings.
111+
- Harder to consume in automation (a CI job).
112+
- Notes of sub-chart are not rendered (at least not by default).
113+
- Call the template function `warning`: There is already the [`fail`](https://helm.sh/docs/chart_template_guide/function_list/#fail) function, so `warn` seems to be more consistent.
114+
115+
## Open issues
116+
117+
Let me know
118+
119+
## References
120+
121+
A collection of URLs or materials used as references through the HIP.

0 commit comments

Comments
 (0)