You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
🎁 Add a delivery: block under run.kafka so a function consuming from Kafka can bound and tune how the runtime sidecar delivers records to it. Fields mirror Knative's DeliverySpec: retry (retries after the first attempt; omit for unlimited, 0 for a single attempt), backoffPolicy (exponential default or linear), backoffDelay, backoffMaxDelay, and timeout (per-attempt request timeout).
🎁 The keda deployer injects each field onto the Kafka runtime sidecar as the matching FUNCTION_DELIVERY_* env var (timeout as FUNCTION_REQUEST_TIMEOUT). An unset field is omitted so the runtime keeps its own default — existing functions are unaffected.
🎁 Validate the block both in Function.Validate() and as a keda deploy-time preflight (the on-cluster deploy path bypasses Function.Validate), rejecting a malformed retry/backoff/timeout value before it can crash-loop the sidecar at startup.
🎁 Pin DefaultKafkaRuntimeImage to the v0.2.0 adapter release, which is the release that reads the FUNCTION_DELIVERY_* env vars, so the delivery settings take effect on deploy.
Previously the sidecar always ran its built-in defaults (unlimited exponential retries, 100ms → 30s), so a poison-pill record (one the function can never accept) wedged a partition forever and operators had no way to cap retries or change the backoff without hand-editing the deployment.
The runtime side that reads these env vars shipped in knative-extensions/func-adapter-kafka#29 and is released as adapter v0.2.0. This PR pins DefaultKafkaRuntimeImage to v0.2.0 (final commit), so the injected FUNCTION_DELIVERY_* env vars are acted on by the released sidecar. A failed delivery attempt — non-2xx, a per-attempt timeout, or a dropped connection — counts toward the finite retry budget (matching Knative Eventing); with the default unlimited budget nothing is ever dropped.
Testing
Verified end to end on a kind + Strimzi cluster: deploy-time validation of the delivery block, the FUNCTION_DELIVERY_* env injected onto the runtime sidecar, and the runtime's bounded-retry / exhaustion / unlimited behavior (a poison-pill record is dropped once the budget is exhausted with its offset committed; the unlimited default never drops). Step-by-step instructions: https://gist.github.com/aliok/f1742f938f9f16d890fc2f4c1ffd1780
Automated integration/E2E coverage is tracked separately in #3956 (func side) and knative-extensions/func-adapter-kafka#30 (the real-broker harness where these delivery scenarios will be automated).
`run.kafka` now accepts a `delivery:` block to bound and tune record delivery to the function: `retry`, `backoffPolicy`, `backoffDelay`, `backoffMaxDelay`, and `timeout`. When the retry budget is exhausted the runtime skips the record and commits its offset so a failing record no longer wedges a partition. Omitting the block (or any field) preserves the previous behavior.
The Kafka runtime sidecar now supports a bounded delivery retry
budget, but func.yaml had no way to configure it: a function
consuming from Kafka always ran the sidecar's defaults (unlimited
exponential retries), so an operator could not cap retries, change
the backoff, or set a per-attempt timeout without hand-editing the
deployment.
Add a delivery: block under run.kafka mirroring Knative's
DeliverySpec (retry, backoffPolicy, backoffDelay, backoffMaxDelay,
timeout). The keda deployer injects each field as the matching
FUNCTION_DELIVERY_* env var (timeout as FUNCTION_REQUEST_TIMEOUT)
onto the sidecar; an unset field is omitted so the runtime keeps its
default and existing functions are unaffected.
retry is a pointer so an explicit 0 (single attempt, fail fast) is
distinct from an omitted field (unlimited). Values are validated both
in Function.Validate and as a keda deploy-time preflight, since the
on-cluster deploy path bypasses Function.Validate.
Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all
knative-prowBot
added
approved
🤖 PR has been approved by an approver from all required OWNERS files.
size/L
🤖 PR changes 100-499 lines, ignoring generated files.
labels
Nov 5, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Active moderate validation inconsistencies can let invalid Kafka configurations pass preflight and fail at sidecar startup, and the schema and documented feature behavior remain incomplete.
Adds configurable Kafka record-delivery retries, backoff, and per-attempt timeout settings under run.kafka.delivery, forwarding them to the Kafka runtime sidecar while preserving existing defaults when fields are omitted. Runtime behavior depends on a forthcoming func-adapter-kafka release.
Changes:
Adds DeliverySpec configuration, schema support, and validation.
Injects delivery settings into Kafka sidecar environment variables.
Adds function, deployment, serialization, validation, and environment-mapping tests.
File
Summary
schema/func_yaml-schema.json
Adds the DeliverySpec schema and exposes it under run.kafka.delivery.
pkg/keda/deployer.go
Adds KEDA deploy-time validation for Kafka delivery settings.
pkg/k8s/deployer.go
Maps delivery configuration to Kafka runtime sidecar environment variables.
pkg/k8s/deployer_test.go
Tests delivery environment propagation, omission behavior, and explicit retry values.
pkg/functions/function.go
Defines DeliverySpec and validates retry, policy, duration, and cross-field values.
pkg/functions/function_test.go
Tests YAML round-tripping and delivery validation cases.
Addresses review feedback on the delivery-retries work, closing gaps
where an invalid or misleading run.kafka config could reach the cluster
or be silently reinterpreted.
The keda deployer validated the required fields, security, and delivery
block only when a kafka scaler trigger was present. But the embedded k8s
deployer injects the runtime sidecar (and its broker/TLS/SASL/delivery
env) whenever run.kafka is set, independent of the scaler, so an invalid
run.kafka on an http-triggered (or untriggered) function slipped through
and crash-looped -- or silently misconfigured -- the sidecar. Move those
checks to a run.kafka != nil gate; only the scaler-specific guards (the
"kafka trigger but no run.kafka" error and the ScaledObject name-length
check) stay gated on a kafka trigger.
ValidateKafkaDelivery now:
- rejects retry == math.MaxInt, the runtime's "unlimited" sentinel, so an
explicit finite budget can never be silently reinterpreted as unlimited;
- accepts only the canonical lowercase backoffPolicy tokens, matching the
runtime's raw env comparison (a mixed-case value would otherwise pass
here but fall through to the default at runtime);
- compares effective backoff values, applying the runtime defaults for an
omitted side, so a one-sided override (e.g. backoffDelay above the
default backoffMaxDelay) is caught at deploy time rather than at runtime
startup. The defaults are duplicated with a keep-in-sync note since the
runtime sidecar is a separate module.
Also emit the retry schema minimum via jsonschema_extras (the jsonschema
tag does not emit minimum), regenerate the schema, and document the
delivery block in the func.yaml reference.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The raw Kubernetes deployer bypasses the new validation, allowing invalid delivery settings to reach the generated Deployment and cause adapter parsing failures.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Validate delivery settings in the raw Kubernetes deployer
pkg/k8s/deployer.go:1194
kafkaSidecarContainer is also used by the raw Kubernetes deployer, but raw Deployer.Deploy and Client.Deploy do not call Function.Validate; only the KEDA wrapper runs the new preflight. As a result, a direct raw deploy with (for example) backoffDelay: "soon" still creates a Deployment containing the invalid env var, and the adapter exits while parsing it. Validate kafka.Delivery in this path as well (before appending the env vars) so the advertised preflight is enforced for every deployer path.
The keda deployer runs a run.kafka.delivery preflight, but the raw k8s
Deployer.Deploy and Client.Deploy paths never call Function.Validate, so
a direct raw deploy with a malformed value (e.g. backoffDelay: "soon")
still built a Deployment containing the bad env var, and the adapter
exited while parsing it at startup.
kafkaSidecarContainer is the single chokepoint every deployer builds the
runtime sidecar through (the raw k8s deployer directly, keda via
embedding), so validate kafka.Delivery there, before appending the env
vars. The keda preflight still runs the same check earlier -- so it can
fail before the raw Deployment is created -- and this is the backstop that
guarantees the advertised preflight is enforced on every deployer path.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Approval should wait until func-adapter-kafka#29 is released and the DefaultKafkaRuntimeImage is pinned to a compatible version, because startup, retry/backoff, and offset-commit behavior cannot be validated against the current v0.1.0 image.
The validation code is correct, but two explanatory comments (and their
test counterparts) described the runtime's behavior wrongly -- a latent
trap, since a maintainer trusting them could relax the checks believing
they preserve parity with the adapter this work targets.
backoffPolicy: the runtime is case-insensitive (it lowercases before
matching), not a raw-token comparison. func's lowercase-only check is a
deliberate canonical-form choice (matching the docs and schema enum), not
a mirror of the runtime; say so.
retry == math.MaxInt: the runtime has no MaxInt "unlimited" sentinel
(unlimited is retry < 0, default -1). The real hazard is that the runtime
computes total attempts as retry + 1, which overflows to a negative budget
at exactly math.MaxInt and drops the first failed record. Reword to cite
the overflow, matching why the runtime itself rejects the same value.
Also rename base/max to baseVal/maxVal to stop shadowing the builtins.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because the change relies on an unreleased default sidecar image for its advertised retry behavior and leaves the documented timeout option’s zero-value semantics unclear.
The Delivery tuning reference lumped a non-2xx response, a timeout, and
a dropped connection together as failures bounded by the finite retry
budget. That is misleading: the runtime spends the budget only on
failures attributable to the record -- a non-2xx rejection or a
per-attempt timeout -- while a dropped connection (the function was
unreachable during a restart or scale-up) is retried indefinitely and
never exhausts the budget, so an outage does not drop good records.
Correct the intro sentence to draw that distinction and note in the
exhaustion paragraph that only record-attributable failures count
toward exhaustion, matching the adapter behavior and the delivery guide.
A prior change split delivery failures into record-attributable ones
(non-2xx, timeout) that spend the finite retry budget and unreachable
ones (dropped connection) that retry forever. The adapter has since
adopted the Knative Eventing model, where every failed attempt counts
toward the budget regardless of cause.
Restore the original wording: a failed attempt (non-2xx, a timeout, or a
dropped connection) is retried and counts toward the budget, and a
finite budget exhausts on any such failures. This matches the adapter
and the delivery guide again.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Approval is deferred because the feature depends on an unreleased func-adapter-kafka implementation and a future compatible DefaultKafkaRuntimeImage pin, requiring human verification of cross-repository release sequencing and end-to-end compatibility.
The Kafka runtime sidecar was pinned to v0.1.0, which predates the
configurable delivery-retry support. The run.kafka.delivery settings this
branch adds are passed to the sidecar as FUNCTION_DELIVERY_* env vars,
and v0.1.0 does not understand them, so the feature would be silently
inert against the pinned image.
Bump DefaultKafkaRuntimeImage to v0.2.0, the func-adapter-kafka release
that consumes those env vars, so delivery tuning takes effect on deploy.
aliok
changed the title
WIP: feat: configurable bounded delivery retries for run.kafka
feat: configurable bounded delivery retries for run.kafka
Nov 9, 2026
Not blocking. #3956 doesn't cover the delivery block yet. Could you add a case there? For example, set retry: 0 with a handler that always returns 500. Then check that the group lag drains to 0 and the sidecar logs that the budget is exhausted. That pins the env var names between func and the adapter, so a later image bump can't silently turn this block into a no-op again.
/lgtm
/approve
/hold
Unhold whenever you please, whether you want to fold this in here or defer it to a later PR.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
approved🤖 PR has been approved by an approver from all required OWNERS files.kind/enhancementFeature additions or improvements to existinglgtm🤖 PR is ready to be merged.size/XL🤖 PR changes 500-999 lines, ignoring generated files.
3 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
delivery:block underrun.kafkaso a function consuming from Kafka can bound and tune how the runtime sidecar delivers records to it. Fields mirror Knative'sDeliverySpec:retry(retries after the first attempt; omit for unlimited,0for a single attempt),backoffPolicy(exponentialdefault orlinear),backoffDelay,backoffMaxDelay, andtimeout(per-attempt request timeout).FUNCTION_DELIVERY_*env var (timeoutasFUNCTION_REQUEST_TIMEOUT). An unset field is omitted so the runtime keeps its own default — existing functions are unaffected.Function.Validate()and as a keda deploy-time preflight (the on-cluster deploy path bypassesFunction.Validate), rejecting a malformed retry/backoff/timeout value before it can crash-loop the sidecar at startup.DefaultKafkaRuntimeImageto thev0.2.0adapter release, which is the release that reads theFUNCTION_DELIVERY_*env vars, so the delivery settings take effect on deploy.Previously the sidecar always ran its built-in defaults (unlimited exponential retries, 100ms → 30s), so a poison-pill record (one the function can never accept) wedged a partition forever and operators had no way to cap retries or change the backoff without hand-editing the deployment.
The runtime side that reads these env vars shipped in knative-extensions/func-adapter-kafka#29 and is released as adapter
v0.2.0. This PR pinsDefaultKafkaRuntimeImagetov0.2.0(final commit), so the injectedFUNCTION_DELIVERY_*env vars are acted on by the released sidecar. A failed delivery attempt — non-2xx, a per-attempt timeout, or a dropped connection — counts toward the finite retry budget (matching Knative Eventing); with the default unlimited budget nothing is ever dropped.Testing
Verified end to end on a kind + Strimzi cluster: deploy-time validation of the
deliveryblock, theFUNCTION_DELIVERY_*env injected onto the runtime sidecar, and the runtime's bounded-retry / exhaustion / unlimited behavior (a poison-pill record is dropped once the budget is exhausted with its offset committed; the unlimited default never drops). Step-by-step instructions: https://gist.github.com/aliok/f1742f938f9f16d890fc2f4c1ffd1780Automated integration/E2E coverage is tracked separately in #3956 (func side) and knative-extensions/func-adapter-kafka#30 (the real-broker harness where these delivery scenarios will be automated).
/kind enhancement
Relates to knative-extensions/func-adapter-kafka#10
Release Note
Docs