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

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/master by this push:
     new c06ef01  fix(trait): using proper contentKey for sources
c06ef01 is described below

commit c06ef01abdb5c376a6909040c502f5520cd2597f
Author: Pasquale Congiusti <pasquale.congiu...@gmail.com>
AuthorDate: Thu Jan 28 10:12:31 2021 +0100

    fix(trait): using proper contentKey for sources
    
    * If an integration is providing specifically a ConfigMap's item we now use 
its key, leaving "content" as default
    * Added some unit test to check default and content ref behavior also for 
sources
    
    Fix #1951
---
 pkg/trait/trait_test.go  | 60 +++++++++++++++++++++++++++++++++++++++++++++++-
 pkg/trait/trait_types.go |  7 ++++--
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index 491a856..6336fd7 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -207,7 +207,65 @@ func TestTraitHierarchyDecode(t *testing.T) {
        assert.Equal(t, 15, *kns.Target)
 }
 
-func TestConfigureVolumesAndMounts(t *testing.T) {
+func TestConfigureVolumesAndMountsSources(t *testing.T) {
+       env := Environment{
+               Resources: kubernetes.NewCollection(),
+               Integration: &v1.Integration{
+                       ObjectMeta: metav1.ObjectMeta{
+                               Name:      TestDeploymentName,
+                               Namespace: "ns",
+                       },
+                       Spec: v1.IntegrationSpec{
+                               Sources: []v1.SourceSpec{
+                                       {
+                                               DataSpec: v1.DataSpec{
+                                                       Name:       
"source1.java",
+                                                       ContentRef: "my-cm1",
+                                                       ContentKey: 
"source1.java",
+                                               },
+                                               Type: "data",
+                                       },
+                                       {
+                                               DataSpec: v1.DataSpec{
+                                                       Name:       
"source2.java",
+                                                       ContentRef: "my-cm2",
+                                               },
+                                               Type: "data",
+                                       },
+                               },
+                       },
+               },
+       }
+
+       vols := make([]corev1.Volume, 0)
+       mnts := make([]corev1.VolumeMount, 0)
+
+       env.Resources.AddAll(env.ComputeConfigMaps())
+       env.ConfigureVolumesAndMounts(&vols, &mnts)
+
+       assert.Len(t, vols, 2)
+       assert.Len(t, mnts, 2)
+
+       v := findVolume(vols, func(v corev1.Volume) bool { return 
v.ConfigMap.Name == "my-cm1" })
+       assert.NotNil(t, v)
+       assert.NotNil(t, v.VolumeSource.ConfigMap)
+       assert.Len(t, v.VolumeSource.ConfigMap.Items, 1)
+       assert.Equal(t, "source1.java", v.VolumeSource.ConfigMap.Items[0].Key)
+
+       m := findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return 
m.Name == v.Name })
+       assert.NotNil(t, m)
+
+       v = findVolume(vols, func(v corev1.Volume) bool { return 
v.ConfigMap.Name == "my-cm2" })
+       assert.NotNil(t, v)
+       assert.NotNil(t, v.VolumeSource.ConfigMap)
+       assert.Len(t, v.VolumeSource.ConfigMap.Items, 1)
+       assert.Equal(t, "content", v.VolumeSource.ConfigMap.Items[0].Key)
+
+       m = findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return 
m.Name == v.Name })
+       assert.NotNil(t, m)
+}
+
+func TestConfigureVolumesAndMountsResourcesAndProperties(t *testing.T) {
        env := Environment{
                Resources: kubernetes.NewCollection(),
                Integration: &v1.Integration{
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index f28fc8f..e896b3b 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -529,12 +529,15 @@ func (e *Environment) ConfigureVolumesAndMounts(vols 
*[]corev1.Volume, mnts *[]c
        //
        // Volumes :: Sources
        //
-
        for i, s := range e.Integration.Sources() {
                cmName := fmt.Sprintf("%s-source-%03d", e.Integration.Name, i)
                if s.ContentRef != "" {
                        cmName = s.ContentRef
                }
+               cmKey := "content"
+               if s.ContentKey != "" {
+                       cmKey = s.ContentKey
+               }
                resName := strings.TrimPrefix(s.Name, "/")
                refName := fmt.Sprintf("i-source-%03d", i)
                resPath := path.Join(SourcesMountPath, refName)
@@ -548,7 +551,7 @@ func (e *Environment) ConfigureVolumesAndMounts(vols 
*[]corev1.Volume, mnts *[]c
                                        },
                                        Items: []corev1.KeyToPath{
                                                {
-                                                       Key:  "content",
+                                                       Key:  cmKey,
                                                        Path: resName,
                                                },
                                        },

Reply via email to