From 65929f11cfbd9ff7dd30ecf828210735c175de83 Mon Sep 17 00:00:00 2001 From: Alex Mamoukarys Date: Sun, 1 Dec 2024 15:36:44 -0500 Subject: [PATCH 1/2] Added feature flag for default timeout --- .../v1alpha1/requestreply_defaults.go | 3 +- pkg/apis/feature/features.go | 38 ++++++++++++++----- pkg/apis/feature/flag_names.go | 26 +++++++------ 3 files changed, 44 insertions(+), 23 deletions(-) diff --git a/pkg/apis/eventing/v1alpha1/requestreply_defaults.go b/pkg/apis/eventing/v1alpha1/requestreply_defaults.go index ee73d0d6a7c..c05f915d104 100644 --- a/pkg/apis/eventing/v1alpha1/requestreply_defaults.go +++ b/pkg/apis/eventing/v1alpha1/requestreply_defaults.go @@ -20,6 +20,7 @@ import ( "context" "k8s.io/utils/ptr" + "knative.dev/eventing/pkg/apis/feature" "knative.dev/pkg/apis" ) @@ -30,7 +31,7 @@ func (rr *RequestReply) SetDefaults(ctx context.Context) { func (rrs *RequestReplySpec) SetDefaults(ctx context.Context) { if rrs.Timeout == nil || *rrs.Timeout == "" { - rrs.Timeout = ptr.To("30s") + rrs.Timeout = ptr.To(feature.FromContextOrDefaults(ctx).RequestReplyDefaultTimeout()) } if rrs.CorrelationAttribute == "" { diff --git a/pkg/apis/feature/features.go b/pkg/apis/feature/features.go index 98eeb2907ca..db162838e05 100644 --- a/pkg/apis/feature/features.go +++ b/pkg/apis/feature/features.go @@ -67,6 +67,10 @@ const ( // DefaultOIDCDiscoveryURL is the default OIDC Discovery URL used in most Kubernetes clusters. DefaultOIDCDiscoveryBaseURL Flag = "https://kubernetes.default.svc" + + // DefaultRequestReplyTimeout is a value for RequestReplyDefaultTimeout that indicates to timeout + // a RequestReply resource after 30 seconds by default. + DefaultRequestReplyTimeout Flag = "30s" ) // Flags is a map containing all the enabled/disabled flags for the experimental features. @@ -75,16 +79,17 @@ type Flags map[string]Flag func newDefaults() Flags { return map[string]Flag{ - KReferenceGroup: Disabled, - DeliveryRetryAfter: Disabled, - DeliveryTimeout: Enabled, - KReferenceMapping: Disabled, - TransportEncryption: Disabled, - OIDCAuthentication: Disabled, - EvenTypeAutoCreate: Disabled, - NewAPIServerFilters: Disabled, - AuthorizationDefaultMode: AuthorizationAllowSameNamespace, - OIDCDiscoveryBaseURL: DefaultOIDCDiscoveryBaseURL, + KReferenceGroup: Disabled, + DeliveryRetryAfter: Disabled, + DeliveryTimeout: Enabled, + KReferenceMapping: Disabled, + TransportEncryption: Disabled, + OIDCAuthentication: Disabled, + EvenTypeAutoCreate: Disabled, + NewAPIServerFilters: Disabled, + AuthorizationDefaultMode: AuthorizationAllowSameNamespace, + OIDCDiscoveryBaseURL: DefaultOIDCDiscoveryBaseURL, + RequestReplyDefaultTimeout: DefaultRequestReplyTimeout, } } @@ -151,6 +156,19 @@ func (e Flags) OIDCDiscoveryBaseURL() string { return string(discoveryUrl) } +func (e Flags) RequestReplyDefaultTimeout() string { + if e == nil { + return string(DefaultRequestReplyTimeout) + } + + timeout, ok := e[RequestReplyDefaultTimeout] + if !ok { + return string(DefaultRequestReplyTimeout) + } + + return string(timeout) // TODO, check this, check this whole function really +} + func (e Flags) String() string { return fmt.Sprintf("%+v", map[string]Flag(e)) } diff --git a/pkg/apis/feature/flag_names.go b/pkg/apis/feature/flag_names.go index e21056eb444..b6cc1b750fc 100644 --- a/pkg/apis/feature/flag_names.go +++ b/pkg/apis/feature/flag_names.go @@ -17,16 +17,18 @@ limitations under the License. package feature const ( - KReferenceGroup = "kreference-group" - DeliveryRetryAfter = "delivery-retryafter" - DeliveryTimeout = "delivery-timeout" - KReferenceMapping = "kreference-mapping" - TransportEncryption = "transport-encryption" - EvenTypeAutoCreate = "eventtype-auto-create" - OIDCAuthentication = "authentication-oidc" - NodeSelectorLabel = "apiserversources-nodeselector-" - CrossNamespaceEventLinks = "cross-namespace-event-links" - NewAPIServerFilters = "new-apiserversource-filters" - AuthorizationDefaultMode = "default-authorization-mode" - OIDCDiscoveryBaseURL = "oidc-discovery-base-url" + KReferenceGroup = "kreference-group" + DeliveryRetryAfter = "delivery-retryafter" + DeliveryTimeout = "delivery-timeout" + KReferenceMapping = "kreference-mapping" + TransportEncryption = "transport-encryption" + EvenTypeAutoCreate = "eventtype-auto-create" + OIDCAuthentication = "authentication-oidc" + NodeSelectorLabel = "apiserversources-nodeselector-" + CrossNamespaceEventLinks = "cross-namespace-event-links" + NewAPIServerFilters = "new-apiserversource-filters" + AuthorizationDefaultMode = "default-authorization-mode" + OIDCDiscoveryBaseURL = "oidc-discovery-base-url" + RequestReplyDefaultTimeout = "requestreply-default-timeout" // TODO check this + ) From 093eb19a30c30b79a93ea2849bd534bf5482e25c Mon Sep 17 00:00:00 2001 From: Alex Mamoukarys Date: Wed, 4 Dec 2024 21:30:19 -0500 Subject: [PATCH 2/2] Removed resolved TODO comments --- pkg/apis/feature/features.go | 2 +- pkg/apis/feature/flag_names.go | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/apis/feature/features.go b/pkg/apis/feature/features.go index db162838e05..cfe379141d0 100644 --- a/pkg/apis/feature/features.go +++ b/pkg/apis/feature/features.go @@ -166,7 +166,7 @@ func (e Flags) RequestReplyDefaultTimeout() string { return string(DefaultRequestReplyTimeout) } - return string(timeout) // TODO, check this, check this whole function really + return string(timeout) } func (e Flags) String() string { diff --git a/pkg/apis/feature/flag_names.go b/pkg/apis/feature/flag_names.go index b6cc1b750fc..ba163868c72 100644 --- a/pkg/apis/feature/flag_names.go +++ b/pkg/apis/feature/flag_names.go @@ -29,6 +29,5 @@ const ( NewAPIServerFilters = "new-apiserversource-filters" AuthorizationDefaultMode = "default-authorization-mode" OIDCDiscoveryBaseURL = "oidc-discovery-base-url" - RequestReplyDefaultTimeout = "requestreply-default-timeout" // TODO check this - + RequestReplyDefaultTimeout = "requestreply-default-timeout" )