diff --git a/pkg/apis/camel/v1/trait/knative_service.go b/pkg/apis/camel/v1/trait/knative_service.go index e29d625345..aa03a33856 100644 --- a/pkg/apis/camel/v1/trait/knative_service.go +++ b/pkg/apis/camel/v1/trait/knative_service.go @@ -28,7 +28,7 @@ type KnativeServiceTrait struct { Trait `property:",squash" json:",inline"` // The annotations added to route. // This can be used to set knative service specific annotations - // CLI usage example: -t "route.annotations.'haproxy.router.openshift.io/balance'=true" + // CLI usage example: -t "knative-service.annotations.'haproxy.router.openshift.io/balance'=true" Annotations map[string]string `property:"annotations" json:"annotations,omitempty"` // Configures the Knative autoscaling class property (e.g. to set `hpa.autoscaling.knative.dev` or `kpa.autoscaling.knative.dev` autoscaling). // diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go index 41bebec1c2..63b8f231ed 100644 --- a/pkg/trait/knative_service.go +++ b/pkg/trait/knative_service.go @@ -178,13 +178,16 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) (*serving.Service, e for k, v := range e.Integration.Annotations { serviceAnnotations[k] = v } - } else { - serviceAnnotations = t.Annotations } // Set Knative rollout if t.RolloutDuration != "" { serviceAnnotations[knativeServingRolloutDurationAnnotation] = t.RolloutDuration } + if t.Annotations != nil { + for k, v := range t.Annotations { + serviceAnnotations[k] = v + } + } revisionAnnotations := make(map[string]string) if e.Integration.Annotations != nil { diff --git a/pkg/trait/knative_service_test.go b/pkg/trait/knative_service_test.go index ea2e54c41f..ccf49b3d83 100644 --- a/pkg/trait/knative_service_test.go +++ b/pkg/trait/knative_service_test.go @@ -22,7 +22,6 @@ import ( "reflect" "testing" - routev1 "github.com/openshift/api/route/v1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -517,23 +516,20 @@ func createKnativeServiceTestEnvironment(t *testing.T, trait *traitv1.KnativeSer func TestServiceAnnotation(t *testing.T) { annotationsTest := map[string]string{"haproxy.router.openshift.io/balance": "true"} - environment := createTestRouteEnvironment(t, KnativeServiceTestName) - environment.Integration.Spec.Traits = v1.Traits{ - Route: &traitv1.RouteTrait{ - Annotations: map[string]string{"haproxy.router.openshift.io/balance": "true"}, - }, - } + environment := createKnativeServiceTestEnvironment(t, &traitv1.KnativeServiceTrait{ + 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 == KnativeServiceTestName + service := environment.Resources.GetKnativeService(func(s *serving.Service) bool { + return s.Name == KnativeServiceTestName }) - assert.NotNil(t, route) - assert.True(t, reflect.DeepEqual(route.GetAnnotations(), annotationsTest)) + assert.NotNil(t, service) + assert.True(t, reflect.DeepEqual(service.GetAnnotations(), annotationsTest)) }