You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ts...@apache.org on 2022/08/23 03:29:00 UTC

[camel-k] branch main updated: fix(trait): force a volume path when key is set

This is an automated email from the ASF dual-hosted git repository.

tsato 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 e2e1f7b0e fix(trait): force a volume path when key is set
e2e1f7b0e is described below

commit e2e1f7b0eb47747a4fc2f8819926250238dea186
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)
+}