Skip to content

feat(kafka): use new apache/kafka-native docker image#2683

Draft
CTrando wants to merge 5 commits intotestcontainers:mainfrom
CTrando:cam-tc
Draft

feat(kafka): use new apache/kafka-native docker image#2683
CTrando wants to merge 5 commits intotestcontainers:mainfrom
CTrando:cam-tc

Conversation

@CTrando
Copy link

@CTrando CTrando commented Aug 5, 2024

What does this PR do?

Uses the new apache/kafka-native docker image instead of the confluent local docker image. The kafka native docker image is much faster (startup time is maybe a second once the image is downloaded).

Trying to see if there is a desire from the community to use this. I can also add support for authentication mechanisms like SASL_PLAINTEXT if desired.

A current limitation of this however is that the desired host port must be known at container creation time - unlike before where we could dynamically pick a port at runtime. The way it was done before was a bit strange, it was running a kafka instance after the container had already started up I believe, which allowed it to pick the right port to use. Here, when we start up the kafka container it must know the port already.

We can still support picking random ports with some tricks like this, but there's no guarantee there won't be collisions.

Also I realize some of these changes may cause unavoidable breaking changes, so I'm happy to make a v2 module.

Why is it important?

Related issues

@netlify
Copy link

netlify bot commented Aug 5, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit dc22413
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/681ad739743e0100089e7a05
😎 Deploy Preview https://deploy-preview-2683--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.


// validateKRaftVersion validates if the image version is compatible with KRaft mode,
// which is available since version 7.0.0.
func validateKRaftVersion(fqName string) error {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

every apache/kafka-native image supports kraft


hostname := inspect.Config.Hostname

code, r, err := container.Exec(context.Background(), []string{"cat", "/usr/sbin/testcontainers_start.sh"})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this script doesn't exist anymore in the kafka image - also I didn't think it was necessary to check advertisted listeners, considering if it's set incorrectly, the other tests would fail because kafka wouldn't work in the first place

ctx := context.Background()

kafkaContainer, err := kafka.Run(ctx, "confluentinc/confluent-local:7.5.0", kafka.WithClusterID("kraftCluster"))
kafkaContainer, err := kafka.Run(ctx, "apache/kafka-native:3.8.0", kafka.WithClusterID("kraftCluster"))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: need some more tests on the client side to demonstrate this works + add tests for setting host port

* main: (302 commits)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.2.2 to 7.1.5 (testcontainers#3137)
  chore(deps): bump github.com/shirou/gopsutil/v4 from 4.25.1 to 4.25.4 (testcontainers#3133)
  chore(deps): bump github.com/docker/docker from 28.0.1+incompatible to 28.1.1+incompatible (testcontainers#3152)
  feat(memcached): add memcached module (testcontainers#3132)
  fix(etcd): single node etcd cluster access (testcontainers#3149)
  feat(valkey): add TLS support for Valkey (testcontainers#3131)
  fix(dockermodelrunner): wait for the model to be pulled (testcontainers#3125)
  fix(localstack): remove checksum before parsing version (testcontainers#3130)
  fix(dockermodelrunner): dependency with socat
  chore: prepare for next minor development cycle (0.38.0)
  chore: use new version (v0.37.0) in modules and examples
  fix: handle stopped containers more gracefully when reuse is enabled (testcontainers#3062)
  feat(gcloud): add option to run firestore in datastore mode (testcontainers#3009)
  feat: support for mounting images (testcontainers#3044)
  chore(ci): close PR if it was sent from main (testcontainers#3123)
  feat: add `WithReuseByName` for modifying Generic Container Requests (testcontainers#3064)
  chore(deps): bump github/codeql-action from 3.28.15 to 3.28.16 (testcontainers#3120)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.2.2 to 7.1.5 (testcontainers#3119)
  chore(deps): bump github.com/magiconair/properties from 1.8.9 to 1.8.10 (testcontainers#3118)
  chore(ci): exclude more files for a full-blown build (testcontainers#3122)
  ...
@mdelapenya
Copy link
Member

@CTrando thanks for opening this PR, and sorry for getting to it that late.

As I'm not a Kafka expert, I wonder if we want to provide a different flavour of kafka for the native image to avoid changing the existing behaviours.

@eddumelendez wdyt?

@mdelapenya mdelapenya changed the title Use new apache/kafka-native docker image for kafka module feat(kafka): use new apache/kafka-native docker image May 7, 2025
@mabrarov
Copy link
Contributor

Hi @CTrando,

FYI, this can be helpful / connected:

  1. [Enhancement]: Kafka Module: graceful shutdown #2206 (comment) (why apache/kafka-native cannot be a choice for some teams).
  2. confluentinc/confluent-local:7.5.0 -> bitnami/kafka:4.0 mabrarov/testcontainers-go-kafka-2206#1 (similar approach can be used in this PR).

Thank you.

@mabrarov
Copy link
Contributor

mabrarov commented May 27, 2025

Hi,

FYI, support of both bitnami/kafka:4.0 and apache/kafka-native:3.9.1 images is implemented in mabrarov/testcontainers-go-kafka-2206#2. Feel free to use that PR in this one if find it useful.

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants