Skip to content

Conversation

@mdelapenya
Copy link
Member

  • chore(etcd): use Run function
  • chore(etcd)!: make options return errors

What does this PR do?

Use the Run function in the etcd module

It also adds a breaking change in the etcd module by changing the signature of the etcd options.
Only those users of the module assigning the options to a variable are affected.
If you're just passing them as arguments, you don't have to do anything with this BC.

Why is it important?

Migrate modules to the new API

Related issues

@mdelapenya mdelapenya requested a review from a team as a code owner October 3, 2025 04:44
@mdelapenya mdelapenya added the breaking change Causing compatibility issues. label Oct 3, 2025
@mdelapenya mdelapenya self-assigned this Oct 3, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 3, 2025

Summary by CodeRabbit

  • New Features
    • Added option to mount a data directory with automatic permission handling.
    • Improved multi-node cluster setup for more consistent configuration across nodes.
  • Refactor
    • Streamlined container startup flow with consolidated option handling.
    • Enhanced error reporting during option application and container startup for clearer diagnostics.
  • Tests
    • Added test covering running with a mounted data directory.

Walkthrough

Refactors etcd module to build container via testcontainers.Run with option-based configuration, introduces error-returning options, adds data-dir post-start chmod via exec, updates cluster node creation to reuse Run, and adds a test validating WithDataDir behavior.

Changes

Cohort / File(s) Summary
Run flow refactor
modules/etcd/etcd.go
Switches from GenericContainer/ContainerRequest to testcontainers.Run with assembled module options; routes network, cmd, and cluster settings via options; adds PostStarts chmod for data dir using exec; updates cluster node spawning to reuse Run; adds error wrapping.
Options API changes
modules/etcd/options.go
Changes Option to return error; removes defaultOptions dependency on ContainerRequest; updates WithAdditionalArgs, WithDataDir, WithNodes, WithClusterToken, and internal setters to propagate errors; adds withClusterOptions aggregator with error handling; Customize remains no-op.
Tests
modules/etcd/etcd_test.go
Adds TestRunWithDataDir to run etcd with WithDataDir, execute etcdctl member list, and assert output contains "default".

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User code
  participant E as etcd.Run
  participant TC as testcontainers.Run
  participant EX as tcexec (PostStarts)
  participant N as Network

  U->>E: Run(ctx, img, options...)
  E->>E: Build moduleOpts (WithCmd, With... options)
  E->>N: Append WithNetwork(...)
  alt WithDataDir
    E->>E: Add PostStarts hook (chmod data dir)
  end
  E->>TC: Run(ctx, img, moduleOpts...)
  TC-->>E: Container or error

  opt Cluster nodes > 1
    loop For each additional node
      E->>E: Update cluster options (node index, names)
      E->>TC: Run(ctx, img, moduleOpts...)
    end
  end

  note over EX,E: On start, exec chmod to set data dir perms
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

chore

Suggested reviewers

  • stevenh

Poem

I hopped through opts, a tidy run,
From Generic fields to one-by-one.
A chmod squeak, post-start delight,
Clustered friends spin up just right.
Tests nibble greens—data dirs cheer!
Thump-thump: etcd’s now crystal clear. 🥕🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.33% which is insufficient. The required threshold is 80.00%. You can run `@coderabbitai generate docstrings` to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary change—migrating the etcd module to use the new Run function—while indicating the breaking change via the conventional commit “!” marker. It is concise, specific, and directly related to the changeset.
Description Check ✅ Passed The description clearly outlines the adoption of the Run function and the breaking change to option signatures in the etcd module, linking rationale and affected users in detail and directly relating to the changeset.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • 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 a5275d9 and a041373.

📒 Files selected for processing (3)
  • modules/etcd/etcd.go (4 hunks)
  • modules/etcd/etcd_test.go (1 hunks)
  • modules/etcd/options.go (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
modules/etcd/etcd_test.go (4)
modules/etcd/etcd.go (1)
  • Run (62-131)
modules/etcd/options.go (1)
  • WithDataDir (47-53)
testing.go (1)
  • CleanupContainer (91-97)
exec/processor.go (1)
  • Multiplexed (103-128)
modules/etcd/etcd.go (5)
options.go (4)
  • ContainerCustomizer (22-24)
  • WithExposedPorts (454-459)
  • WithCmd (462-467)
  • WithAdditionalLifecycleHooks (497-502)
modules/etcd/options.go (1)
  • Option (28-28)
lifecycle.go (2)
  • ContainerLifecycleHooks (43-55)
  • ContainerHook (38-38)
container.go (1)
  • Container (41-73)
exec/processor.go (1)
  • Multiplexed (103-128)
modules/etcd/options.go (2)
docker.go (1)
  • DockerNetwork (951-957)
options.go (1)
  • ContainerCustomizer (22-24)

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.

@netlify
Copy link

netlify bot commented Oct 3, 2025

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit a041373
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-go/deploys/68df54c07cfcdb0008c03823
😎 Deploy Preview https://deploy-preview-3409--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.

@mdelapenya mdelapenya changed the title chore!(etcd): use Run function chore(etcd)!: use Run function Oct 3, 2025
@mdelapenya mdelapenya merged commit 29480b8 into testcontainers:main Oct 3, 2025
17 of 18 checks passed
@mdelapenya mdelapenya deleted the use-run-etcd branch October 3, 2025 04:56
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