Skip to content

Commit

Permalink
🐛 Fix error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Franckrst committed Feb 11, 2024
1 parent 156755c commit f4dc326
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ a [JSONSchema](https://json-schema.org/) with the Helm `pre-install` & `pre-upgr
1. Copy the `example/templates/tests/helm-values-validator.yaml` file to your Helm stack.
2. Add your `schema.json` to the root of your Helm chart (same level as the values.yaml).
3. Install the Helm chart with the `helm install` command.
4. (Optional) Convert your `values.yaml` file to `JSONSchema` on [jsonformater.org](https://jsonformatter.org/yaml-to-jsonschema)
4. (Optional) Convert your `values.yaml` file to `JSONSchema`
on [jsonformater.org](https://jsonformatter.org/yaml-to-jsonschema)

## 📝 Logs

To see the validation error messages, you can use the following commands:

```shell
# Logs
kubectl logs helm-values-validator-release-name
kubectl logs release-name-helm-values-validator

# Error messages
kubectl get pod -n demo-test test-demo-helm-values-validator -o go-template="{{range .status.containerStatuses}}{{.state.terminated.message}}{{end}}"
kubectl get pod release-name-helm-values-validator -o go-template="{{range .status.containerStatuses}}{{.state.terminated.message}}{{end}}"
```

## 🧑‍🔧 Manual execution
Expand Down
2 changes: 1 addition & 1 deletion exemple/templates/tests/helm-values-validator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
spec:
containers:
- name: helm-values-validator
image: franckrst/helm-values-validator:0.0.0-alpha
image: franckrst/helm-values-validator:0.0.1
env:
- name: VALUES_FILE
value: /values.json
Expand Down
3 changes: 3 additions & 0 deletions exemple/values-invalide.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
line:
- "zaeeae"
country: "12France"
2 changes: 1 addition & 1 deletion exemple/values.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
line:
- "zaeeae"
country: "12France"
country: "France"
10 changes: 5 additions & 5 deletions validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const _tryCatch = (fnc, message) => {
try {
fnc();
} catch (e) {
console.error(message);
console.error(message.replace('%E', e.message));
process.exit(1);
}
}
Expand All @@ -25,16 +25,16 @@ if (!process.env.VALUES_FILE) {
// -- Load Files
let valuesFile, schemaFile;
_tryCatch(() => valuesFile = fs.readFileSync(process.env.VALUES_FILE).toString(),
`[ERR] Can't read values file "${process.env.VALUES_FILE}" (${e.message}).`.red);
`[ERR] Can't read values file "${process.env.VALUES_FILE}" (%E).`.red);
_tryCatch(() => schemaFile = fs.readFileSync(process.env.SCHEMA_FILE).toString(),
`[ERR] Can't read values file "${process.env.SCHEMA_FILE}" (${e.message}).`.red);
`[ERR] Can't read values file "${process.env.SCHEMA_FILE}" (%E).`.red);

// -- Parse Files
let values, schema;
_tryCatch(() => values = JSON.parse(valuesFile),
`[ERR] Can't parse file "${process.env.VALUES_FILE}" (${e.message}).`.red);
`[ERR] Can't parse file "${process.env.VALUES_FILE}" (%E).`.red);
_tryCatch(() => schema = JSON.parse(schemaFile),
`[ERR] Can't parse file "${process.env.SCHEMA_FILE}" (${e.message}).`.red);
`[ERR] Can't parse file "${process.env.SCHEMA_FILE}" (%E).`.red);
console.log(`Schema : \n`.blue, JSON.stringify(schema));
console.log(`Values : \n`.blue, JSON.stringify(values));

Expand Down

0 comments on commit f4dc326

Please sign in to comment.