Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
// starterScript {
starterScriptContent = `#!/bin/bash
source /etc/confluent/docker/bash-config
export KAFKA_ADVERTISED_LISTENERS=%s,BROKER://%s:9092
export KAFKA_ADVERTISED_LISTENERS="%s,BROKER://%s:9092${EXTRA_ADVERTISED_LISTENERS:+,${EXTRA_ADVERTISED_LISTENERS}}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify which variable name is used by docs/tests/code.
rg -n -C2 'EXTRA_KAFKA_ADVERTISED_LISTENERS|EXTRA_ADVERTISED_LISTENERS'

Repository: testcontainers/testcontainers-go

Length of output: 499


🏁 Script executed:

# Search across entire codebase for any mention of EXTRA_KAFKA_ADVERTISED_LISTENERS
rg -i 'EXTRA_KAFKA' --type-list | head -20
rg 'EXTRA_KAFKA_ADVERTISED_LISTENERS' -t go -t md -t txt --type-list
find . -type f \( -name "*.md" -o -name "*.txt" -o -name "*README*" \) | head -20

Repository: testcontainers/testcontainers-go

Length of output: 1447


🏁 Script executed:

# Check kafka_test.go for any test related to extra listeners
rg -A5 -B5 'EXTRA.*ADVERTISED|extra.*listener' modules/kafka/kafka_test.go

Repository: testcontainers/testcontainers-go

Length of output: 58


🏁 Script executed:

# Look for any documentation or comments mentioning the feature name
rg -C3 'EXTRA_ADVERTISED_LISTENERS' modules/kafka/

Repository: testcontainers/testcontainers-go

Length of output: 697


🏁 Script executed:

# Explicit search for EXTRA_KAFKA_ADVERTISED_LISTENERS
rg 'EXTRA_KAFKA_ADVERTISED_LISTENERS' --max-count 10

Repository: testcontainers/testcontainers-go

Length of output: 58


🏁 Script executed:

# Read the kafka_test.go file to see test coverage
cat modules/kafka/kafka_test.go

Repository: testcontainers/testcontainers-go

Length of output: 2915


🏁 Script executed:

# Search for any docs mentioning kafka advertised listeners
rg -l 'advertised.*listener|KAFKA_ADVERTISED' --type md --type txt

Repository: testcontainers/testcontainers-go

Length of output: 58


Fix environment variable name mismatch in starter script

Line 24 uses EXTRA_ADVERTISED_LISTENERS, but this inconsistency with the documented feature name means users following the intended API contract will not have their settings applied. The code currently references an environment variable that does not appear elsewhere in the codebase or documentation.

🔧 Proposed fix
-export KAFKA_ADVERTISED_LISTENERS="%s,BROKER://%s:9092${EXTRA_ADVERTISED_LISTENERS:+,${EXTRA_ADVERTISED_LISTENERS}}"
+export KAFKA_ADVERTISED_LISTENERS="%s,BROKER://%s:9092${EXTRA_KAFKA_ADVERTISED_LISTENERS:+,${EXTRA_KAFKA_ADVERTISED_LISTENERS}}"

Additionally, the existing test in kafka_test.go only validates the BROKER:// URL format and does not cover the extra advertised listeners append behavior. Consider adding a test to verify that extra listeners are properly applied when the environment variable is set.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export KAFKA_ADVERTISED_LISTENERS="%s,BROKER://%s:9092${EXTRA_ADVERTISED_LISTENERS:+,${EXTRA_ADVERTISED_LISTENERS}}"
export KAFKA_ADVERTISED_LISTENERS="%s,BROKER://%s:9092${EXTRA_KAFKA_ADVERTISED_LISTENERS:+,${EXTRA_KAFKA_ADVERTISED_LISTENERS}}"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@modules/kafka/kafka.go` at line 24, Mismatch between the exported env var
name and the documented feature: replace the incorrect env var name used in the
export string inside modules/kafka/kafka.go (the export
KAFKA_ADVERTISED_LISTENERS line that currently references
EXTRA_ADVERTISED_LISTENERS) with the documented environment variable name used
by the feature (ensure the token exactly matches the name used in docs/other
code), and then extend kafka_test.go to set that env var and assert that its
value is appended to the computed KAFKA_ADVERTISED_LISTENERS (add a test case
that sets the env var and verifies the EXTRA listeners are included after
BROKER://%s:9092).

echo Starting Kafka KRaft mode
sed -i '/KAFKA_ZOOKEEPER_CONNECT/d' /etc/confluent/docker/configure
echo 'kafka-storage format --ignore-formatted -t "$(kafka-storage random-uuid)" -c /etc/kafka/kafka.properties' >> /etc/confluent/docker/configure
Expand Down
Loading