Skip to content

Commit d78fc4b

Browse files
committed
Fix omitting default values
Copy the whole chart expect templates (not only values.yaml), because other plugins can take values from other files
1 parent 6732e54 commit d78fc4b

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

e2e-tests/charts/one-service/deno-templates/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ interface ChartContext {
66
values: {
77
serviceName?: string
88
selector: Record<string, string>
9+
annotations: Record<string, string>
910
}
1011
}
1112

@@ -20,6 +21,7 @@ export default function oneService(c: ChartContext) {
2021
apiVersion: "v1",
2122
metadata: {
2223
name: c.values.serviceName || c.release.name,
24+
annotations: c.values.annotations,
2325
},
2426
spec: {
2527
selector: c.values.selector,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
annotations:
2+
default-annotation: default-value

e2e-tests/e2e.test.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ async function runHelmDeno(args: string[]) {
4545
return await run([helmDenoBin, ...args])
4646
}
4747

48+
async function assertYamlParsable(yamlFileContent: string) {
49+
try {
50+
await yaml.parseAll(yamlFileContent)
51+
} catch (err) {
52+
throw new Error(`Cloud parse yaml context ${err} ${yamlFileContent}`)
53+
}
54+
}
55+
4856
Deno.test({
4957
name: "should successfuly run `helm deno template` with deno chart",
5058
async fn() {
@@ -65,6 +73,9 @@ Deno.test({
6573
kind: "Service",
6674
metadata: {
6775
name: "my-release-name",
76+
annotations: {
77+
"default-annotation": "default-value",
78+
},
6879
},
6980
spec: {
7081
ports: [
@@ -117,7 +128,6 @@ Deno.test(
117128
stdout.replaceAll(helmPluginDir, ""),
118129
`\
119130
==> Linting /e2e-tests/charts/one-service
120-
[INFO] values.yaml: file does not exist
121131
[WARNING] templates/: directory not found
122132
123133
1 chart(s) linted, 0 chart(s) failed
@@ -220,6 +230,9 @@ Deno.test({
220230
kind: "Service",
221231
metadata: {
222232
name: "my-release-name",
233+
annotations: {
234+
"default-annotation": "default-value",
235+
},
223236
},
224237
spec: {
225238
ports: [
@@ -584,6 +597,9 @@ Deno.test({
584597
kind: "Service",
585598
metadata: {
586599
name: "my-release-name",
600+
annotations: {
601+
"default-annotation": "default-value",
602+
},
587603
},
588604
spec: {
589605
ports: [
@@ -650,7 +666,7 @@ Deno.test({
650666
"should successfuly run `helm deno template` with remote deno chart (with --repo option)",
651667
ignore: !runAllTests,
652668
async fn() {
653-
const { status } = await runHelmDeno([
669+
const { status, stdout, stderr } = await runHelmDeno([
654670
"template",
655671
"ingress",
656672
"nginx-ingress",
@@ -660,7 +676,8 @@ Deno.test({
660676
"1.41.3",
661677
])
662678

663-
assertEquals(status.success, true)
679+
await assertYamlParsable(stdout)
680+
assertEquals(status.success, true, stderr)
664681
},
665682
})
666683

@@ -702,7 +719,8 @@ Deno.test({
702719
"1.41.3",
703720
])
704721

705-
assertEquals(templateCmd.status.success, true)
722+
await assertYamlParsable(templateCmd.stdout)
723+
assertEquals(templateCmd.status.success, true, templateCmd.stderr)
706724
} finally {
707725
await tmpRepo.cleanup()
708726
}

src/helm/get-chart-context.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,17 @@ function normalizeRelease(r: HelmRelease): Release {
3535
export async function getChartContext(
3636
release: string,
3737
tmpDir: string,
38+
chartDir: string,
3839
args: readonly string[]
3940
): Promise<ChartContext> {
4041
const getValuesChartDir = path.join(tmpDir, "get-values-chart")
4142
try {
42-
await fs.ensureDir(path.join(getValuesChartDir, "templates"))
43+
await fs.copy(chartDir, getValuesChartDir)
44+
const getValuesTemplatesDir = path.join(getValuesChartDir, "templates")
45+
await ignoreNotFoundError(
46+
Deno.remove(getValuesTemplatesDir, { recursive: true })
47+
)
48+
await fs.ensureDir(getValuesTemplatesDir)
4349

4450
await Deno.writeFile(
4551
path.join(getValuesChartDir, "templates/values-and-release.yaml"),

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@ async function main() {
131131
debug(`Successfuly fetched chart ${chartLocation} to temporary directory`)
132132
}
133133

134-
const chartContext = await getChartContext(releaseName, tmpDir, args)
134+
const chartContext = await getChartContext(
135+
releaseName,
136+
tmpDir,
137+
tmpChartPath,
138+
args
139+
)
135140
debug(`Chart context:\n${JSON.stringify(chartContext, null, 2)}`)
136141

137142
await renderDenoChart(chartContext, tmpChartPath, options)

0 commit comments

Comments
 (0)