camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From astefanu...@apache.org
Subject [camel-k] branch master updated: trait(route): do not set Route.Spec.TLS if not needed
Date Wed, 29 May 2019 17:55:21 GMT
This is an automated email from the ASF dual-hosted git repository.

astefanutti 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 98b24c9  trait(route): do not set Route.Spec.TLS if not needed
98b24c9 is described below

commit 98b24c91ead1b816edcba4d738f7a3c91e6ff11b
Author: lburgazzoli <lburgazzoli@gmail.com>
AuthorDate: Wed May 29 15:48:50 2019 +0200

    trait(route): do not set Route.Spec.TLS if not needed
---
 pkg/trait/route.go      |  6 +++++-
 pkg/trait/route_test.go | 51 ++++++++++++++++++++++++++++++++++---------------
 2 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/pkg/trait/route.go b/pkg/trait/route.go
index 351d309..41f69c8 100644
--- a/pkg/trait/route.go
+++ b/pkg/trait/route.go
@@ -19,6 +19,7 @@ package trait
 
 import (
 	"errors"
+	"reflect"
 
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 
@@ -116,7 +117,6 @@ func (t *routeTrait) getRouteFor(service *corev1.Service) *routev1.Route
{
 }
 
 func (t *routeTrait) getTLSConfig() *routev1.TLSConfig {
-
 	config := routev1.TLSConfig{
 		Termination:                   routev1.TLSTerminationType(t.TLSTermination),
 		Certificate:                   t.TLSCertificate,
@@ -126,5 +126,9 @@ func (t *routeTrait) getTLSConfig() *routev1.TLSConfig {
 		InsecureEdgeTerminationPolicy: routev1.InsecureEdgeTerminationPolicyType(t.TLSInsecureEdgeTerminationPolicy),
 	}
 
+	if reflect.DeepEqual(config, routev1.TLSConfig{}) {
+		return nil
+	}
+
 	return &config
 }
diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go
index b1975d9..58ff495 100644
--- a/pkg/trait/route_test.go
+++ b/pkg/trait/route_test.go
@@ -34,15 +34,13 @@ import (
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 )
 
-func TestRoute_TLS(t *testing.T) {
+func createTestRouteEnvironment(t *testing.T) *Environment {
 	catalog, err := test.DefaultCatalog()
 	assert.Nil(t, err)
 
-	traitCatalog := NewCatalog(context.TODO(), nil)
-
-	environment := Environment{
+	return &Environment{
 		CamelCatalog: catalog,
-		Catalog:      traitCatalog,
+		Catalog:      NewCatalog(context.TODO(), nil),
 		Integration: &v1alpha1.Integration{
 			ObjectMeta: metav1.ObjectMeta{
 				Name:      "test-i",
@@ -51,15 +49,7 @@ func TestRoute_TLS(t *testing.T) {
 			Status: v1alpha1.IntegrationStatus{
 				Phase: v1alpha1.IntegrationPhaseDeploying,
 			},
-			Spec: v1alpha1.IntegrationSpec{
-				Traits: map[string]v1alpha1.TraitSpec{
-					"route": {
-						Configuration: map[string]string{
-							"tls-termination": string(routev1.TLSTerminationEdge),
-						},
-					},
-				},
-			},
+			Spec: v1alpha1.IntegrationSpec{},
 		},
 		IntegrationContext: &v1alpha1.IntegrationContext{
 			Status: v1alpha1.IntegrationContextStatus{
@@ -98,8 +88,39 @@ func TestRoute_TLS(t *testing.T) {
 			},
 		}),
 	}
+}
+
+func TestRoute_Default(t *testing.T) {
+	environment := createTestRouteEnvironment(t)
+	traitsCatalog := environment.Catalog
+
+	err := traitsCatalog.apply(environment)
+
+	assert.Nil(t, err)
+	assert.NotEmpty(t, environment.ExecutedTraits)
+	assert.NotNil(t, environment.GetTrait(ID("route")))
+
+	route := environment.Resources.GetRoute(func(r *routev1.Route) bool {
+		return r.ObjectMeta.Name == "test-i"
+	})
+
+	assert.NotNil(t, route)
+	assert.Nil(t, route.Spec.TLS)
+}
+
+func TestRoute_TLS(t *testing.T) {
+	environment := createTestRouteEnvironment(t)
+	traitsCatalog := environment.Catalog
+
+	environment.Integration.Spec.Traits = map[string]v1alpha1.TraitSpec{
+		"route": {
+			Configuration: map[string]string{
+				"tls-termination": string(routev1.TLSTerminationEdge),
+			},
+		},
+	}
 
-	err = traitCatalog.apply(&environment)
+	err := traitsCatalog.apply(environment)
 
 	assert.Nil(t, err)
 	assert.NotEmpty(t, environment.ExecutedTraits)


Mime
View raw message