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 a5ea7cf  Fix #749: do not create route if not needed
a5ea7cf is described below

commit a5ea7cf5b1236ccfd1c882af3f9cfa5a9030f22b
Author: nferraro <ni.ferr...@gmail.com>
AuthorDate: Thu Jun 13 16:06:54 2019 +0200

    Fix #749: do not create route if not needed
---
 pkg/trait/ingress.go    | 5 ++++-
 pkg/trait/route.go      | 5 ++++-
 pkg/trait/route_test.go | 1 +
 pkg/trait/service.go    | 3 +++
 4 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/pkg/trait/ingress.go b/pkg/trait/ingress.go
index 8f0fe56..2ef8718 100644
--- a/pkg/trait/ingress.go
+++ b/pkg/trait/ingress.go
@@ -83,7 +83,10 @@ func (t *ingressTrait) getTargetService(e *Environment) 
(service *corev1.Service
        e.Resources.VisitService(func(s *corev1.Service) {
                if s.ObjectMeta.Labels != nil {
                        if intName, ok := 
s.ObjectMeta.Labels["camel.apache.org/integration"]; ok && intName == 
e.Integration.Name {
-                               service = s
+                               if 
s.ObjectMeta.Labels["camel.apache.org/service.type"] == "user" {
+                                       // We should build an ingress only on 
top of the user service (e.g. not if the service contains only prometheus)
+                                       service = s
+                               }
                        }
                }
        })
diff --git a/pkg/trait/route.go b/pkg/trait/route.go
index 41f69c8..aa1fc0b 100644
--- a/pkg/trait/route.go
+++ b/pkg/trait/route.go
@@ -84,7 +84,10 @@ func (t *routeTrait) getTargetService(e *Environment) 
(service *corev1.Service)
        e.Resources.VisitService(func(s *corev1.Service) {
                if s.ObjectMeta.Labels != nil {
                        if intName, ok := 
s.ObjectMeta.Labels["camel.apache.org/integration"]; ok && intName == 
e.Integration.Name {
-                               service = s
+                               if 
s.ObjectMeta.Labels["camel.apache.org/service.type"] == "user" {
+                                       // We should build a route only on top 
of the user service (e.g. not if the service contains only prometheus)
+                                       service = s
+                               }
                        }
                }
        })
diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go
index f55c4ea..d484bda 100644
--- a/pkg/trait/route_test.go
+++ b/pkg/trait/route_test.go
@@ -78,6 +78,7 @@ func createTestRouteEnvironment(t *testing.T) *Environment {
                                Namespace: "test-ns",
                                Labels: map[string]string{
                                        "camel.apache.org/integration": 
"test-i",
+                                       "camel.apache.org/service.type": "user",
                                },
                        },
                        Spec: corev1.ServiceSpec{
diff --git a/pkg/trait/service.go b/pkg/trait/service.go
index 8e91366..408a05b 100644
--- a/pkg/trait/service.go
+++ b/pkg/trait/service.go
@@ -84,6 +84,9 @@ func (t *serviceTrait) Apply(e *Environment) (err error) {
        }
        svc.Spec.Ports = append(svc.Spec.Ports, port)
 
+       // Mark the service as a user service
+       svc.Labels["camel.apache.org/service.type"] = "user"
+
        // Register a post processor to add a container port to the integration 
deployment
        e.PostProcessors = append(e.PostProcessors, func(environment 
*Environment) error {
                var container *corev1.Container

Reply via email to