Conversation
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: aliok The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
aliok
force-pushed
the
remove-go-inprocess-kafka
branch
from
November 19, 2026 08:07
750c008 to
8515538
Compare
The Go cloudevents scaffolds branched on FUNC_TRANSPORT=kafka to consume Kafka in-process via func-go's kafka package. That package is removed; Kafka delivery is handled by the language-agnostic runtime adapter, which delivers records to the function over HTTP. On the cluster this path is already fully migrated. The in-process branch only affected local `func run` for Go -- the single language that shipped an in-process consumer. Local `func run` for Go Kafka functions therefore no longer consumes records; a sub-process mode that runs the adapter alongside the function locally will restore this for every language uniformly. Drops the func-go/kafka import from both cloudevents scaffolds, retidies their go.mod/go.sum (removing the now-unused sarama tree), and regenerates the embedded template bundle. The KAFKA_* env the local runners inject is left in place: it is the adapter's config contract, reused by the forthcoming sub-process mode.
Local `func run` + run.kafka had no working delivery: the runners injected FUNC_TRANSPORT=kafka + KAFKA_* onto the function, which only the now-removed Go in-process consumer read. Go functions regressed to a no-op locally and no other language ever had a local Kafka path. Run the language-agnostic adapter as a child process next to the function instead -- the local counterpart of the on-cluster sidecar. It consumes Kafka and POSTs each record to the function over loopback HTTP, committing only on a 2xx, so Kafka works for every language with no in-process code and local behavior matches deployed. - pkg/kafkaruntime embeds the adapter binary (go:embed) and extracts it to the func config dir, version-keyed and checksum-cached. - The adapter version is sourced from kafkaruntime.Version, which also builds DefaultKafkaRuntimeImage, keeping local and cluster in lockstep. - A Makefile step go-installs the pinned adapter module into the embed dir, so nothing is downloaded at run time. - The host runner starts the adapter after the function with KAFKA_* relocated to it plus FUNCTION_TARGET/LISTEN_ADDRESS, wired to the run context and job.Errors, with [kafka]-prefixed logs; FUNC_TRANSPORT is dropped. - Readiness gating reuses the existing probe, generalized to poll the adapter's /health/readiness too, so a bad broker or bad credentials fails `func run` fast. POC/WIP scope: embeds the host platform only (full release matrix is a TODO), the container-run backend is not yet wired (host runner only), and Kafka credential values pass through raw (Interpolate plus the unresolved-cluster-ref warning are a TODO).
The Kafka runtime that func run starts next to a function consuming from run.kafka was embedded only for the platform func was built on, was started by the host runner alone, and was configured from its own copy of the run.kafka-to-env mapping, which could drift from the one configuring the sidecar on the cluster. Embed the runtime for macOS, Linux and Windows on amd64 and arm64, built by make from the version pinned by kafkaruntime.Version, which also sets DefaultKafkaRuntimeImage, so the local runtime and the deployed sidecar are the same program. A func built without it (plain go build, other platforms) warns that records will not be delivered; FUNC_KAFKA_RUNTIME_BINARY can point it at a runtime binary instead. Start the runtime from Client.Run once the function is up, so it runs for containerized functions too, and configure it from the same mapping as the sidecar, so both always set the variables the runtime reads. A SASL credential given as a cluster reference cannot be resolved locally, so func run warns that authentication will fail. func run fails if the runtime does not become ready (unreachable broker, missing topic, bad credentials) or exits, rather than running a function that silently receives nothing. When it fails, it now stops the host function it started, which was left running, and the error of a runtime that crashes mid-run is no longer replaced by the result of stopping the run. Issue knative#4124
run.kafka.sasl.user and password accepted only inline values and
{{ secret:name:key }} / {{ configMap:name:key }} references. func run
cannot resolve a cluster reference, so running a function locally
against a SASL-secured broker meant writing the credentials into
func.yaml.
Accept {{ env:NAME }} as well, resolved from the environment func runs
in, as run.envs references are: func run passes the value to the local
Kafka runtime, and func deploy sets it on the runtime sidecar as a
literal value, so it is not kept in a Secret on the cluster. An unset
variable is an error naming the field.
func run stops the Kafka runtime it started when it exits normally, is interrupted or loses its terminal. A func process killed outright (kill -9) or crashing gets no chance to, so its runtime keeps running in the background: it goes on consuming and committing offsets with no one watching, and the next func run of the function shares the consumer group with it. Record each runtime in the function's run directory while it runs, and have the next func run of the function stop any recorded runtime whose func process is gone. A runtime is stopped only if its PID still runs the recorded executable, so a reused PID is never signaled, and a runtime whose func process is still running (a second func run of the function) is left alone.
Accepting {{ env:NAME }} in run.kafka.sasl.user and password changes
what func deploy writes to the cluster: the resolved credential
becomes a literal value on the Kafka runtime sidecar. That deserves
its own review and release note, so it moves to a separate change
against main.
Revert the validation, deploy-time resolution, schema and docs added
by "feat: accept env refs for Kafka SASL credentials". func run still
resolves {{ env:NAME }} in SASL credentials through Interpolate, as
for run.envs, which takes effect once validation accepts it.
Fix the issues review found in how func run starts and stops the Kafka runtime: - Interrupting the run while it waited for the runtime to become ready reported that the runtime exited before becoming ready, as the interrupt stops the runtime too. It is now reported as the cancellation. - FUNCTION_MAX_CONCURRENCY, which func never sets, reached the runtime from the shell. All inherited KAFKA_*, FUNCTION_* and LISTEN_ADDRESS variables are now dropped, so run.kafka alone configures it. - A leftover runtime was identified by its PID and executable only, which another runtime reusing the PID matches too, as all runtimes run the same executable. The record now holds the process start time as well, and both must match. - A container runner reports the function started once its published port accepts connections, which the engine's port proxy does before the function listens. The runtime is now started only once the function itself answers HTTP, so early deliveries are not dropped. - The runtime is ready once it joins the group, with or without partitions, not once partitions are assigned as the comments and docs said. Also test that the host runner stops a function that never becomes ready, and correct the docs' claim that Windows arm64 release builds include the runtime.
func run started an fkafka-runtime binary that a Makefile step built outside func's module and embedded per platform. A func installed with go install or built with a plain go build had no runtime, building func fetched the adapter module separately, the runtime's dependencies were invisible to tools scanning func's module, and the binary grew by about 11 MB. Require knative.dev/func-adapter-kafka in go.mod instead and run the runtime through a hidden kafka-runtime command: func run re-executes func (kn func when inlined into kn), which runs the adapter as its own fkafka-runtime command does. Every func build has the runtime, the release binary grows by about 3 MB, and pkg/kafkaruntime, the build script and the Makefile steps go away. DefaultKafkaRuntimeImage is a literal again, and a test keeps its tag equal to the version required in go.mod, so local runs and the sidecar keep using the same runtime version. FUNC_KAFKA_RUNTIME_BINARY still runs a given fkafka-runtime build instead.
By default a local run consumes as run.kafka.consumerGroup, the group the deployed function uses, so against a shared broker the two split the topic's partitions and offsets between them. This was documented, but nothing said so at run time. Print the topic and group once the runtime is ready, on stderr, so --json output stays parseable.
The unit tests drive a fake runtime, so nothing checked that func run delivers records with the real one: a change to the adapter's environment contract, readiness endpoint or exit behavior would go unnoticed. Add TestKafkaRun_Delivery, which runs the func binary against a broker, produces a record and checks that the function receives it intact and that its offset is committed, and TestKafkaRun_UnreachableBroker, which checks that the run fails. They need a broker reachable from the host (FUNC_E2E_KAFKA_BROKERS), which the cluster's Strimzi broker is not, so a new CI job runs them against an apache/kafka container through make test-e2e-kafka-run.
aliok
force-pushed
the
remove-go-inprocess-kafka
branch
from
December 1, 2026 19:58
8515538 to
543a684
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Design write-up: https://gist.github.com/ff624d15f7e91fd55bbc4b3083456d47
Local
func runwithrun.kafkahad no working delivery. The runners injectedFUNC_TRANSPORT=kafkaand theKAFKA_*config onto the function itself, which only the now-removed Go in-process consumer ever read. Go functions silently regressed to a no-op locally, and no other language ever had a local Kafka path at all.This runs the language-agnostic Kafka runtime adapter as a child process next to the function — the local counterpart of the on-cluster sidecar. The adapter consumes Kafka and POSTs each record to the function over loopback HTTP, committing the offset only on a 2xx. Kafka then works for every language locally with no in-process code, and local behavior matches what gets deployed.
pkg/kafkaruntime: embeds the adapter binary (go:embed) and extracts it to the func config dir, version-keyed and checksum-cached. The adapter version lives inkafkaruntime.Version, which also buildsDefaultKafkaRuntimeImage, keeping the local binary and the cluster sidecar image in lockstep.KAFKA_*config relocated onto it plusFUNCTION_TARGET/LISTEN_ADDRESS, wired to the run context andjob.Errors, with[kafka]-prefixed logs. Readiness gating is generalized to poll the adapter's/health/readinesstoo, so a bad broker or bad credentials failsfunc runfast.FUNC_TRANSPORT=kafka→ func-go's removedkafkapackage), retidy theirgo.mod/go.sum(removing the now-unused sarama tree), and regenerate the embedded template bundle.FUNC_TRANSPORT; the function no longer consumes Kafka in-process.go installs the pinned adapter module into the embed dir, so nothing is downloaded at run time./kind enhancement
Relates to #4124
Release Note
Docs