Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(termination)!: make container termination timeout configurable #2926

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

moogacs
Copy link

@moogacs moogacs commented Dec 19, 2024

What does this PR do?

  • extend Terminate() method with optional configuration for timeout configuration.
  • moved the terminationOptions under container to give the ability to make timeout, etc configurable via a functional option.
  • moved cleaning up under Terminate() function.

Why is it important?

  • Terminate() became broken with latest release version with latest release 0.34.0 Terminate() require handle for errors "is already in progress"
  • this is CleanupContainer method signature and to use it in down streams that will require many refactors because it expects testing.TB
func CleanupContainer(tb testing.TB, ctr Container, options ...TerminateOption) {

so with this change it will give the ability to configure the timeout and move the cleanup logic under termination

Related issues

a unit test added and shall be tested with all the existed pipelines

Copy link

netlify bot commented Dec 19, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 31203a9
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/676bf2d0a34d940008eb276b
😎 Deploy Preview https://deploy-preview-2926--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.

@moogacs moogacs marked this pull request as ready for review December 19, 2024 23:39
@moogacs moogacs requested a review from a team as a code owner December 19, 2024 23:39
@mdelapenya mdelapenya added feature New functionality or new behaviors on the existing one breaking change Causing compatibility issues. labels Dec 20, 2024
@moogacs moogacs changed the title feat(termination): make container termination timeout configurable feat(termination)!: make container termination timeout configurable Dec 20, 2024
Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

Thanks for PR, seems like a good idea, unfortunately this approach doesn't work with an interface design, see comments for details.

cleanup.go Outdated
@@ -16,21 +15,21 @@ type terminateOptions struct {
}

// TerminateOption is a type that represents an option for terminating a container.
type TerminateOption func(*terminateOptions)
type TerminateOption func(*DockerContainer)
Copy link
Collaborator

Choose a reason for hiding this comment

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

bug: This ties the container implementation to the concrete DockerContainer type, which would prevent other types implementing Container for example the incoming ollama change.

We could maintain the dedicated type but export it and the fields, which could then be embedded in others.

The challenge with that is you can't rely on the interface to ensure an implementation is complete so it may be better to bite the bullet and make them concrete options @mdelapenya thoughts?

Copy link
Author

@moogacs moogacs Dec 20, 2024

Choose a reason for hiding this comment

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

yeah, i had similar feeling, but wasn't sure if shall i introduce a separate type, when i was opening this PR i tried to make as minimal breaking change but seems it has to be. open for suggestions

i like the idea of maintain the dedicated type but export it and the fields

Copy link
Collaborator

Choose a reason for hiding this comment

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

I initially thought the dedicated type would work, but that wont ensure that all Container implementations support the options, which I'm not a fan of as a consumer would be left wondering why their options didn't work.

Copy link
Author

Choose a reason for hiding this comment

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

the other thought i had before i come to this was introducing it in the ContainerRequest and add getter in the container interface

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought about setters too, but I think that would make it much harder to discover for users.

I can't think of any perfect solution ATM, something mull over.

Copy link
Author

Choose a reason for hiding this comment

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

i have made a change and revert it to make sure it uses terminateOptions instead of the dependency on DockerContainer type.

also added more test to show case the usage and the changes of configuration

defaults of volumes is nil, timeout is 10 and context is passed already on Terminate() , lmk wdyt ?

cleanup.go Show resolved Hide resolved
docker.go Outdated Show resolved Hide resolved
@moogacs moogacs requested a review from stevenh December 21, 2024 16:02
Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

Thanks for fleshing out what this looks like, I've done a review on how it stands and will discuss with @mdelapenya in the new year the pros and cons of functional options vs require args.

modules/etcd/etcd.go Show resolved Hide resolved
docker.go Outdated Show resolved Hide resolved
docker.go Outdated Show resolved Hide resolved
docker_test.go Outdated Show resolved Hide resolved
docker_test.go Show resolved Hide resolved
docker_test.go Show resolved Hide resolved
docker_test.go Show resolved Hide resolved
docker_test.go Outdated Show resolved Hide resolved
@moogacs
Copy link
Author

moogacs commented Dec 23, 2024

@stevenh thanks for feedback, i have address the comments. looking forward, Happy new year 😊

Copy link
Collaborator

@stevenh stevenh left a comment

Choose a reason for hiding this comment

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

Sorry to be a pain, but looking at what you've done with this, we should actually make the fields private with methods to avoid any ambiguity as to their use by other types, see suggestion in cleanup.go.

docker.go Outdated Show resolved Hide resolved
docker_test.go Outdated Show resolved Hide resolved
docker.go Outdated Show resolved Hide resolved
docker.go Outdated Show resolved Hide resolved
docker.go Outdated Show resolved Hide resolved
cleanup.go Outdated Show resolved Hide resolved
@moogacs moogacs requested a review from stevenh December 25, 2024 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Causing compatibility issues. feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: response from daemon: removal of container x is already in progress on calling Terminate()
3 participants