You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by pc...@apache.org on 2023/09/13 14:19:56 UTC
[camel-k] branch main updated: feat: knative service trait annotation support (#4729)
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 c89127a54 feat: knative service trait annotation support (#4729)
c89127a54 is described below
commit c89127a54a08021845822edea45bdbb83a12e3b9
Author: Martin Olšiak <56...@users.noreply.github.com>
AuthorDate: Wed Sep 13 16:19:50 2023 +0200
feat: knative service trait annotation support (#4729)
* feat: annotation support for knative svc trait
* doc: annotation documentation
* chore: test fix, annotation append, doc edit
* chore: generated docs
---------
Co-authored-by: Martin Olsiak <ma...@gmail.com>
---
.../camel.apache.org_integrationplatforms.yaml | 14 ++++++++++++++
config/crd/bases/camel.apache.org_integrations.yaml | 7 +++++++
.../crd/bases/camel.apache.org_kameletbindings.yaml | 7 +++++++
config/crd/bases/camel.apache.org_pipes.yaml | 7 +++++++
docs/modules/ROOT/partials/apis/camel-k-crds.adoc | 9 +++++++++
docs/modules/traits/pages/knative-service.adoc | 6 ++++++
helm/camel-k/crds/crd-integration-platform.yaml | 14 ++++++++++++++
helm/camel-k/crds/crd-integration.yaml | 7 +++++++
helm/camel-k/crds/crd-kamelet-binding.yaml | 7 +++++++
helm/camel-k/crds/crd-pipe.yaml | 7 +++++++
pkg/apis/camel/v1/trait/knative_service.go | 4 ++++
pkg/apis/camel/v1/trait/zz_generated.deepcopy.go | 7 +++++++
pkg/trait/knative_service.go | 8 ++++++++
pkg/trait/knative_service_test.go | 21 +++++++++++++++++++++
resources/traits.yaml | 4 ++++
15 files changed, 129 insertions(+)
diff --git a/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
index 489d1a39d..f65b8207a 100644
--- a/config/crd/bases/camel.apache.org_integrationplatforms.yaml
+++ b/config/crd/bases/camel.apache.org_integrationplatforms.yaml
@@ -1258,6 +1258,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can be
+ used to set knative service specific annotations CLI usage
+ example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as Knative
service when all conditions hold: \n * Integration is using
@@ -3023,6 +3030,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can be
+ used to set knative service specific annotations CLI usage
+ example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as Knative
service when all conditions hold: \n * Integration is using
diff --git a/config/crd/bases/camel.apache.org_integrations.yaml b/config/crd/bases/camel.apache.org_integrations.yaml
index a0fb500ac..7a41808ee 100644
--- a/config/crd/bases/camel.apache.org_integrations.yaml
+++ b/config/crd/bases/camel.apache.org_integrations.yaml
@@ -7175,6 +7175,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can be
+ used to set knative service specific annotations CLI usage
+ example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as Knative
service when all conditions hold: \n * Integration is using
diff --git a/config/crd/bases/camel.apache.org_kameletbindings.yaml b/config/crd/bases/camel.apache.org_kameletbindings.yaml
index d6464e655..d3c4b9a6f 100644
--- a/config/crd/bases/camel.apache.org_kameletbindings.yaml
+++ b/config/crd/bases/camel.apache.org_kameletbindings.yaml
@@ -7466,6 +7466,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can
+ be used to set knative service specific annotations
+ CLI usage example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as
Knative service when all conditions hold: \n * Integration
diff --git a/config/crd/bases/camel.apache.org_pipes.yaml b/config/crd/bases/camel.apache.org_pipes.yaml
index bb6fbbb86..33fb3e7d1 100644
--- a/config/crd/bases/camel.apache.org_pipes.yaml
+++ b/config/crd/bases/camel.apache.org_pipes.yaml
@@ -7463,6 +7463,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can
+ be used to set knative service specific annotations
+ CLI usage example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as
Knative service when all conditions hold: \n * Integration
diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
index 736fe3e79..c5dba1aa0 100644
--- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
+++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc
@@ -6900,6 +6900,15 @@ are only relevant when the Camel route(s) use(s) an HTTP endpoint consumer.
+|`annotations` +
+map[string]string
+|
+
+
+The annotations added to route.
+This can be used to set knative service specific annotations
+CLI usage example: -t "knative-service.annotations.'haproxy.router.openshift.io/balance'=true"
+
|`class` +
string
|
diff --git a/docs/modules/traits/pages/knative-service.adoc b/docs/modules/traits/pages/knative-service.adoc
index e9729d059..9782199f9 100755
--- a/docs/modules/traits/pages/knative-service.adoc
+++ b/docs/modules/traits/pages/knative-service.adoc
@@ -29,6 +29,12 @@ The following configuration options are available:
| bool
| Can be used to enable or disable a trait. All traits share this common property.
+| knative-service.annotations
+| map[string]string
+| The annotations added to route.
+This can be used to set knative service specific annotations
+CLI usage example: -t "knative-service.annotations.'haproxy.router.openshift.io/balance'=true"
+
| knative-service.autoscaling-class
| string
| Configures the Knative autoscaling class property (e.g. to set `hpa.autoscaling.knative.dev` or `kpa.autoscaling.knative.dev` autoscaling).
diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml
index 489d1a39d..f65b8207a 100644
--- a/helm/camel-k/crds/crd-integration-platform.yaml
+++ b/helm/camel-k/crds/crd-integration-platform.yaml
@@ -1258,6 +1258,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can be
+ used to set knative service specific annotations CLI usage
+ example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as Knative
service when all conditions hold: \n * Integration is using
@@ -3023,6 +3030,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can be
+ used to set knative service specific annotations CLI usage
+ example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as Knative
service when all conditions hold: \n * Integration is using
diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml
index a0fb500ac..7a41808ee 100644
--- a/helm/camel-k/crds/crd-integration.yaml
+++ b/helm/camel-k/crds/crd-integration.yaml
@@ -7175,6 +7175,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can be
+ used to set knative service specific annotations CLI usage
+ example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as Knative
service when all conditions hold: \n * Integration is using
diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml
index d6464e655..d3c4b9a6f 100644
--- a/helm/camel-k/crds/crd-kamelet-binding.yaml
+++ b/helm/camel-k/crds/crd-kamelet-binding.yaml
@@ -7466,6 +7466,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can
+ be used to set knative service specific annotations
+ CLI usage example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as
Knative service when all conditions hold: \n * Integration
diff --git a/helm/camel-k/crds/crd-pipe.yaml b/helm/camel-k/crds/crd-pipe.yaml
index bb6fbbb86..33fb3e7d1 100644
--- a/helm/camel-k/crds/crd-pipe.yaml
+++ b/helm/camel-k/crds/crd-pipe.yaml
@@ -7463,6 +7463,13 @@ spec:
knative-service:
description: The configuration of Knative Service trait
properties:
+ annotations:
+ additionalProperties:
+ type: string
+ description: 'The annotations added to route. This can
+ be used to set knative service specific annotations
+ CLI usage example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
+ type: object
auto:
description: "Automatically deploy the integration as
Knative service when all conditions hold: \n * Integration
diff --git a/pkg/apis/camel/v1/trait/knative_service.go b/pkg/apis/camel/v1/trait/knative_service.go
index a474ec33f..aa03a3385 100644
--- a/pkg/apis/camel/v1/trait/knative_service.go
+++ b/pkg/apis/camel/v1/trait/knative_service.go
@@ -26,6 +26,10 @@ package trait
// +camel-k:trait=knative-service.
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 "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).
//
// Refer to the Knative documentation for more information.
diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
index 037173370..505fbfd0a 100644
--- a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
+++ b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go
@@ -542,6 +542,13 @@ func (in *KameletsTrait) DeepCopy() *KameletsTrait {
func (in *KnativeServiceTrait) DeepCopyInto(out *KnativeServiceTrait) {
*out = *in
in.Trait.DeepCopyInto(&out.Trait)
+ if in.Annotations != nil {
+ in, out := &in.Annotations, &out.Annotations
+ *out = make(map[string]string, len(*in))
+ for key, val := range *in {
+ (*out)[key] = val
+ }
+ }
if in.Target != nil {
in, out := &in.Target, &out.Target
*out = new(int)
diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go
index fb7bc0d1a..63b8f231e 100644
--- a/pkg/trait/knative_service.go
+++ b/pkg/trait/knative_service.go
@@ -58,6 +58,9 @@ var _ ControllerStrategySelector = &knativeServiceTrait{}
func newKnativeServiceTrait() Trait {
return &knativeServiceTrait{
BaseTrait: NewBaseTrait(knativeServiceTraitID, 1400),
+ KnativeServiceTrait: traitv1.KnativeServiceTrait{
+ Annotations: map[string]string{},
+ },
}
}
@@ -180,6 +183,11 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) (*serving.Service, e
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 6db7760d7..ccf49b3d8 100644
--- a/pkg/trait/knative_service_test.go
+++ b/pkg/trait/knative_service_test.go
@@ -19,6 +19,7 @@ package trait
import (
"path/filepath"
+ "reflect"
"testing"
"github.com/stretchr/testify/assert"
@@ -512,3 +513,23 @@ func createKnativeServiceTestEnvironment(t *testing.T, trait *traitv1.KnativeSer
return environment
}
+func TestServiceAnnotation(t *testing.T) {
+ annotationsTest := 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)
+
+ service := environment.Resources.GetKnativeService(func(s *serving.Service) bool {
+ return s.Name == KnativeServiceTestName
+ })
+
+ assert.NotNil(t, service)
+ assert.True(t, reflect.DeepEqual(service.GetAnnotations(), annotationsTest))
+
+}
diff --git a/resources/traits.yaml b/resources/traits.yaml
index 64b2a0e0e..5426e8202 100755
--- a/resources/traits.yaml
+++ b/resources/traits.yaml
@@ -985,6 +985,10 @@ traits:
type: bool
description: Can be used to enable or disable a trait. All traits share this common
property.
+ - name: annotations
+ type: map[string]string
+ description: 'The annotations added to route. This can be used to set knative
+ service specific annotations CLI usage example: -t "knative-service.annotations.''haproxy.router.openshift.io/balance''=true"'
- name: autoscaling-class
type: string
description: Configures the Knative autoscaling class property (e.g. to set `hpa.autoscaling.knative.dev`