-
Notifications
You must be signed in to change notification settings - Fork 613
feat: filter containers seen by docker-gen #623
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
base: main
Are you sure you want to change the base?
Conversation
dee75d0
to
b8b39af
Compare
b8b39af
to
938fec6
Compare
938fec6
to
d3962a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new -container-filter option to docker-gen, allowing users to filter containers in a more flexible and composable way. Key changes include the removal of legacy filtering logic from the template package, updates to generator and configuration modules to support the new filter option, and corresponding updates in command-line options and documentation.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
internal/template/template.go | Removed legacy filterRunning logic and updated logging to use unfiltered containers, assuming filtering now occurs upstream. |
internal/generator/generator.go | Updated getContainers signature and internal filtering logic to use config.ContainerFilter; removed the All flag. |
internal/context/context.go & context_test.go | Removed the PublishedAddresses method and its test, as published/exposed filtering is now handled via container filters. |
internal/config/config.go | Replaced OnlyExposed, OnlyPublished, and IncludeStopped flags with ContainerFilter. |
cmd/docker-gen/main.go | Added container-filter flag and updated default filter logic, along with documentation changes. |
README.md | Updated command option descriptions to reflect the new filtering option. |
Comments suppressed due to low confidence (3)
internal/context/context.go:107
- The PublishedAddresses method and its associated tests have been removed. Verify that no other part of the codebase relies on this functionality and that its removal is fully covered by the new container filtering approach.
func (r *RuntimeContainer) PublishedAddresses() []Address {
internal/template/template.go:153
- The removal of the filterRunning function means that filtering is now assumed to happen upstream. Ensure that the logging statement (which now logs the count of 'containers') still accurately reflects the intended filtered list; otherwise, update the log to avoid potential confusion.
contents := executeTemplate(config.Template, containers)
internal/generator/generator.go:400
- The removal of the All flag and the decision to always pass 'true' for All in the Docker client's ListContainersOptions should be carefully validated. Confirm that this new approach interacts correctly with the provided container filters under all expected scenarios.
All: true,
The PR add the
-container-filter
option to filter the containers that docker-gen will see.The option work pretty much like
-notify-filter
and can be used multiple times to combine filters with AND.This:
will result in docker-gen only seeing running container that possess the label
com.github.nginx-proxy.nginx
.Closes #276
Unfortunately Docker filter options for containers does not provide negative filtering, so #117 and #252 won't be entirely fixed by this.
Thanks @tarasov65536 for the inspiration.