File tree 1 file changed +83
-2
lines changed
content/en/docs/chart_best_practices
1 file changed +83
-2
lines changed Original file line number Diff line number Diff line change @@ -49,8 +49,6 @@ as the template names are automatically defined as per this best practice.
49
49
50
50
## Formatting Templates
51
51
52
- Templates should be indented using _ two spaces_ (never tabs).
53
-
54
52
Template directives should have whitespace after the opening braces and before
55
53
the closing braces:
56
54
@@ -91,8 +89,91 @@ app.kubernetes.io/instance: {{ .Release.Name }}
91
89
apiVersion : v1
92
90
` ` `
93
91
92
+ Template logic should align indentation with associated content.
93
+
94
+ Correct:
95
+
96
+ ` ` ` yaml
97
+ metadata :
98
+ annotations :
99
+ {{- if .Values.foo }}
100
+ foo : true
101
+ {{- end }}
102
+ bar : true
103
+ {{- with .Values.extraAnnotations }}
104
+ {{- . | toYaml | nindent 4 }}
105
+ {{- end }}
106
+ ```
107
+
108
+ Incorrect:
109
+
110
+ ``` yaml
111
+ metadata :
112
+ annotations :
113
+ {{- if .Values.foo }}
114
+ foo : true
115
+ {{- end }}
116
+ bar : true
117
+ {{- with .Values.extraAnnotations }}
118
+ {{- . | toYaml | indent 4 }}
119
+ {{- end }}
120
+ ```
121
+
122
+ To align templates logic with associated content, the ` nindent ` function
123
+ together with left whitespace chomping is often required. ` nindent ` works
124
+ exactly like ` indent ` but prefixes a new line that can compensate for our left
125
+ whitespace chomping.
126
+
127
+ Correct:
128
+
129
+ ``` yaml
130
+ metadata :
131
+ annotations :
132
+ foo : true
133
+ {{- with .Values.extraAnnotations }}
134
+ {{- . | toYaml | nindent 4 }}
135
+ {{- end }}
136
+ ```
137
+
138
+ Incorrect:
139
+
140
+ ``` yaml
141
+ metadata :
142
+ annotations :
143
+ foo : true
144
+ {{- with .Values.extraAnnotations }}
145
+ {{- . | toYaml | indent 4 }}
146
+ {{- end }}
147
+ ```
148
+
94
149
## Whitespace in Generated Templates
95
150
151
+ Generated content should be indented with increments of _ two spaces_ .
152
+
153
+ Correct:
154
+
155
+ ``` yaml
156
+ apiVersion : batch/v1
157
+ kind : Job
158
+ metadata :
159
+ name : example
160
+ labels :
161
+ first : first
162
+ second : second
163
+ ` ` `
164
+
165
+ Incorrect:
166
+
167
+ ` ` ` yaml
168
+ apiVersion : batch/v1
169
+ kind : Job
170
+ metadata :
171
+ name : example
172
+ labels :
173
+ first : first
174
+ second : second
175
+ ` ` `
176
+
96
177
It is preferable to keep the amount of whitespace in generated templates to a
97
178
minimum. In particular, numerous blank lines should not appear adjacent to each
98
179
other. But occasional empty lines (particularly between logical sections) is
You can’t perform that action at this time.
0 commit comments