Skip to content

Commit 60cd1ac

Browse files
moko-poiyorugac
authored andcommitted
fix: restrict ConfigMap file to base name only, support path in VolumeClaim
1 parent e8f4836 commit 60cd1ac

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

api/v1alpha1/testrun_types.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ type K6Configmap struct {
154154
// Name of the ConfigMap. It is expected to be in the sanme namespace as the `TestRun`.
155155
Name string `json:"name"`
156156
// Name of the file to execute (.js or .tar), stored as a key in the ConfigMap.
157-
// Can include a path component (e.g., "subdir/script.js").
158157
File string `json:"file,omitempty"`
159158
}
160159

@@ -210,6 +209,7 @@ func (k6 TestRunSpec) ParseScript() (*types.Script, error) {
210209
spec := k6.Script
211210
s := &types.Script{}
212211

212+
// VolumeClaim: allow file to include a path component (e.g. "subdir/script.js").
213213
if spec.VolumeClaim.Name != "" {
214214
s.Name = spec.VolumeClaim.Name
215215
if spec.VolumeClaim.File != "" {
@@ -227,17 +227,15 @@ func (k6 TestRunSpec) ParseScript() (*types.Script, error) {
227227
return s, nil
228228
}
229229

230+
// ConfigMap: supports file name only (no path components)
230231
if spec.ConfigMap.Name != "" {
232+
s.Path = "/test/"
233+
s.Filename = "test.js"
234+
231235
s.Name = spec.ConfigMap.Name
232236

233237
if spec.ConfigMap.File != "" {
234-
s.Path, s.Filename = filepath.Split(spec.ConfigMap.File)
235-
}
236-
if s.Path == "" {
237-
s.Path = "/test/"
238-
}
239-
if s.Filename == "" {
240-
s.Filename = "test.js"
238+
s.Filename = spec.ConfigMap.File
241239
}
242240

243241
s.Type = "ConfigMap"

docs/crd-generated.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,7 @@ K6Configmap describes the location of the script in the ConfigMap.
779779
<td><b>file</b></td>
780780
<td>string</td>
781781
<td>
782-
Name of the file to execute (.js or .tar), stored as a key in the ConfigMap.
783-
Can include a path component (e.g., "subdir/script.js").<br/>
782+
Name of the file to execute (.js or .tar), stored as a key in the ConfigMap.<br/>
784783
</td>
785784
<td>false</td>
786785
</tr></tbody>

pkg/types/script.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,27 +57,24 @@ func (s *Script) Volume() []corev1.Volume {
5757
// VolumeMount creates a VolumeMount spec for the script
5858
func (s *Script) VolumeMount() []corev1.VolumeMount {
5959

60-
mountPath := s.Path
61-
if mountPath == "" {
62-
mountPath = "/test/"
63-
}
64-
6560
switch s.Type {
6661

62+
// VolumeClaim: mounts the volume at s.Path (default "/test").
6763
case "VolumeClaim":
6864
return []corev1.VolumeMount{
6965
corev1.VolumeMount{
7066
Name: "k6-test-volume",
71-
MountPath: mountPath,
67+
MountPath: s.Path,
7268
ReadOnly: s.ReadOnly,
7369
},
7470
}
7571

72+
// ConfigMap: always mounted at "/test" since keys cannot represent nested directories.
7673
case "ConfigMap":
7774
return []corev1.VolumeMount{
7875
corev1.VolumeMount{
7976
Name: "k6-test-volume",
80-
MountPath: mountPath,
77+
MountPath: "/test",
8178
ReadOnly: true,
8279
},
8380
}

0 commit comments

Comments
 (0)