@rophy123/helmtest 2.0.1 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +7 -0
- package/README.md +12 -12
- package/lib/helmtest.js +24 -26
- package/package.json +1 -1
package/Makefile
ADDED
package/README.md
CHANGED
|
@@ -74,15 +74,15 @@ helmtest currently only expose one method: `helmtest.renderTemplate(options)`.
|
|
|
74
74
|
|
|
75
75
|
`options` is a object with option names, descriptions and defaults as below:
|
|
76
76
|
|
|
77
|
-
| Option | Description | Default
|
|
78
|
-
| -------------------- | ----------------------------------------------------------------------------------- |
|
|
79
|
-
| chartDir | Path to chart, the `CHART` arg in helm CLI: `helm template [NAME] [CHART] [flags]`. | `'.'`
|
|
80
|
-
| releaseName | Release name, the `NAME` arg in helm CLI: `helm template [NAME] [CHART] [flags]`. | `'release-name'`
|
|
81
|
-
| values |
|
|
82
|
-
| valuesFiles |
|
|
83
|
-
| extraHelmArgs |
|
|
84
|
-
| helmBinary | Path to helm binary. | `process.env.HELM_BINARY
|
|
85
|
-
| loadYaml | if `false`, will return rendered template as raw string instead of js object. | `true`
|
|
86
|
-
| kubeconformEnabled | if `true`, will pass rendered template to kubeconform CLI to validate schema. | `process.env.KUBECONFORM_ENABLED
|
|
87
|
-
| kubeconformBinary | Path to kubeconform binary. | `process.env.KUBECONFORM_BINARY
|
|
88
|
-
|
|
|
77
|
+
| Option | Description | Default |
|
|
78
|
+
| -------------------- | ----------------------------------------------------------------------------------- | --------------------------------------------------- |
|
|
79
|
+
| chartDir | Path to chart, the `CHART` arg in helm CLI: `helm template [NAME] [CHART] [flags]`. | `'.'` |
|
|
80
|
+
| releaseName | Release name, the `NAME` arg in helm CLI: `helm template [NAME] [CHART] [flags]`. | `'release-name'` |
|
|
81
|
+
| values | Map of chart values to set. | `{}` |
|
|
82
|
+
| valuesFiles | Paths to additional values.yaml. | `[]` |
|
|
83
|
+
| extraHelmArgs | Extra args to pass to helm CLI, e.g. `--timeout=5s` | `[]` |
|
|
84
|
+
| helmBinary | Path to helm binary. | `process.env.HELM_BINARY \|\| 'helm'` |
|
|
85
|
+
| loadYaml | if `false`, will return rendered template as raw string instead of js object. | `true` |
|
|
86
|
+
| kubeconformEnabled | if `true`, will pass rendered template to kubeconform CLI to validate schema. | `process.env.KUBECONFORM_ENABLED \|\| false` |
|
|
87
|
+
| kubeconformBinary | Path to kubeconform binary. | `process.env.KUBECONFORM_BINARY \|\| 'kubeconform'` |
|
|
88
|
+
| kubeconformArgs | Args to pass to kubeconform CLI. Will append `process.env.KUBECONFORM_EXTRA_ARGS`. | `['-strict','-ignore-missing-schemas','-summary']` |
|
package/lib/helmtest.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const fs = require('fs');
|
|
2
2
|
const path = require('path');
|
|
3
3
|
const util = require('util');
|
|
4
|
-
const
|
|
4
|
+
const execFile = util.promisify(require('node:child_process').execFile);
|
|
5
5
|
const yaml = require('js-yaml');
|
|
6
6
|
const debug = require('debug')('helmtest');
|
|
7
7
|
const Readable = require('stream').Readable;
|
|
@@ -26,8 +26,13 @@ async function renderTemplate(options = {}) {
|
|
|
26
26
|
process.env.KUBECONFORM_ENABLED || false;
|
|
27
27
|
options.kubeconformBinary = options.kubeconformBinary ||
|
|
28
28
|
process.env.KUBECONFORM_BINARY || 'kubeconform';
|
|
29
|
-
options.
|
|
30
|
-
|
|
29
|
+
options.kubeconformArgs = options.kubeconformArgs ||
|
|
30
|
+
['-strict', '-ignore-missing-schemas', '-summary'];
|
|
31
|
+
|
|
32
|
+
if (process.env.KUBECONFORM_EXTRA_ARGS) {
|
|
33
|
+
const kcExtraArgs = process.env.KUBECONFORM_EXTRA_ARGS.split(' ');
|
|
34
|
+
options.kubeConformArgs.concat(kcExtraArgs);
|
|
35
|
+
}
|
|
31
36
|
|
|
32
37
|
debug(`options: ${JSON.stringify(options)}`);
|
|
33
38
|
|
|
@@ -35,7 +40,8 @@ async function renderTemplate(options = {}) {
|
|
|
35
40
|
fs.statSync(options.chartDir);
|
|
36
41
|
|
|
37
42
|
// Now construct the args.
|
|
38
|
-
const helmCmd =
|
|
43
|
+
const helmCmd = options.helmBinary;
|
|
44
|
+
const helmArgs = ['template'];
|
|
39
45
|
|
|
40
46
|
const valueKeys = Object.keys(options.values);
|
|
41
47
|
const valuePairs = [];
|
|
@@ -43,7 +49,7 @@ async function renderTemplate(options = {}) {
|
|
|
43
49
|
valuePairs.push(`${key}=${options.values[key]}`);
|
|
44
50
|
});
|
|
45
51
|
if (valuePairs.length > 0) {
|
|
46
|
-
|
|
52
|
+
helmArgs.push('--set', valuePairs.join(','));
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
if (options.valuesFiles) {
|
|
@@ -52,8 +58,7 @@ async function renderTemplate(options = {}) {
|
|
|
52
58
|
options.valuesFiles;
|
|
53
59
|
valuesFiles.forEach((valuesFile) => {
|
|
54
60
|
fs.statSync(valuesFile);
|
|
55
|
-
|
|
56
|
-
helmCmd.push(valuesFile);
|
|
61
|
+
helmArgs.push('-f', valuesFile);
|
|
57
62
|
});
|
|
58
63
|
}
|
|
59
64
|
|
|
@@ -66,35 +71,28 @@ async function renderTemplate(options = {}) {
|
|
|
66
71
|
fs.statSync(filePath);
|
|
67
72
|
// Note: get the abs template file path to chek it actually exists,
|
|
68
73
|
// `helm template` command expects relative path from chartDir.
|
|
69
|
-
|
|
70
|
-
helmCmd.push(templateFile);
|
|
74
|
+
helmArgs.push('--show-only', templateFile);
|
|
71
75
|
});
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
helmCmd.push(options.releaseName);
|
|
79
|
-
helmCmd.push(options.chartDir);
|
|
80
|
-
|
|
81
|
-
const command = helmCmd.join(' ');
|
|
82
|
-
debug(`command: ${command}`);
|
|
83
|
-
const helmOutput = await exec(command);
|
|
78
|
+
options.extraHelmArgs.forEach((arg) => helmArgs.push(arg));
|
|
79
|
+
helmArgs.push(options.releaseName, options.chartDir);
|
|
80
|
+
debug(`helm command: ${helmCmd} ${helmArgs.join(' ')}`);
|
|
81
|
+
const helmOutput = await execFile(helmCmd, helmArgs);
|
|
84
82
|
|
|
85
83
|
if (options.kubeconformEnabled) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
debug(`kcCommand: ${kcCommand}`);
|
|
91
|
-
const kcProc = exec(kcCommand);
|
|
84
|
+
const kcCmd = options.kubeconformBinary;
|
|
85
|
+
const kcArgs = options.kubeconformArgs;
|
|
86
|
+
debug(`kubeconform command: ${kcCmd} ${kcArgs.join(' ')}`);
|
|
87
|
+
const kcProc = execFile(kcCmd, kcArgs);
|
|
92
88
|
const piper = new Readable();
|
|
93
89
|
piper.pipe(kcProc.child.stdin);
|
|
94
90
|
piper.push(helmOutput.stdout);
|
|
95
91
|
piper.push(null);
|
|
96
92
|
try {
|
|
97
|
-
await kcProc;
|
|
93
|
+
const kcResult = await kcProc;
|
|
94
|
+
if (kcResult.stdout) debug(kcResult.stdout);
|
|
95
|
+
if (kcResult.stderr) debug(kcResult.stderr);
|
|
98
96
|
} catch (err) {
|
|
99
97
|
if (err.stdout) console.error(err.stdout);
|
|
100
98
|
if (err.stderr) console.error(err.stderr);
|