-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
allow filter networks by dangling status #14643
allow filter networks by dangling status #14643
Conversation
9341185
to
4b12339
Compare
Lint is not happy. |
@@ -144,6 +172,33 @@ func (ic *ContainerEngine) NetworkExists(ctx context.Context, networkname string | |||
|
|||
// Network prune removes unused cni networks | |||
func (ic *ContainerEngine) NetworkPrune(ctx context.Context, options entities.NetworkPruneOptions) ([]*entities.NetworkPruneReport, error) { | |||
// get all filters | |||
filters, err := netutil.GenerateNetworkPruneFilters(options.Filters) |
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.
Why isn't dangling filters done in the GenerateNetworkPruneFilters function?
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.
my understanding is that GenerateNetworkPruneFilters does not know (or has reasons to know) the list of all containers, which is needed by this feature.
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.
GenerateNetworkPruneFilters Generates a list of filters These filters can return your danglinFilterFunc?
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.
And I could see where I want to Prune all Networks without containers.
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.
GenerateNetworkPruneFilters comes from another repository, do you think it would be better to push this change there? However, I am not sure how to let common/libnetwork use the podman's ContainerEngine struct, then.
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.
@Luap99 Thoughts?
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.
I think it is cleaner to have it in podman. Adding to c/common would require ugly callback function just to get the container networks.
Doesn't this need a man page update? |
4b12339
to
9bf8343
Compare
yes indeed, I did not think about it |
9bf8343
to
cff7dad
Compare
cff7dad
to
c6e0fca
Compare
I noticed a test is failing on the API. I will look into it |
c6e0fca
to
09f7c1d
Compare
A test in
Is it ok if I change the expected result of this test? |
8ea4a1d
to
3525681
Compare
There are a couple of test still failing, but I don't think it's due to this changes. Let me know if there is anything from my side I can do. |
pkg/domain/infra/abi/network.go
Outdated
if filterDangling { | ||
var err error | ||
|
||
wantDangling, err = strconv.ParseBool(val[0]) |
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.
This can panic. You have to loop over all values here.
While unlikely it is possible that more than one dangling value is set:
'{"dangling":["1","0"]}'
or '{"dangling":[]}'
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.
yes, indeed, I will fix this
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.
however, being "dangling" a binary filter, I wonder if a good user experience would be to just error out if more than one value is set (or none).
Also to avoid to decide what to do when two valid, but opposite values are passed (like in your first example)
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.
Well what does docker do? AFAIK if both true and false are set it should just return all.
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.
good point, I just checked
❯ docker network ls --filter dangling=true --filter dangling=false
Error response from daemon: got more than one value for filter key "dangling"
pkg/domain/infra/abi/network.go
Outdated
if filterDangling { | ||
danglingFilterFunc, err := ic.createDanglingFilterFunc(wantDangling) | ||
if err != nil { | ||
return make([]types.Network, 0), err |
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.
return make([]types.Network, 0), err | |
return nil, err |
They do not look related to your change. so likely flakes. We can restart the tests manually. |
add the ability to filter networks by their dangling status via: `network ls --filter dangling=true/false` Fixes: containers#14595 Signed-off-by: Carlo Lobrano <[email protected]>
3525681
to
4a981c4
Compare
LGTM One test still running, even though Github shows everything as green except Total Success |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: baude, clobrano The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
is this ready for merge? |
/lgtm |
add the ability to filter networks by their dangling status via:
network ls --filter dangling=true/false
Fixes: #14595
Does this PR introduce a user-facing change?