Skip to content

Commit ccac415

Browse files
authored
Merge pull request #6 from wintermute-core/host-path
chore: path validation update
2 parents 58395f1 + bd8a383 commit ccac415

File tree

6 files changed

+55
-18
lines changed

6 files changed

+55
-18
lines changed

.github/workflows/main-validation.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,16 @@ jobs:
6060
exit 1
6161
fi
6262
63+
- name: Test missing mountPath detection
64+
run: |
65+
echo "Testing missing mountPath detection..."
66+
if helm template test charts/k8s-service -f charts/k8s-service/tests/missing-mountpath.yaml 2>&1 | grep -q "mountPath.*required"; then
67+
echo "✓ Missing mountPath correctly detected and rejected"
68+
else
69+
echo "✗ FAIL: Missing mountPath was not detected"
70+
exit 1
71+
fi
72+
6373
- name: Validation complete
6474
run: |
6575
echo "✓ Main branch validation passed"
@@ -71,3 +81,4 @@ jobs:
7181
echo " - Valid hostPaths test passed"
7282
echo " - Duplicate mountPath detection passed"
7383
echo " - Duplicate host path detection passed"
84+
echo " - Missing mountPath detection passed"

.github/workflows/pr-validation.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ jobs:
5555
exit 1
5656
fi
5757
58+
- name: Test missing mountPath detection
59+
run: |
60+
echo "Testing missing mountPath detection..."
61+
if helm template test charts/k8s-service -f charts/k8s-service/tests/missing-mountpath.yaml 2>&1 | grep -q "mountPath.*required"; then
62+
echo "✓ Missing mountPath correctly detected and rejected"
63+
else
64+
echo "✗ FAIL: Missing mountPath was not detected"
65+
exit 1
66+
fi
67+
5868
- name: Validation complete
5969
run: |
6070
echo "✓ All Helm chart validations passed successfully"
@@ -63,3 +73,4 @@ jobs:
6373
echo " - Valid hostPaths test passed"
6474
echo " - Duplicate mountPath detection passed"
6575
echo " - Duplicate host path detection passed"
76+
echo " - Missing mountPath detection passed"

charts/k8s-service/templates/_deployment_spec.tpl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,6 @@ spec:
473473
- name: {{ $name }}
474474
emptyDir: {}
475475
{{- end }}
476-
{{- range $name, $value := .Values.hostPaths }}
477-
- name: {{ $name }}
478-
hostPath:
479-
path: {{ $value.path }}
480-
type: {{ $value.type }}
481-
{{- end }}
482476
{{- /* END VOLUME LOGIC */ -}}
483477

484478
{{- with .Values.nodeSelector }}

charts/k8s-service/templates/_helpers.tpl

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,28 @@ However, due to yaml/json limitations, all the Kubernetes resources require file
7373
{{- end -}}
7474
7575
{{/*
76-
Validate hostPaths for duplicate mount paths and host paths.
76+
Validate hostPaths for required fields and duplicates.
7777
*/}}
7878
{{- define "k8s-service.validateHostPaths" -}}
7979
{{- $mountPaths := dict -}}
8080
{{- $hostPaths := dict -}}
8181
{{- 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 -}}
82+
{{- /* Validate required fields */ -}}
83+
{{- if not $value.path -}}
84+
{{- fail (printf "hostPaths.%s: 'path' is required but not provided" $name) -}}
8785
{{- 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 -}}
86+
{{- if not $value.mountPath -}}
87+
{{- fail (printf "hostPaths.%s: 'mountPath' is required but not provided" $name) -}}
9388
{{- end -}}
89+
{{- /* Check for duplicate mountPath */ -}}
90+
{{- if hasKey $mountPaths $value.mountPath -}}
91+
{{- fail (printf "Duplicate mountPath '%s' found in hostPaths: both '%s' and '%s' use the same mountPath" $value.mountPath (index $mountPaths $value.mountPath) $name) -}}
92+
{{- end -}}
93+
{{- $_ := set $mountPaths $value.mountPath $name -}}
94+
{{- /* Check for duplicate host path */ -}}
95+
{{- if hasKey $hostPaths $value.path -}}
96+
{{- fail (printf "Duplicate host path '%s' found in hostPaths: both '%s' and '%s' use the same path" $value.path (index $hostPaths $value.path) $name) -}}
97+
{{- end -}}
98+
{{- $_ := set $hostPaths $value.path $name -}}
9499
{{- end -}}
95100
{{- end -}}

charts/k8s-service/tests/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,24 @@ This directory contains test value files for validating chart behavior.
88

99
- `duplicate-mountpath.yaml` - Tests that duplicate `mountPath` values are detected and rejected
1010
- `duplicate-hostpath.yaml` - Tests that duplicate host `path` values are detected and rejected
11+
- `missing-mountpath.yaml` - Tests that missing required `mountPath` field is detected and rejected
1112

1213
### Positive Tests (Should Pass)
1314

1415
- `valid-hostpaths.yaml` - Tests that valid unique hostPaths configuration works correctly
1516

1617
## Running Tests Locally
1718

18-
### Test that duplicates are rejected:
19+
### Test that validation catches errors:
1920
```bash
2021
# Should fail with error about duplicate mountPath
2122
helm template test charts/k8s-service -f charts/k8s-service/tests/duplicate-mountpath.yaml
2223

2324
# Should fail with error about duplicate host path
2425
helm template test charts/k8s-service -f charts/k8s-service/tests/duplicate-hostpath.yaml
26+
27+
# Should fail with error about required mountPath
28+
helm template test charts/k8s-service -f charts/k8s-service/tests/missing-mountpath.yaml
2529
```
2630

2731
### Test that valid config works:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Test: Missing mountPath should fail validation
2+
# This test should FAIL with error about required mountPath
3+
4+
applicationName: test-missing-mountpath
5+
containerImage:
6+
repository: nginx
7+
tag: stable
8+
9+
hostPaths:
10+
data:
11+
path: /host/data
12+
# mountPath is missing - should fail!

0 commit comments

Comments
 (0)