Skip to content

Conversation

@mdelapenya
Copy link
Member

What does this PR do?

Use the Run function in redpanda

Why is it important?

Migrate modules to the new API, improving consistency and leveraging the latest testcontainers functionality.

Breaking Changes

BREAKING CHANGE: The Option type signature has changed to return an error:

  • Old: type Option func(*options)
  • New: type Option func(*options) error

All option functions now return error (returning nil for success). The WithListener option now properly validates and returns errors for invalid host:port formats instead of silently ignoring them.

Related issues

🤖 Generated with Claude Code

BREAKING CHANGE: Option type now returns error

- Changed Option type to return error for proper error handling
- Migrated from GenericContainer to testcontainers.Run()
- Process custom options before building moduleOpts
- Listener network validation happens after user options (as final step)
- WithListener now returns errors for invalid host:port format
- All option functions return error (nil for success)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@mdelapenya mdelapenya requested a review from a team as a code owner October 8, 2025 10:05
@mdelapenya mdelapenya added chore Changes that do not impact the existing functionality breaking change Causing compatibility issues. labels Oct 8, 2025
@netlify
Copy link

netlify bot commented Oct 8, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 5165ec1
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68e647f3da075900089b6170
😎 Deploy Preview https://deploy-preview-3430--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 project configuration.

@coderabbitai
Copy link

coderabbitai bot commented Oct 8, 2025

Summary by CodeRabbit

  • New Features

    • More reliable startup and readiness checks, including TLS-aware health probing.
    • Clearer, actionable errors for invalid listener host/port configurations.
    • Improved handling of TLS and authentication settings with consolidated environment configuration.
  • Bug Fixes

    • Consistent application order of configuration reduces race conditions and misconfiguration issues.
    • Improved error messages across configuration and run paths.
  • Refactor

    • Reworked container configuration into a modular pipeline for stability and clarity.
    • Configuration options now return errors; callers should handle potential failures during option application.

Walkthrough

Option builders now return errors (type Option func(*options) error). Redpanda container creation was refactored from mutating a GenericContainerRequest to composing moduleOpts (WithEnv/WithFiles/WithWaitStrategy/etc.) and calling testcontainers.Run, with aggregated env/files, listener validation, and updated readiness/TLS handling.

Changes

Cohort / File(s) Summary
Option signature and builders
modules/redpanda/options.go
Changed Option from func(*options) to func(*options) error; updated all option builders to return error (nil on success); added input validation errors (listener host/port split, port parsing).
Run refactor to modular options
modules/redpanda/redpanda.go
Replaced in-place GenericContainerRequest mutation with assembled moduleOpts passed to testcontainers.Run; aggregate env vars and files (TLS, bootstrap) and apply via WithEnv/WithFiles; introduced withListeners option factory (validates networks/ports and sets aliases); adjusted readiness wait and TLS readiness logic; moved some image/version checks to image parsing.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant RP as Redpanda.Run
  participant Opts as moduleOpts (With*)
  participant TC as testcontainers.Run
  participant C as Container

  User->>RP: Run(ctx, image, opts...)
  RP->>RP: Build defaults, parse options (Option now returns error)
  alt Option returns error
    RP-->>User: return error
  end
  RP->>Opts: Add WithConfigModifier / WithExposedPorts / WithEntrypoint / WithCmd / WithWaitStrategy
  RP->>RP: Aggregate env vars (auth) and files (TLS, bootstrap)
  RP->>Opts: WithEnv (conditional)
  RP->>Opts: WithFiles (conditional)
  RP->>Opts: Append user opts
  RP->>Opts: withListeners(...) (conditional, validates networks/ports)
  RP->>TC: Run(ctx, image, moduleOpts...)
  alt Run error
    TC-->>RP: error
    RP-->>User: return error
  else Success
    TC-->>RP: Container
    RP->>C: Post-run waits (TLS/readiness as needed)
    RP-->>User: return module with container handle
  end

  note right of RP: Wasm enabled/disabled by image version
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

chore

Poem

I hopped through opts with careful cheer,
Errors caught so builds are clear,
Ports aligned and TLS in tow,
With Run I leap — containers go! 🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly indicates the scope “redpanda” and succinctly describes the main change of switching to the Run function, following a conventional commit style and signalling the breaking change with the exclamation mark.
Description Check ✅ Passed The description clearly outlines the purpose and importance of using the Run function, details the breaking Option signature change, and links related issues, all of which align directly with the changes introduced in the pull request.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1498340 and 5165ec1.

📒 Files selected for processing (1)
  • modules/redpanda/redpanda.go (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
modules/redpanda/redpanda.go (6)
modules/redpanda/options.go (1)
  • Option (88-88)
options.go (8)
  • WithConfigModifier (56-62)
  • WithExposedPorts (454-459)
  • WithEntrypoint (438-443)
  • WithCmd (462-467)
  • WithWaitStrategy (366-368)
  • WithEnv (75-85)
  • WithFiles (524-529)
  • CustomizeRequestOption (28-28)
wait/host_port.go (1)
  • ForMappedPort (79-81)
container.go (2)
  • ContainerFile (110-115)
  • Container (41-73)
wait/http.go (1)
  • ForHTTP (149-151)
generic.go (1)
  • GenericContainerRequest (21-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: test (1.25.x, modules/redpanda) / test: modules/redpanda/1.25.x
  • GitHub Check: test (1.24.x, modules/redpanda) / test: modules/redpanda/1.24.x
  • GitHub Check: Analyze (go)

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mdelapenya mdelapenya removed the chore Changes that do not impact the existing functionality label Oct 8, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
modules/redpanda/redpanda.go (1)

217-223: wait.ForHTTP is passed a port, not a path — will misbehave

ForHTTP expects a path; set the port via WithPort. Current code may never probe the Admin API correctly.

-    waitHTTP := wait.ForHTTP(defaultAdminAPIPort).
-        WithStatusCodeMatcher(func(status int) bool {
+    waitHTTP := wait.ForHTTP("/").
+        WithPort(nat.Port(defaultAdminAPIPort)).
+        WithStatusCodeMatcher(func(status int) bool {
             // Redpanda's admin API returns 404 for requests to "/".
             return status == http.StatusNotFound
         })
🧹 Nitpick comments (3)
modules/redpanda/options.go (1)

152-168: Consider returning an error for invalid HTTP proxy auth method

New Option signature enables input validation. Instead of silently defaulting to "none", return an error to surface misconfiguration early. If preserving old behavior is desired, consider adding a strict variant.

Example:

 func WithHTTPProxyAuthMethod(method HTTPProxyAuthMethod) Option {
   switch method {
   case HTTPProxyAuthMethodNone, HTTPProxyAuthMethodHTTPBasic, HTTPProxyAuthMethodOIDC:
     return func(o *options) error {
       o.HTTPProxyAuthenticationMethod = method
       return nil
     }
   default:
-    return func(o *options) error {
-      // Invalid method, default to "none"
-      o.HTTPProxyAuthenticationMethod = HTTPProxyAuthMethodNone
-      return nil
-    }
+    return func(o *options) error {
+      return fmt.Errorf("invalid HTTP proxy auth method: %q", method)
+    }
   }
 }
modules/redpanda/redpanda.go (2)

433-448: Minor: clarify comment and param name in isAtLeastVersion

Comment mentions v8.x; function compares against provided min version (e.g., 23.3). Consider updating for clarity.

-// isAtLeastVersion returns true if the base image (without tag) is in a version or above
-func isAtLeastVersion(image, major string) bool {
+// isAtLeastVersion returns true if the image tag is >= the given semantic version (e.g., "23.3")
+func isAtLeastVersion(image, minVersion string) bool {
   parts := strings.Split(image, ":")
   version := parts[len(parts)-1]
 ...
-  if semver.IsValid(version) {
-    return semver.Compare(version, "v"+major) >= 0 // version >= v8.x
+  if semver.IsValid(version) {
+    return semver.Compare(version, "v"+minVersion) >= 0
   }

193-215: Comment numbering is inconsistent (duplicate 9, out-of-order 6/7)

Clean up step numbering for readability.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da9df18 and 8397a4b.

📒 Files selected for processing (2)
  • modules/redpanda/options.go (7 hunks)
  • modules/redpanda/redpanda.go (5 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
modules/redpanda/options.go (5)
modules/opensearch/options.go (1)
  • Option (22-22)
modules/gcloud/gcloud.go (1)
  • Option (65-65)
modules/elasticsearch/options.go (1)
  • Option (27-27)
modules/couchbase/options.go (1)
  • Option (7-7)
modules/rabbitmq/options.go (1)
  • Option (44-44)
modules/redpanda/redpanda.go (4)
modules/redpanda/options.go (1)
  • Option (88-88)
options.go (9)
  • ContainerCustomizer (22-24)
  • WithConfigModifier (56-62)
  • WithExposedPorts (454-459)
  • WithEntrypoint (438-443)
  • WithCmd (462-467)
  • WithWaitStrategy (366-368)
  • WithEnv (75-85)
  • WithFiles (524-529)
  • CustomizeRequestOption (28-28)
container.go (2)
  • ContainerFile (110-115)
  • Container (41-73)
generic.go (1)
  • GenericContainerRequest (21-27)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: test (1.25.x, modules/redpanda) / test: modules/redpanda/1.25.x
  • GitHub Check: test (1.24.x, modules/redpanda) / test: modules/redpanda/1.24.x
  • GitHub Check: Analyze (go)
🔇 Additional comments (2)
modules/redpanda/options.go (1)

88-94: Option now returns error and satisfies ContainerCustomizer — good alignment

Type change and NOOP Customize keep options composable while enabling early validation via errors. Looks good.

modules/redpanda/redpanda.go (1)

112-131: Ordering and use of user-provided opts look correct

Defaults first, then user opts to allow overrides, then listeners. Good.

@mdelapenya mdelapenya merged commit 7ae3814 into testcontainers:main Oct 8, 2025
17 checks passed
@mdelapenya mdelapenya deleted the use-run-claude-redpanda branch October 8, 2025 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Causing compatibility issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant