From 9c45e364d06cd7977d6da9b454c9de8e56dc2c07 Mon Sep 17 00:00:00 2001 From: hernanguardado Date: Mon, 17 Jun 2024 18:54:20 -0400 Subject: [PATCH] Added TimeoutSeconds to knative-serving trait --- .../modules/ROOT/partials/apis/camel-k-crds.adoc | 10 ++++++++++ docs/modules/traits/pages/knative-service.adoc | 7 +++++++ helm/camel-k/crds/crd-integration-platform.yaml | 14 ++++++++++++++ helm/camel-k/crds/crd-integration-profile.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 | 5 +++++ pkg/apis/camel/v1/trait/zz_generated.deepcopy.go | 5 +++++ .../camel.apache.org_integrationplatforms.yaml | 14 ++++++++++++++ .../camel.apache.org_integrationprofiles.yaml | 14 ++++++++++++++ .../crd/bases/camel.apache.org_integrations.yaml | 7 +++++++ .../bases/camel.apache.org_kameletbindings.yaml | 7 +++++++ .../config/crd/bases/camel.apache.org_pipes.yaml | 7 +++++++ pkg/trait/knative_service.go | 3 +++ pkg/trait/knative_service_test.go | 16 ++++++++++++++++ 16 files changed, 144 insertions(+) diff --git a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc index 2dd82a59f9..df8614196f 100644 --- a/docs/modules/ROOT/partials/apis/camel-k-crds.adoc +++ b/docs/modules/ROOT/partials/apis/camel-k-crds.adoc @@ -7633,6 +7633,16 @@ Automatically deploy the integration as Knative service when all conditions hold * Integration is using the Knative profile * All routes are either starting from an HTTP based consumer or a passive consumer (e.g. `direct` is a passive consumer) +|`timeoutSeconds` + +int64 +| + + +The maximum duration in seconds that the request instance is allowed to respond to a request. +This field propagates to the integration pod's terminationGracePeriodSeconds + +Refer to the Knative documentation for more information. + |=== diff --git a/docs/modules/traits/pages/knative-service.adoc b/docs/modules/traits/pages/knative-service.adoc index 5d8ebbedf6..2a69ff7ee0 100755 --- a/docs/modules/traits/pages/knative-service.adoc +++ b/docs/modules/traits/pages/knative-service.adoc @@ -89,6 +89,13 @@ Refer to the Knative documentation for more information. * Integration is using the Knative profile * All routes are either starting from an HTTP based consumer or a passive consumer (e.g. `direct` is a passive consumer) +| knative-service.timeout-seconds +| int64 +| The maximum duration in seconds that the request instance is allowed to respond to a request. +This field propagates to the integration pod's terminationGracePeriodSeconds + +Refer to the Knative documentation for more information. + |=== // End of autogenerated code - DO NOT EDIT! (configuration) diff --git a/helm/camel-k/crds/crd-integration-platform.yaml b/helm/camel-k/crds/crd-integration-platform.yaml index 9bc5fb4702..de7182dabc 100644 --- a/helm/camel-k/crds/crd-integration-platform.yaml +++ b/helm/camel-k/crds/crd-integration-platform.yaml @@ -1504,6 +1504,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the @@ -3526,6 +3533,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the diff --git a/helm/camel-k/crds/crd-integration-profile.yaml b/helm/camel-k/crds/crd-integration-profile.yaml index a5f9689e59..7da5787ad3 100644 --- a/helm/camel-k/crds/crd-integration-profile.yaml +++ b/helm/camel-k/crds/crd-integration-profile.yaml @@ -1381,6 +1381,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the @@ -3286,6 +3293,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the diff --git a/helm/camel-k/crds/crd-integration.yaml b/helm/camel-k/crds/crd-integration.yaml index 41ef39a36a..251ecc09cc 100644 --- a/helm/camel-k/crds/crd-integration.yaml +++ b/helm/camel-k/crds/crd-integration.yaml @@ -7445,6 +7445,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the diff --git a/helm/camel-k/crds/crd-kamelet-binding.yaml b/helm/camel-k/crds/crd-kamelet-binding.yaml index 9f420d5280..334c08a9a3 100644 --- a/helm/camel-k/crds/crd-kamelet-binding.yaml +++ b/helm/camel-k/crds/crd-kamelet-binding.yaml @@ -7738,6 +7738,13 @@ spec: `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the + request instance is allowed to respond to a request. + This field propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option diff --git a/helm/camel-k/crds/crd-pipe.yaml b/helm/camel-k/crds/crd-pipe.yaml index 89703a6cc0..5bbb853389 100644 --- a/helm/camel-k/crds/crd-pipe.yaml +++ b/helm/camel-k/crds/crd-pipe.yaml @@ -7736,6 +7736,13 @@ spec: `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the + request instance is allowed to respond to a request. + This field propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option diff --git a/pkg/apis/camel/v1/trait/knative_service.go b/pkg/apis/camel/v1/trait/knative_service.go index aa03a33856..a43706daa3 100644 --- a/pkg/apis/camel/v1/trait/knative_service.go +++ b/pkg/apis/camel/v1/trait/knative_service.go @@ -68,4 +68,9 @@ type KnativeServiceTrait struct { // * Integration is using the Knative profile // * All routes are either starting from an HTTP based consumer or a passive consumer (e.g. `direct` is a passive consumer) Auto *bool `property:"auto" json:"auto,omitempty"` + // The maximum duration in seconds that the request instance is allowed to respond to a request. + // This field propagates to the integration pod's terminationGracePeriodSeconds + // + // Refer to the Knative documentation for more information. + TimeoutSeconds *int64 `property:"timeout-seconds" json:"timeoutSeconds,omitempty"` } diff --git a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go index c428ad5dfd..a17cfbd7b2 100644 --- a/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go +++ b/pkg/apis/camel/v1/trait/zz_generated.deepcopy.go @@ -645,6 +645,11 @@ func (in *KnativeServiceTrait) DeepCopyInto(out *KnativeServiceTrait) { *out = new(bool) **out = **in } + if in.TimeoutSeconds != nil { + in, out := &in.TimeoutSeconds, &out.TimeoutSeconds + *out = new(int64) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KnativeServiceTrait. diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml index 9bc5fb4702..de7182dabc 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationplatforms.yaml @@ -1504,6 +1504,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the @@ -3526,6 +3533,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml index a5f9689e59..7da5787ad3 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrationprofiles.yaml @@ -1381,6 +1381,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the @@ -3286,6 +3293,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the diff --git a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml index 41ef39a36a..251ecc09cc 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_integrations.yaml @@ -7445,6 +7445,13 @@ spec: default and must be expressed as a Golang `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the request + instance is allowed to respond to a request. This field + propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option applies the diff --git a/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml b/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml index 9f420d5280..334c08a9a3 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_kameletbindings.yaml @@ -7738,6 +7738,13 @@ spec: `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the + request instance is allowed to respond to a request. + This field propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option diff --git a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml index 89703a6cc0..5bbb853389 100644 --- a/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml +++ b/pkg/resources/config/crd/bases/camel.apache.org_pipes.yaml @@ -7736,6 +7736,13 @@ spec: `time.Duration` string representation, rounded to a second precision. type: string + timeoutSeconds: + description: "The maximum duration in seconds that the + request instance is allowed to respond to a request. + This field propagates to the integration pod's terminationGracePeriodSeconds + \n Refer to the Knative documentation for more information." + format: int64 + type: integer visibility: description: "Setting `cluster-local`, Knative service becomes a private service. Specifically, this option diff --git a/pkg/trait/knative_service.go b/pkg/trait/knative_service.go index 65c93b8b29..50c87a4514 100644 --- a/pkg/trait/knative_service.go +++ b/pkg/trait/knative_service.go @@ -286,6 +286,9 @@ func (t *knativeServiceTrait) getServiceFor(e *Environment) (*serving.Service, e }, } + if t.TimeoutSeconds != nil { + svc.Spec.ConfigurationSpec.Template.Spec.TimeoutSeconds = t.TimeoutSeconds + } replicas := e.Integration.Spec.Replicas isUpdateRequired := false diff --git a/pkg/trait/knative_service_test.go b/pkg/trait/knative_service_test.go index a084f4e29d..5fa1e8d10c 100644 --- a/pkg/trait/knative_service_test.go +++ b/pkg/trait/knative_service_test.go @@ -518,6 +518,22 @@ func TestKnativeServiceWithVisibility(t *testing.T) { assert.Equal(t, ksvc.Labels[knativeServingVisibilityLabel], "cluster-local") } +func TestKnativeServiceWithTimeoutSeconds(t *testing.T) { + timeoutSeconds := int64(44) + environment := createKnativeServiceTestEnvironment(t, &traitv1.KnativeServiceTrait{ + TimeoutSeconds: &timeoutSeconds, + }) + assert.NotEmpty(t, environment.ExecutedTraits) + assert.NotNil(t, environment.GetTrait("knative-service")) + + ksvc := environment.Resources.GetKnativeService(func(service *serving.Service) bool { + return service.Name == KnativeServiceTestName + }) + assert.NotNil(t, ksvc) + + assert.Equal(t, *ksvc.Spec.Template.Spec.TimeoutSeconds, int64(44)) +} + func createKnativeServiceTestEnvironment(t *testing.T, trait *traitv1.KnativeServiceTrait) *Environment { t.Helper()