This is an automated email from the ASF dual-hosted git repository.
nferraro pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git
The following commit(s) were added to refs/heads/main by this push:
new 8d163c5 Fix Route Trait Crash
8d163c5 is described below
commit 8d163c53cc23b0d28ddd003a6f5c337eee0bc68c
Author: Kyle Cooley <[email protected]>
AuthorDate: Mon May 24 17:31:36 2021 -0500
Fix Route Trait Crash
---
pkg/trait/route.go | 28 ++++++++++++++++------------
pkg/trait/route_test.go | 14 ++++++++++++++
2 files changed, 30 insertions(+), 12 deletions(-)
diff --git a/pkg/trait/route.go b/pkg/trait/route.go
index 4cc05f6..c664ff5 100644
--- a/pkg/trait/route.go
+++ b/pkg/trait/route.go
@@ -82,12 +82,14 @@ func (t *routeTrait) IsAllowedInProfile(profile
v1.TraitProfile) bool {
func (t *routeTrait) Configure(e *Environment) (bool, error) {
if t.Enabled != nil && !*t.Enabled {
- e.Integration.Status.SetCondition(
- v1.IntegrationConditionExposureAvailable,
- corev1.ConditionFalse,
- v1.IntegrationConditionRouteNotAvailableReason,
- "explicitly disabled",
- )
+ if e.Integration != nil {
+ e.Integration.Status.SetCondition(
+ v1.IntegrationConditionExposureAvailable,
+ corev1.ConditionFalse,
+ v1.IntegrationConditionRouteNotAvailableReason,
+ "explicitly disabled",
+ )
+ }
return false, nil
}
@@ -98,12 +100,14 @@ func (t *routeTrait) Configure(e *Environment) (bool,
error) {
t.service = e.Resources.GetUserServiceForIntegration(e.Integration)
if t.service == nil {
- e.Integration.Status.SetCondition(
- v1.IntegrationConditionExposureAvailable,
- corev1.ConditionFalse,
- v1.IntegrationConditionRouteNotAvailableReason,
- "no target service found",
- )
+ if e.Integration != nil {
+ e.Integration.Status.SetCondition(
+ v1.IntegrationConditionExposureAvailable,
+ corev1.ConditionFalse,
+ v1.IntegrationConditionRouteNotAvailableReason,
+ "no target service found",
+ )
+ }
return false, nil
}
diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go
index 11b7eea..764fedc 100644
--- a/pkg/trait/route_test.go
+++ b/pkg/trait/route_test.go
@@ -140,6 +140,20 @@ func TestRoute_Disabled(t *testing.T) {
assert.Nil(t, route)
}
+func TestRoute_Configure_IntegrationKitOnly(t *testing.T) {
+ name := xid.New().String()
+ environment := createTestRouteEnvironment(t, name)
+ environment.Integration = nil
+
+ routeTrait := newRouteTrait().(*routeTrait)
+ enabled := false
+ routeTrait.Enabled = &enabled
+
+ result, err := routeTrait.Configure(environment)
+ assert.False(t, result)
+ assert.Nil(t, err)
+}
+
func TestRoute_TLS(t *testing.T) {
name := xid.New().String()
environment := createTestRouteEnvironment(t, name)