Skip to content

Commit

Permalink
chore: test fix, annotation append, doc edit
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Olsiak committed Sep 13, 2023
1 parent 95c794e commit f03ff6d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/camel/v1/trait/knative_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
//
Expand Down
7 changes: 5 additions & 2 deletions pkg/trait/knative_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 7 additions & 11 deletions pkg/trait/knative_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"reflect"
"testing"

routev1 "github.com/openshift/api/route/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -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))

}

0 comments on commit f03ff6d

Please sign in to comment.