Registry Mirror
Skip to content

Conversation

@aliok

@aliok aliok commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Changes

  • 🎁 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).

/kind enhancement

Relates to knative-extensions/func-adapter-kafka#10

Release Note

`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.

Docs


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.
@knative-prow

knative-prow Bot commented Nov 5, 2026

Copy link
Copy Markdown

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-prow knative-prow Bot added do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. kind/enhancement Feature additions or improvements to existing labels Nov 5, 2026
@knative-prow knative-prow Bot 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
@aliok
aliok requested a lite review from Copilot November 5, 2026 08:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

6 open issues
What changed in this PR

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.

Review effort: Lite

Comment thread pkg/functions/function.go Resolved
Comment thread pkg/functions/function.go Resolved
Comment thread pkg/functions/function.go Resolved
Comment thread pkg/functions/function.go Resolved
Comment thread pkg/keda/deployer.go Resolved
Comment thread pkg/functions/function.go Resolved
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.
@knative-prow knative-prow Bot added size/XL 🤖 PR changes 500-999 lines, ignoring generated files. and removed size/L 🤖 PR changes 100-499 lines, ignoring generated files. labels Nov 5, 2026
@aliok
aliok requested a lite review from Copilot November 5, 2026 08:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Medium severity 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.

6 resolved since last review

Review effort: Lite

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

No open issues 🎉

Review effort: Lite

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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

No open issues 🎉

Review effort: Lite

aliok added 2 commits November 9, 2026 12:20
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

No open issues 🎉

Review effort: Lite

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 aliok changed the title WIP: feat: configurable bounded delivery retries for run.kafka feat: configurable bounded delivery retries for run.kafka Nov 9, 2026
@aliok
aliok marked this pull request as ready for review November 9, 2026 20:13
@knative-prow knative-prow Bot removed the do-not-merge/work-in-progress 🤖 PR should not merge because it is a work in progress. label Nov 9, 2026
@gauron99

Copy link
Copy Markdown
Contributor

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.

@knative-prow knative-prow Bot added the do-not-merge/hold 🤖 PR should not merge because someone has issued a /hold command. label Nov 10, 2026
@knative-prow knative-prow Bot added the lgtm 🤖 PR is ready to be merged. label Nov 10, 2026
@knative-prow

knative-prow Bot commented Nov 10, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: aliok, gauron99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@aliok

aliok commented Nov 10, 2026

Copy link
Copy Markdown
Member Author

/unhold

@gauron99 thanks for the catch! I added a comment in #3956 for your findings.

@knative-prow knative-prow Bot removed the do-not-merge/hold 🤖 PR should not merge because someone has issued a /hold command. label Nov 10, 2026
@knative-prow
knative-prow Bot merged commit e8ed917 into knative:main Nov 10, 2026
73 of 74 checks passed
@aliok
aliok deleted the feat-kafka-delivery-retries branch November 10, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved 🤖 PR has been approved by an approver from all required OWNERS files. kind/enhancement Feature additions or improvements to existing lgtm 🤖 PR is ready to be merged. size/XL 🤖 PR changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants