From 08b59049a5147f47d2df65b7b40a2cb53b52df12 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 | 11 ++-- test/build_manager_integration_test.go | 79 +++++++++++++------------- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/pkg/trait/deployment.go b/pkg/trait/deployment.go index 4f01bcd176..3f0361f4d0 100644 --- a/pkg/trait/deployment.go +++ b/pkg/trait/deployment.go @@ -24,6 +24,7 @@ import ( "strings" "github.com/apache/camel-k/pkg/util/envvar" + "github.com/rs/xid" "github.com/apache/camel-k/pkg/apis/camel/v1alpha1" appsv1 "k8s.io/api/apps/v1" @@ -418,7 +419,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 := xid.New().String() + fileName := "integration-cm-" + strings.ToLower(cmName) vols = append(vols, corev1.Volume{ Name: refName, @@ -433,7 +435,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), }) }) @@ -442,7 +444,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 := xid.New().String() + fileName := "integration-secret-" + strings.ToLower(secretName) vols = append(vols, corev1.Volume{ Name: refName, @@ -455,7 +458,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/test/build_manager_integration_test.go b/test/build_manager_integration_test.go index 44ed8501d9..93cff8c7f2 100644 --- a/test/build_manager_integration_test.go +++ b/test/build_manager_integration_test.go @@ -34,6 +34,22 @@ import ( "github.com/stretchr/testify/assert" ) +func handler(in chan builder.Result, out chan builder.Result) { + for { + select { + case res := <-in: + if res.Status == builder.StatusCompleted || res.Status == builder.StatusError { + out <- res + return + } + case <-time.After(5 * time.Minute): + fmt.Println("timeout 1") + close(out) + return + } + } +} + func TestBuildManagerBuild(t *testing.T) { namespace := getTargetNamespace() b := builder.New(testContext, testClient, namespace) @@ -56,28 +72,20 @@ func TestBuildManagerBuild(t *testing.T) { Steps: s2i.DefaultSteps, } - c := make(chan builder.Result) + hc := make(chan builder.Result) + rc := make(chan builder.Result) - b.Submit(r, func(res builder.Result) { - c <- res - }) - - var result builder.Result - -loop: - for { - select { - case res := <-c: - if res.Status == builder.StatusCompleted || res.Status == builder.StatusError { - result = res - break loop - } - case <-time.After(5 * time.Minute): - fmt.Println("timeout 1") - break loop - } - } + go func() { + handler(hc, rc) + }() + go func() { + b.Submit(r, func(res builder.Result) { + hc <- res + }) + }() + result, ok := <-rc + assert.True(t, ok) assert.NotEqual(t, builder.StatusError, result.Status) assert.Equal(t, builder.StatusCompleted, result.Status) assert.Regexp(t, ".*/.*/.*:.*", result.Image) @@ -104,27 +112,20 @@ func TestBuildManagerFailedBuild(t *testing.T) { Steps: s2i.DefaultSteps, } - c := make(chan builder.Result) - - b.Submit(r, func(res builder.Result) { - c <- res - }) + hc := make(chan builder.Result) + rc := make(chan builder.Result) - var result builder.Result -loop: - for { - select { - case res := <-c: - if res.Status == builder.StatusCompleted || res.Status == builder.StatusError { - result = res - break loop - } - case <-time.After(5 * time.Minute): - fmt.Println("timeout 1") - break loop - } - } + go func() { + handler(hc, rc) + }() + go func() { + b.Submit(r, func(res builder.Result) { + hc <- res + }) + }() + result, ok := <-rc + assert.True(t, ok) assert.Equal(t, builder.StatusError, result.Status) assert.NotEqual(t, builder.StatusCompleted, result.Status) }