You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/08/12 16:29:47 UTC
[camel-k] 01/01: fix(trait): force a volume path when key is set
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch 3543/set-default-path
in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit f28e0e0eabea15d987a919651e354216b863f3b1
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Fri Aug 12 18:29:25 2022 +0200
fix(trait): force a volume path when key is set
---
pkg/trait/trait_types.go | 4 +++-
pkg/trait/trait_types_test.go | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 5106102de..82aa32ecd 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -608,7 +608,9 @@ func convertToKeyToPath(k, v string) []corev1.KeyToPath {
if k == "" {
return nil
}
-
+ if v == "" {
+ v = k
+ }
kp := []corev1.KeyToPath{
{
Key: k,
diff --git a/pkg/trait/trait_types_test.go b/pkg/trait/trait_types_test.go
index 9d3509de9..96bc674c2 100644
--- a/pkg/trait/trait_types_test.go
+++ b/pkg/trait/trait_types_test.go
@@ -114,3 +114,42 @@ func TestCollectConfigurationPairs(t *testing.T) {
{Name: "p4", Value: "integration"},
})
}
+
+func TestVolumeWithKeyAndPath(t *testing.T) {
+ v := getVolume("SomeVolName", "secret", "SomeSecretName", "SomeKey", "SomePath")
+ assert.NotNil(t, v)
+ assert.Equal(t, "SomeVolName", v.Name)
+ s := v.VolumeSource.Secret
+ assert.NotNil(t, s)
+ assert.Equal(t, "SomeSecretName", s.SecretName)
+ items := s.Items
+ assert.NotNil(t, items)
+ assert.Equal(t, 1, len(items))
+ assert.Equal(t, "SomeKey", items[0].Key)
+ assert.Equal(t, "SomePath", items[0].Path)
+}
+
+func TestVolumeWithPathOnly(t *testing.T) {
+ v := getVolume("SomeVolName", "secret", "SomeSecretName", "", "SomePath")
+ assert.NotNil(t, v)
+ assert.Equal(t, "SomeVolName", v.Name)
+ s := v.VolumeSource.Secret
+ assert.NotNil(t, s)
+ assert.Equal(t, "SomeSecretName", s.SecretName)
+ items := s.Items
+ assert.Nil(t, items)
+}
+
+func TestVolumeWithKeyOnly(t *testing.T) {
+ v := getVolume("SomeVolName", "secret", "SomeSecretName", "SomeKey", "")
+ assert.NotNil(t, v)
+ assert.Equal(t, "SomeVolName", v.Name)
+ s := v.VolumeSource.Secret
+ assert.NotNil(t, s)
+ assert.Equal(t, "SomeSecretName", s.SecretName)
+ items := s.Items
+ assert.NotNil(t, items)
+ assert.Equal(t, 1, len(items))
+ assert.Equal(t, "SomeKey", items[0].Key)
+ assert.Equal(t, "SomeKey", items[0].Path)
+}