Skip to content

Commit 58395f1

Browse files
authored
Merge pull request #5 from wintermute-core/host-path
chore: host path passing fixes
2 parents 85194f0 + 7ceca83 commit 58395f1

File tree

9 files changed

+180
-5
lines changed

9 files changed

+180
-5
lines changed

.github/workflows/main-validation.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,40 @@ jobs:
3434
helm template test-release charts/k8s-service -f charts/k8s-service/linter_values.yaml > /dev/null
3535
echo "✓ Template rendering successful"
3636
37+
- name: Test valid hostPaths configuration
38+
run: |
39+
echo "Testing valid hostPaths configuration..."
40+
helm template test charts/k8s-service -f charts/k8s-service/tests/valid-hostpaths.yaml > /dev/null
41+
echo "✓ Valid hostPaths test passed"
42+
43+
- name: Test duplicate mountPath detection
44+
run: |
45+
echo "Testing duplicate mountPath detection..."
46+
if helm template test charts/k8s-service -f charts/k8s-service/tests/duplicate-mountpath.yaml 2>&1 | grep -q "Duplicate mountPath"; then
47+
echo "✓ Duplicate mountPath correctly detected and rejected"
48+
else
49+
echo "✗ FAIL: Duplicate mountPath was not detected"
50+
exit 1
51+
fi
52+
53+
- name: Test duplicate host path detection
54+
run: |
55+
echo "Testing duplicate host path detection..."
56+
if helm template test charts/k8s-service -f charts/k8s-service/tests/duplicate-hostpath.yaml 2>&1 | grep -q "Duplicate host path"; then
57+
echo "✓ Duplicate host path correctly detected and rejected"
58+
else
59+
echo "✗ FAIL: Duplicate host path was not detected"
60+
exit 1
61+
fi
62+
3763
- name: Validation complete
3864
run: |
3965
echo "✓ Main branch validation passed"
4066
echo "Chart is ready for release"
67+
echo ""
68+
echo "Validation summary:"
69+
echo " - Helm lint passed"
70+
echo " - Template rendering passed"
71+
echo " - Valid hostPaths test passed"
72+
echo " - Duplicate mountPath detection passed"
73+
echo " - Duplicate host path detection passed"

.github/workflows/pr-validation.yml

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ name: PR Validation
33
on:
44
pull_request:
55
types: [opened, synchronize, reopened]
6-
paths:
7-
- 'charts/**'
8-
- '.github/workflows/pr-validation.yml'
96

107
jobs:
118
validate-helm-chart:
@@ -32,6 +29,37 @@ jobs:
3229
helm template test-release charts/k8s-service -f charts/k8s-service/linter_values.yaml > /dev/null
3330
echo "✓ Template rendering successful"
3431
32+
- name: Test valid hostPaths configuration
33+
run: |
34+
echo "Testing valid hostPaths configuration..."
35+
helm template test charts/k8s-service -f charts/k8s-service/tests/valid-hostpaths.yaml > /dev/null
36+
echo "✓ Valid hostPaths test passed"
37+
38+
- name: Test duplicate mountPath detection
39+
run: |
40+
echo "Testing duplicate mountPath detection..."
41+
if helm template test charts/k8s-service -f charts/k8s-service/tests/duplicate-mountpath.yaml 2>&1 | grep -q "Duplicate mountPath"; then
42+
echo "✓ Duplicate mountPath correctly detected and rejected"
43+
else
44+
echo "✗ FAIL: Duplicate mountPath was not detected"
45+
exit 1
46+
fi
47+
48+
- name: Test duplicate host path detection
49+
run: |
50+
echo "Testing duplicate host path detection..."
51+
if helm template test charts/k8s-service -f charts/k8s-service/tests/duplicate-hostpath.yaml 2>&1 | grep -q "Duplicate host path"; then
52+
echo "✓ Duplicate host path correctly detected and rejected"
53+
else
54+
echo "✗ FAIL: Duplicate host path was not detected"
55+
exit 1
56+
fi
57+
3558
- name: Validation complete
3659
run: |
3760
echo "✓ All Helm chart validations passed successfully"
61+
echo " - Helm lint passed"
62+
echo " - Template rendering passed"
63+
echo " - Valid hostPaths test passed"
64+
echo " - Duplicate mountPath detection passed"
65+
echo " - Duplicate host path detection passed"

charts/k8s-service/templates/_deployment_spec.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ You can construct this context using dict:
99
(dict "Values" .Values "Release" .Release "Chart" .Chart "isCanary" true)
1010
*/ -}}
1111
{{- define "k8s-service.deploymentSpec" -}}
12+
{{- /* Validate hostPaths for duplicates */ -}}
13+
{{- include "k8s-service.validateHostPaths" . -}}
1214
{{- /*
1315
We must decide whether or not there are volumes to inject. The logic to decide whether or not to inject is based on
1416
whether or not there are configMaps OR secrets that are specified as volume mounts (`as: volume` attributes). We do this

charts/k8s-service/templates/_helpers.tpl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,25 @@ However, due to yaml/json limitations, all the Kubernetes resources require file
7171
{{- end -}}
7272
{{- "res" | index $accumulator | toString | printf -}}
7373
{{- end -}}
74+
75+
{{/*
76+
Validate hostPaths for duplicate mount paths and host paths.
77+
*/}}
78+
{{- define "k8s-service.validateHostPaths" -}}
79+
{{- $mountPaths := dict -}}
80+
{{- $hostPaths := dict -}}
81+
{{- range $name, $value := .Values.hostPaths -}}
82+
{{- if $value.mountPath -}}
83+
{{- if hasKey $mountPaths $value.mountPath -}}
84+
{{- fail (printf "Duplicate mountPath '%s' found in hostPaths: both '%s' and '%s' use the same mountPath" $value.mountPath (index $mountPaths $value.mountPath) $name) -}}
85+
{{- end -}}
86+
{{- $_ := set $mountPaths $value.mountPath $name -}}
87+
{{- end -}}
88+
{{- if $value.path -}}
89+
{{- if hasKey $hostPaths $value.path -}}
90+
{{- fail (printf "Duplicate host path '%s' found in hostPaths: both '%s' and '%s' use the same path" $value.path (index $hostPaths $value.path) $name) -}}
91+
{{- end -}}
92+
{{- $_ := set $hostPaths $value.path $name -}}
93+
{{- end -}}
94+
{{- end -}}
95+
{{- end -}}

charts/k8s-service/tests/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Chart Validation Tests
2+
3+
This directory contains test value files for validating chart behavior.
4+
5+
## Test Files
6+
7+
### Negative Tests (Should Fail)
8+
9+
- `duplicate-mountpath.yaml` - Tests that duplicate `mountPath` values are detected and rejected
10+
- `duplicate-hostpath.yaml` - Tests that duplicate host `path` values are detected and rejected
11+
12+
### Positive Tests (Should Pass)
13+
14+
- `valid-hostpaths.yaml` - Tests that valid unique hostPaths configuration works correctly
15+
16+
## Running Tests Locally
17+
18+
### Test that duplicates are rejected:
19+
```bash
20+
# Should fail with error about duplicate mountPath
21+
helm template test charts/k8s-service -f charts/k8s-service/tests/duplicate-mountpath.yaml
22+
23+
# Should fail with error about duplicate host path
24+
helm template test charts/k8s-service -f charts/k8s-service/tests/duplicate-hostpath.yaml
25+
```
26+
27+
### Test that valid config works:
28+
```bash
29+
# Should succeed
30+
helm template test charts/k8s-service -f charts/k8s-service/tests/valid-hostpaths.yaml
31+
```
32+
33+
## CI/CD Integration
34+
35+
These tests are automatically run in GitHub Actions workflows to ensure validation logic works correctly.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Test: Duplicate host path should fail validation
2+
# This test should FAIL with error about duplicate host path
3+
4+
applicationName: test-duplicate-hostpath
5+
containerImage:
6+
repository: nginx
7+
tag: stable
8+
9+
hostPaths:
10+
data1:
11+
path: /k8s-data/shared
12+
mountPath: /data1
13+
data2:
14+
path: /k8s-data/shared
15+
mountPath: /data2
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Test: Duplicate mountPath should fail validation
2+
# This test should FAIL with error about duplicate mountPath
3+
4+
applicationName: test-duplicate-mountpath
5+
containerImage:
6+
repository: nginx
7+
tag: stable
8+
9+
hostPaths:
10+
data1:
11+
path: /host/path1
12+
mountPath: /data
13+
data2:
14+
path: /host/path2
15+
mountPath: /data
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Test: Valid unique hostPaths should pass validation
2+
# This test should PASS
3+
4+
applicationName: test-valid-hostpaths
5+
containerImage:
6+
repository: nginx
7+
tag: stable
8+
9+
hostPaths:
10+
data:
11+
path: /host/data
12+
mountPath: /data
13+
logs:
14+
path: /host/logs
15+
mountPath: /logs
16+
type: DirectoryOrCreate
17+
downloads:
18+
path: /host/downloads
19+
mountPath: /downloads
20+
readOnly: true
21+
type: Directory

charts/k8s-service/values.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,15 @@ persistentVolumes: {}
595595
scratchPaths: {}
596596

597597
# hostPaths is a map of key value pairs that specifies which paths in the container should be setup as hostPaths.
598+
# WARNING: Duplicate 'path' or 'mountPath' values will cause validation errors.
598599
# Example:
599600
#hostPaths:
600601
# "download":
601-
# path: /tmp/download
602-
# type: DirectoryOrCreate
602+
# path: /tmp/download # Path on the host node (required)
603+
# mountPath: /downloads # Path in the container (required)
604+
# type: DirectoryOrCreate # Optional: hostPath type
605+
# readOnly: false # Optional: mount as read-only
606+
# subPath: "" # Optional: subPath within the volume
603607

604608
hostPaths: {}
605609

0 commit comments

Comments
 (0)