You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/01/25 08:34:30 UTC

[camel-k] branch master updated: kamel stuck when a secret has an illegal name #356

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

lburgazzoli 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 3c98d04  kamel stuck when a secret has an illegal name #356
3c98d04 is described below

commit 3c98d04d8f5391db9fb07546a2b9eb053b991e61
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Jan 22 15:44:31 2019 +0100

    kamel stuck when a secret has an illegal name #356
---
 pkg/trait/deployment.go         | 12 ++++++++----
 pkg/util/kubernetes/sanitize.go |  8 ++++++++
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go
index 00de1fc..fa72c38 100644
--- a/pkg/trait/deployment.go
+++ b/pkg/trait/deployment.go
@@ -23,6 +23,8 @@ import (
 	"strconv"
 	"strings"
 
+	"github.com/apache/camel-k/pkg/util/kubernetes"
+
 	"github.com/apache/camel-k/pkg/util/envvar"
 
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
@@ -415,7 +417,8 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 	//
 
 	VisitConfigurations("configmap", e.Context, e.Integration, func(cmName string) {
-		refName := "integration-cm-" + strings.ToLower(cmName)
+		refName := kubernetes.SanitizeLabel(cmName)
+		fileName := "integration-cm-" + strings.ToLower(cmName)
 
 		vols = append(vols, corev1.Volume{
 			Name: refName,
@@ -430,7 +433,7 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 
 		mnts = append(mnts, corev1.VolumeMount{
 			Name:      refName,
-			MountPath: path.Join("/etc/camel/conf.d", refName),
+			MountPath: path.Join("/etc/camel/conf.d", fileName),
 		})
 	})
 
@@ -439,7 +442,8 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 	//
 
 	VisitConfigurations("secret", e.Context, e.Integration, func(secretName string) {
-		refName := "integration-secret-" + strings.ToLower(secretName)
+		refName := kubernetes.SanitizeLabel(secretName)
+		fileName := "integration-secret-" + strings.ToLower(secretName)
 
 		vols = append(vols, corev1.Volume{
 			Name: refName,
@@ -452,7 +456,7 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
 
 		mnts = append(mnts, corev1.VolumeMount{
 			Name:      refName,
-			MountPath: path.Join("/etc/camel/conf.d", refName),
+			MountPath: path.Join("/etc/camel/conf.d", fileName),
 		})
 	})
 
diff --git a/pkg/util/kubernetes/sanitize.go b/pkg/util/kubernetes/sanitize.go
index 4e02170..c3ee990 100644
--- a/pkg/util/kubernetes/sanitize.go
+++ b/pkg/util/kubernetes/sanitize.go
@@ -40,6 +40,14 @@ func SanitizeName(name string) string {
 	return name
 }
 
+// SanitizeLabel sanitizes the given name to be compatible with k8s
+func SanitizeLabel(name string) string {
+	name = strings.ToLower(name)
+	name = disallowedChars.ReplaceAllString(name, "")
+	name = strings.TrimFunc(name, isDisallowedStartEndChar)
+	return name
+}
+
 func isDisallowedStartEndChar(rune rune) bool {
 	return !unicode.IsLetter(rune)
 }