You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by as...@apache.org on 2021/02/08 08:36:29 UTC

[camel-k] 02/03: chore(conf): Mount application and user properties with sub-paths

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

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

commit f9f7d0edefd7f2f0d39b0ab94b409e1cd200cfea
Author: Antonin Stefanutti <an...@stefanutti.fr>
AuthorDate: Thu Feb 4 16:59:54 2021 +0100

    chore(conf): Mount application and user properties with sub-paths
---
 pkg/trait/container.go            |  5 +++--
 pkg/trait/knative_service_test.go |  2 +-
 pkg/trait/trait_test.go           |  2 +-
 pkg/trait/trait_types.go          | 15 ++++++++-------
 4 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/pkg/trait/container.go b/pkg/trait/container.go
index 4803b51..8f3a7d1 100644
--- a/pkg/trait/container.go
+++ b/pkg/trait/container.go
@@ -19,6 +19,7 @@ package trait
 
 import (
 	"fmt"
+	"path"
 	"sort"
 
 	appsv1 "k8s.io/api/apps/v1"
@@ -190,8 +191,8 @@ func (t *containerTrait) configureContainer(e *Environment) error {
 	}
 
 	envvar.SetVal(&container.Env, "CAMEL_K_DIGEST", e.Integration.Status.Digest)
-	envvar.SetVal(&container.Env, "CAMEL_K_CONF", "/etc/camel/conf/application.properties")
-	envvar.SetVal(&container.Env, "CAMEL_K_CONF_D", "/etc/camel/conf.d")
+	envvar.SetVal(&container.Env, "CAMEL_K_CONF", path.Join(basePath, "application.properties"))
+	envvar.SetVal(&container.Env, "CAMEL_K_CONF_D", confDPath)
 
 	e.addSourcesProperties()
 
diff --git a/pkg/trait/knative_service_test.go b/pkg/trait/knative_service_test.go
index b486ab0..482cd89 100644
--- a/pkg/trait/knative_service_test.go
+++ b/pkg/trait/knative_service_test.go
@@ -176,7 +176,7 @@ func TestKnativeService(t *testing.T) {
 	assert.Equal(t, "file:/etc/camel/sources/routes.js", environment.ApplicationProperties["camel.k.sources[0].location"])
 	assert.Equal(t, "js", environment.ApplicationProperties["camel.k.sources[0].language"])
 	assert.Equal(t, "true", environment.ApplicationProperties["camel.k.sources[0].compressed"])
-	test.EnvVarHasValue(t, spec.Containers[0].Env, "CAMEL_K_CONF", "/etc/camel/conf/application.properties")
+	test.EnvVarHasValue(t, spec.Containers[0].Env, "CAMEL_K_CONF", "/etc/camel/application.properties")
 	test.EnvVarHasValue(t, spec.Containers[0].Env, "CAMEL_K_CONF_D", "/etc/camel/conf.d")
 }
 
diff --git a/pkg/trait/trait_test.go b/pkg/trait/trait_test.go
index 36eeef3..f8f75af 100644
--- a/pkg/trait/trait_test.go
+++ b/pkg/trait/trait_test.go
@@ -291,7 +291,7 @@ func TestConfigureVolumesAndMountsTextResourcesAndProperties(t *testing.T) {
 
 	m := findVVolumeMount(mnts, func(m corev1.VolumeMount) bool { return m.Name == v.Name })
 	assert.NotNil(t, m)
-	assert.Equal(t, "/etc/camel/conf.d", m.MountPath)
+	assert.Equal(t, "/etc/camel/conf.d/user.properties", m.MountPath)
 
 	v = findVolume(vols, func(v corev1.Volume) bool { return v.ConfigMap.Name == "my-cm1" })
 	assert.NotNil(t, v)
diff --git a/pkg/trait/trait_types.go b/pkg/trait/trait_types.go
index 3ef9def..7b60392 100644
--- a/pkg/trait/trait_types.go
+++ b/pkg/trait/trait_types.go
@@ -43,7 +43,6 @@ const True = "true"
 
 var (
 	basePath            = "/etc/camel"
-	confPath            = path.Join(basePath, "conf")
 	confDPath           = path.Join(basePath, "conf.d")
 	sourcesMountPath    = path.Join(basePath, "sources")
 	resourcesMountPath  = path.Join(basePath, "resources")
@@ -606,14 +605,15 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
 
 	if e.Resources != nil {
 		e.Resources.VisitConfigMap(func(configMap *corev1.ConfigMap) {
-			var propertiesType string
-			var mountPath string
+			propertiesType := configMap.Labels["camel.apache.org/properties.type"]
+			resName := propertiesType + ".properties"
 
-			switch propertiesType = configMap.Labels["camel.apache.org/properties.type"]; propertiesType {
+			var mountPath string
+			switch propertiesType {
 			case "application":
-				mountPath = confPath
+				mountPath = path.Join(basePath, resName)
 			case "user":
-				mountPath = confDPath
+				mountPath = path.Join(confDPath, resName)
 			}
 
 			if propertiesType != "" {
@@ -627,7 +627,7 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
 							Items: []corev1.KeyToPath{
 								{
 									Key:  "application.properties",
-									Path: propertiesType + ".properties",
+									Path: resName,
 								},
 							},
 						},
@@ -638,6 +638,7 @@ func (e *Environment) configureVolumesAndMounts(vols *[]corev1.Volume, mnts *[]c
 					Name:      propertiesType + "-properties",
 					MountPath: mountPath,
 					ReadOnly:  true,
+					SubPath:   resName,
 				})
 			}
 		})