From 320ad08096a1dd215ae5e2006653fb397ee011ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ol=C5=A1iak?= <56640450+realMartinez@users.noreply.github.com> Date: Fri, 11 Aug 2023 09:24:28 +0200 Subject: [PATCH] feat: added annotations support for route trait (#4664) * Added annotation support for Route trait * chore: added unit test * chore: added unit tests for route annotations * doc: added annotations documentation * doc: cli example edit * chore: unit test edit * chore: fixed documentation example --------- Co-authored-by: Martin Olsiak --- pkg/apis/camel/v1/trait/route.go | 5 +++++ pkg/trait/route.go | 5 +++++ pkg/trait/route_test.go | 26 ++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) 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)) + +}