From 3c98d04d8f5391db9fb07546a2b9eb053b991e61 Mon Sep 17 00:00:00 2001 From: lburgazzoli Date: Tue, 22 Jan 2019 15:44:31 +0100 Subject: [PATCH] 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 00de1fc59d..fa72c3843c 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 4e021707e4..c3ee990109 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) }