Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added annotations support for route trait #4664

Merged
merged 7 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -538,3 +539,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))

}