This is an automated email from the ASF dual-hosted git repository.

pcongiusti 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 1207e6afd feat: added annotations support for route trait (#4664)
1207e6afd is described below

commit 1207e6afd17bab8c6fab1feeae44fc87d5f80445
Author: Martin OlÅ¡iak <[email protected]>
AuthorDate: Fri Aug 11 09:24:28 2023 +0200

    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 <[email protected]>
---
 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 66c242975..3bef73712 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 250816360..933eba3d4 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 73697cbfc..ae8d335a9 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"
@@ -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))
+
+}

Reply via email to