This is an automated email from the ASF dual-hosted git repository.
pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new 9f943f08b fix(trait): mount sanitize to return refName and confName
9f943f08b is described below
commit 9f943f08b33a46844304e356aa00427a667aa251
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Sun Jan 25 09:19:50 2026 +0100
fix(trait): mount sanitize to return refName and confName
Closes #6464
---
pkg/trait/mount.go | 6 +++---
pkg/trait/mount_support.go | 15 +++++++++------
2 files changed, 12 insertions(+), 9 deletions(-)
diff --git a/pkg/trait/mount.go b/pkg/trait/mount.go
index 4322df614..2d7047d6b 100644
--- a/pkg/trait/mount.go
+++ b/pkg/trait/mount.go
@@ -316,7 +316,7 @@ func (t *mountTrait) configureCamelVolumesAndMounts(e
*Environment, vols *[]core
// mountResource add the resource to volumes and mounts and return the final
path where the resource is mounted.
func (t *mountTrait) mountResource(vols *[]corev1.Volume, mnts
*[]corev1.VolumeMount, icnts *[]corev1.Container, conf *utilResource.Config)
string {
- refName := sanitizeVolumeName(conf.Name(), vols)
+ refName, confName := sanitizeVolumeName(conf.Name(), vols)
dstDir := conf.DestinationPath()
dstFile := ""
if conf.DestinationPath() != "" {
@@ -326,8 +326,8 @@ func (t *mountTrait) mountResource(vols *[]corev1.Volume,
mnts *[]corev1.VolumeM
dstFile = conf.Key()
}
}
- vol := getVolume(refName, string(conf.StorageType()), refName,
conf.Key(), dstFile)
- mntPath := getMountPoint(refName, dstDir, string(conf.StorageType()),
string(conf.ContentType()))
+ vol := getVolume(refName, string(conf.StorageType()), confName,
conf.Key(), dstFile)
+ mntPath := getMountPoint(confName, dstDir, string(conf.StorageType()),
string(conf.ContentType()))
readOnly := (conf.StorageType() != utilResource.StorageTypePVC)
mnt := getMount(refName, mntPath, dstFile, readOnly)
diff --git a/pkg/trait/mount_support.go b/pkg/trait/mount_support.go
index e0f0b9c2a..c6916a809 100644
--- a/pkg/trait/mount_support.go
+++ b/pkg/trait/mount_support.go
@@ -146,17 +146,20 @@ func createPVC(e *Environment, volumeParts []string)
error {
// sanitizeVolumeName ensures the provided name is unique among the volumes.
// If `name` already exists, it appends -1, -2, etc. until a unique name is
found.
-func sanitizeVolumeName(name string, vols *[]corev1.Volume) string {
- name = kubernetes.SanitizeLabel(name)
- if !volumeExists(name, vols) {
- return name
+// It returns the sanitizedName and the configuration name accordingly.
+func sanitizeVolumeName(name string, vols *[]corev1.Volume) (string, string) {
+ sanitName := kubernetes.SanitizeLabel(name)
+ if !volumeExists(sanitName, vols) {
+ return sanitName, name
}
suffix := 1
for {
- candidate := fmt.Sprintf("%s-%d", name, suffix)
+ candidate := fmt.Sprintf("%s-%d", sanitName, suffix)
if !volumeExists(candidate, vols) {
- return candidate
+ newConfName := fmt.Sprintf("%s-%d", name, suffix)
+
+ return candidate, newConfName
}
suffix++
}