Skip to content

Commit c782da6

Browse files
desaintmartinwgiddens
authored andcommitted
Guidelines: set matchLabels as being mandatory (helm#7692)
* Guidelines: set matchLabels as being mandatory. Signed-off-by: Cédric de Saint Martin <[email protected]> * fixup! Guidelines: set matchLabels as being mandatory. Signed-off-by: Cédric de Saint Martin <[email protected]> * fixup! fixup! Guidelines: set matchLabels as being mandatory. Signed-off-by: Cédric de Saint Martin <[email protected]> * Update guidelines: mention DaemonSets as well. Signed-off-by: Cédric de Saint Martin <[email protected]> * Review guidelines: be more precise + specify upgrade Signed-off-by: Cédric de Saint Martin <[email protected]> * Review guidelines: fix typos, add persistence paragraph and do not repeat component part. Signed-off-by: Cédric de Saint Martin <[email protected]> * Review guidelines: add PVC paragraph. Signed-off-by: Cédric de Saint Martin <[email protected]> * Fix spelling/typos Signed-off-by: Reinhard Nägele <[email protected]> * Fix incorrect typo fix Signed-off-by: Reinhard Nägele <[email protected]>
1 parent 9e0d1c7 commit c782da6

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

REVIEW_GUIDELINES.md

+56-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Stable charts should not depend on charts in incubator.
3333

3434
## Names and Labels
3535

36-
Resources and labels should follow some conventions. The standard resource metadata should be this:
36+
### Metadata
37+
Resources and labels should follow some conventions. The standard resource metadata (`metadata.labels` and `spec.template.metadata.labels`) should be this:
3738

3839
```yaml
3940
name: {{ template "myapp.fullname" . }}
@@ -44,8 +45,41 @@ labels:
4445
heritage: {{ .Release.Service }}
4546
```
4647
48+
If a chart has multiple components, a `component` label should be added (e. g. `component: server`). The resource name should get the component as suffix (e. g. `name: {{ template "myapp.fullname" . }}-server`).
49+
4750
Note that templates have to be namespaced. With Helm 2.7+, `helm create` does this out-of-the-box. The `app` label should use the `name` template, not `fullname` as is still the case with older charts.
4851

52+
### Deployments, StatefulSets, DaemonSets Selectors
53+
54+
`spec.selector.matchLabels` must be specified should follow some conventions. The standard selector should be this:
55+
56+
```yaml
57+
selector:
58+
matchLabels:
59+
app: {{ template "myapp.name" . }}
60+
release: {{ .Release.Name }}
61+
```
62+
63+
If a chart has multiple components, a `component` label should be added to the selector (see above).
64+
65+
`spec.selector.matchLabels` defined in `Deployments`/`StatefulSets`/`DaemonSets` `>=v1/beta2` **must not** contain `chart` label or any label containing a version of the chart, because the selector is immutable.
66+
The chart label string contains the version, so if it is specified, whenever the the Chart.yaml version changes, Helm's attempt to change this immutable field would cause the upgrade to fail.
67+
68+
#### Fixing Selectors
69+
70+
##### For Deployments, StatefulSets, DaemonSets apps/v1beta1 or extensions/v1beta1
71+
72+
- If it does not specify `spec.selector.matchLabels`, set it
73+
- Remove `chart` label in `spec.selector.matchLabels` if it exists
74+
- Bump patch version of the Chart
75+
76+
##### For Deployments, StatefulSets, DaemonSets >=apps/v1beta2
77+
78+
- Remove `chart` label in `spec.selector.matchLabels` if it exists
79+
- Bump major version of the Chart as it is a breaking change
80+
81+
### Service Selectors
82+
4983
Label selectors for services must have both `app` and `release` labels.
5084

5185
```yaml
@@ -54,7 +88,26 @@ selector:
5488
release: {{ .Release.Name }}
5589
```
5690

57-
If a chart has multiple components, a `component` label should be added (e. g. `component: server`). The resource name should get the component as suffix (e. g. `name: {{ template "myapp.fullname" . }}-server`). The `component` label must be added to label selectors as well.
91+
If a chart has multiple components, a `component` label should be added to the selector (see above).
92+
93+
### Persistence Labels
94+
95+
### StatefulSet
96+
97+
In case of a `Statefulset`, `spec.volumeClaimTemplates.metadata.labels` must have both `app` and `release` labels, and **must not** contain `chart` label or any label containing a version of the chart, because `spec.volumeClaimTemplates` is immutable.
98+
99+
```yaml
100+
labels:
101+
app: {{ template "myapp.name" . }}
102+
release: {{ .Release.Name }}
103+
```
104+
105+
If a chart has multiple components, a `component` label should be added to the selector (see above).
106+
107+
### PersistentVolumeClaim
108+
109+
In case of a `PersistentVolumeClaim`, unless special needs, `matchLabels` should not be specified
110+
because it would prevent automatic `PersistentVolume` provisioning.
58111

59112
## Formatting
60113

@@ -269,7 +322,7 @@ spec:
269322
270323
We officially support compatibility with the current and the previous minor version of Kubernetes. Generated resources should use the latest possible API versions compatible with these versions. For extended backwards compatibility conditional logic based on capabilities may be used (see [built-in objects](https://github.com/helm/helm/blob/master/docs/chart_template_guide/builtin_objects.md)).
271324
272-
## Kubernetes Native Workloads.
325+
## Kubernetes Native Workloads
273326
274327
While reviewing Charts that contain workloads such as [Deployments](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/), [StatefulSets](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/), [DaemonSets](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) and [Jobs](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/) the below points should be considered. These are to be seen as best practices rather than strict enforcement.
275328

0 commit comments

Comments
 (0)