diff --git a/pkg/apis/camel/v1/trait/route.go b/pkg/apis/camel/v1/trait/route.go index 29466b9cd2..10937dcc71 100644 --- a/pkg/apis/camel/v1/trait/route.go +++ b/pkg/apis/camel/v1/trait/route.go @@ -31,6 +31,11 @@ package trait // nolint: tagliatelle type RouteTrait struct { Trait `property:",squash" json:",inline"` + // The annotations added to route. + // This can be used to set route specific annotations + // For annotations options see https://docs.openshift.com/container-platform/3.11/architecture/networking/routes.html#route-specific-annotations + // CLI usage example: -t "route.annotations.'haproxy.router.openshift.io/balance'=true" + Annotations map[string]string `property:"annotations" json:"annotations,omitempty"` // To configure the host exposed by the route. Host string `property:"host" json:"host,omitempty"` // The TLS termination type, like `edge`, `passthrough` or `reencrypt`. diff --git a/pkg/trait/route.go b/pkg/trait/route.go index 008f716074..770b2efd38 100644 --- a/pkg/trait/route.go +++ b/pkg/trait/route.go @@ -43,6 +43,10 @@ type routeTrait struct { func newRouteTrait() Trait { return &routeTrait{ BaseTrait: NewBaseTrait("route", 2200), + RouteTrait: traitv1.RouteTrait{ + Annotations: map[string]string{}, + Host: "", + }, } } @@ -109,6 +113,7 @@ func (t *routeTrait) Apply(e *Environment) error { Labels: map[string]string{ v1.IntegrationLabel: e.Integration.Name, }, + Annotations: t.Annotations, }, Spec: routev1.RouteSpec{ Port: &routev1.RoutePort{ diff --git a/pkg/trait/route_test.go b/pkg/trait/route_test.go index a83839e0b6..fd9b9d967b 100644 --- a/pkg/trait/route_test.go +++ b/pkg/trait/route_test.go @@ -18,6 +18,7 @@ limitations under the License. package trait import ( + "reflect" "testing" "github.com/rs/xid" @@ -534,3 +535,28 @@ func TestRoute_WithCustomServicePort(t *testing.T) { route.Spec.Port.TargetPort.StrVal, ) } + +func TestRouteAnnotation(t *testing.T) { + annotationsTest := map[string]string{"haproxy.router.openshift.io/balance": "true"} + + name := xid.New().String() + environment := createTestRouteEnvironment(t, name) + environment.Integration.Spec.Traits = v1.Traits{ + Route: &traitv1.RouteTrait{ + Annotations: map[string]string{"haproxy.router.openshift.io/balance": "true"}, + }, + } + + traitsCatalog := environment.Catalog + err := traitsCatalog.apply(environment) + + assert.Nil(t, err) + + route := environment.Resources.GetRoute(func(r *routev1.Route) bool { + return r.ObjectMeta.Name == name + }) + + assert.NotNil(t, route) + assert.True(t, reflect.DeepEqual(route.GetAnnotations(), annotationsTest)) + +}