Skip to content

Commit

Permalink
feat: added annotations support for route trait (apache#4664)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
2 people authored and squakez committed Nov 3, 2023
1 parent 41a3c9f commit 320ad08
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/apis/camel/v1/trait/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
5 changes: 5 additions & 0 deletions pkg/trait/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ type routeTrait struct {
func newRouteTrait() Trait {
return &routeTrait{
BaseTrait: NewBaseTrait("route", 2200),
RouteTrait: traitv1.RouteTrait{
Annotations: map[string]string{},
Host: "",
},
}
}

Expand Down Expand Up @@ -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{
Expand Down
26 changes: 26 additions & 0 deletions pkg/trait/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ limitations under the License.
package trait

import (
"reflect"
"testing"

"github.com/rs/xid"
Expand Down Expand Up @@ -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))

}

0 comments on commit 320ad08

Please sign in to comment.