Skip to content

Commit

Permalink
kamel stuck when a secret has an illegal name #356
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jan 25, 2019
1 parent 3290846 commit 3c98d04
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/trait/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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),
})
})

Expand All @@ -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,
Expand All @@ -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),
})
})

Expand Down
8 changes: 8 additions & 0 deletions pkg/util/kubernetes/sanitize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 3c98d04

Please sign in to comment.