Skip to content

Commit e936842

Browse files
committed
[helm] Refactor validation warning and error checks
1 parent 0825d68 commit e936842

File tree

4 files changed

+102
-22
lines changed

4 files changed

+102
-22
lines changed

helm/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,37 @@ For how to build your local Fluss image and use it in Minikube refer to the
2828
Refer to the [official documentation](https://fluss.apache.org/docs/next/install-deploy/deploying-with-helm/#configuration-parameters)
2929
as well for configuration values.
3030

31-
We use the [`helm-unittest`](https://github.com/helm-unittest/helm-unittest) plugin for testing Fluss Helm charts.
31+
We use the [`helm-unittest`](https://github.com/helm-unittest/helm-unittest) plugin for testing Fluss Helm charts.
3232
You can run tests locally via:
3333

3434
```bash
3535
# From the /helm folder:
3636
docker run -ti --rm -v $(pwd):/apps helmunittest/helm-unittest .
3737
```
3838

39+
### Validation Checks
40+
41+
The chart runs the validation checks at install or upgrade time using templates in `_validate.tpl` file.
42+
43+
The warnings are printed to the user, but errors abort the deployment.
44+
45+
To add new validations, for example for a new feature:
46+
47+
1. Define `fluss.<feature>.validateWarning` or `fluss.<feature>.validateError` templates in the feature `_<feature>.tpl` template file.
48+
2. Add the corresponding `include` calls to `fluss.validateWarning` or `fluss.validateError` in `_validate.tpl` template file.
49+
50+
For example, for the `security` checks, include and update these methods in the `_validate.tpl` file:
51+
52+
```
53+
{{- define "fluss.validateWarning" -}}
54+
{{- include "fluss.security.validateWarning" . -}}
55+
{{- end -}}
56+
57+
{{- define "fluss.validateError" -}}
58+
{{- include "fluss.security.validateError" . -}}
59+
{{- end -}}
60+
```
61+
3962
## Contributing
4063

4164
Follow the [development section](#development) for local development.

helm/templates/NOTES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ CHART NAME: {{ .Chart.Name }}
2020
CHART VERSION: {{ .Chart.Version }}
2121
APP VERSION: {{ .Chart.AppVersion }}
2222

23-
{{ include "fluss.security.validateValues" . }}
23+
{{ include "fluss.validate" . }}

helm/templates/_security.tpl

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -170,33 +170,25 @@ Usage:
170170
{{- end -}}
171171

172172
{{/*
173-
Compile all warnings and errors into a single message.
173+
Collects security warning messages.
174174
Usage:
175-
include "fluss.security.validateValues" .
175+
include "fluss.security.validateWarning" .
176176
*/}}
177-
{{- define "fluss.security.validateValues" -}}
177+
{{- define "fluss.security.validateWarning" -}}
178+
{{- include "fluss.security.sasl.warnInternalUser" . -}}
179+
{{- end -}}
178180

181+
{{/*
182+
Collects security error messages.
183+
Usage:
184+
include "fluss.security.validateError" .
185+
*/}}
186+
{{- define "fluss.security.validateError" -}}
179187
{{- $errMessages := list -}}
180188
{{- $errMessages = append $errMessages (include "fluss.security.sasl.validateMechanisms" .) -}}
181189
{{- $errMessages = append $errMessages (include "fluss.security.sasl.validateClientPlainUsers" .) -}}
182-
183190
{{- $errMessages = without $errMessages "" -}}
184-
{{- $errMessage := join "\n" $errMessages -}}
185-
186-
{{- $warnMessages := list -}}
187-
{{- $warnMessages = append $warnMessages (include "fluss.security.sasl.warnInternalUser" .) -}}
188-
189-
{{- $warnMessages = without $warnMessages "" -}}
190-
{{- $warnMessage := join "\n" $warnMessages -}}
191-
192-
{{- if $warnMessage -}}
193-
{{- printf "\nVALUES WARNING:\n%s" $warnMessage -}}
194-
{{- end -}}
195-
196-
{{- if $errMessage -}}
197-
{{- printf "\nVALUES VALIDATION:\n%s" $errMessage | fail -}}
198-
{{- end -}}
199-
191+
{{- join "\n" $errMessages -}}
200192
{{- end -}}
201193

202194
{{/*

helm/templates/_validate.tpl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
{{/*
20+
Collects all warning messages from validation methods.
21+
Usage:
22+
include "fluss.validateWarning" .
23+
*/}}
24+
{{- define "fluss.validateWarning" -}}
25+
{{- include "fluss.security.validateWarning" . -}}
26+
{{- end -}}
27+
28+
{{/*
29+
Collects all error messages from validation methods.
30+
Usage:
31+
include "fluss.validateError" .
32+
*/}}
33+
{{- define "fluss.validateError" -}}
34+
{{- include "fluss.security.validateError" . -}}
35+
{{- end -}}
36+
37+
{{/*
38+
Global validation checks entry point.
39+
Collects all warnings and errors, prints warnings and fails on errors.
40+
Usage:
41+
include "fluss.validate" .
42+
*/}}
43+
{{- define "fluss.validate" -}}
44+
45+
{{- $warnMessages := list -}}
46+
{{- $warnMessages = append $warnMessages (include "fluss.validateWarning" .) -}}
47+
48+
{{- $warnMessages = without $warnMessages "" -}}
49+
{{- $warnMessage := join "\n" $warnMessages -}}
50+
51+
{{- $errMessages := list -}}
52+
{{- $errMessages = append $errMessages (include "fluss.validateError" .) -}}
53+
54+
{{- $errMessages = without $errMessages "" -}}
55+
{{- $errMessage := join "\n" $errMessages -}}
56+
57+
{{- if $warnMessage -}}
58+
{{- printf "\nVALUES WARNING:\n%s" $warnMessage -}}
59+
{{- end -}}
60+
61+
{{- if $errMessage -}}
62+
{{- printf "\nVALUES VALIDATION:\n%s" $errMessage | fail -}}
63+
{{- end -}}
64+
65+
{{- end -}}

0 commit comments

Comments
 (0)