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

allow filter networks by dangling status #14643

Merged

Conversation

clobrano
Copy link
Contributor

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?

Added support for `network ls --filter dangling=true/false`

@clobrano clobrano force-pushed the feature/network/list/dangling/dev branch from 9341185 to 4b12339 Compare June 17, 2022 15:20
@rhatdan
Copy link
Member

rhatdan commented Jun 17, 2022

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)
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

@Luap99 Thoughts?

Copy link
Member

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.

@rhatdan
Copy link
Member

rhatdan commented Jun 17, 2022

Doesn't this need a man page update?

@clobrano clobrano force-pushed the feature/network/list/dangling/dev branch from 4b12339 to 9bf8343 Compare June 17, 2022 16:22
@clobrano
Copy link
Contributor Author

Doesn't this need a man page update?

yes indeed, I did not think about it

@clobrano clobrano force-pushed the feature/network/list/dangling/dev branch from 9bf8343 to cff7dad Compare June 17, 2022 16:27
@clobrano clobrano force-pushed the feature/network/list/dangling/dev branch from cff7dad to c6e0fca Compare June 17, 2022 17:33
@clobrano
Copy link
Contributor Author

I noticed a test is failing on the API. I will look into it

pkg/domain/infra/abi/network.go Outdated Show resolved Hide resolved
pkg/domain/infra/abi/network.go Show resolved Hide resolved
@clobrano clobrano force-pushed the feature/network/list/dangling/dev branch from c6e0fca to 09f7c1d Compare June 18, 2022 12:08
@clobrano
Copy link
Contributor Author

clobrano commented Jun 18, 2022

I noticed a test is failing on the API. I will look into it

A test in test/apiv2/35-networks.at is expecting an error since "dangling" was considered an invalid filter, while now it is supported.

ok 763 [35-networks] GET networks?filters={"id":["b385480e1e5da54a3cf0f17cd44e5a193ea3ab2757a1c28723f495a4edfe4cf8"]} : .[0].Id=b385480e1e5da54a3cf0f17cd44e5a193ea3ab2757a1c28723f495a4edfe4cf8
         not ok 764 [35-networks] GET networks?filters={"dangling":["1"]} : status
         #  expected: 500
         #    actual: 200

Is it ok if I change the expected result of this test?

@clobrano clobrano force-pushed the feature/network/list/dangling/dev branch 2 times, most recently from 8ea4a1d to 3525681 Compare June 20, 2022 18:41
@clobrano
Copy link
Contributor Author

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.

if filterDangling {
var err error

wantDangling, err = strconv.ParseBool(val[0])
Copy link
Member

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":[]}'

Copy link
Contributor Author

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

Copy link
Contributor Author

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)

Copy link
Member

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.

Copy link
Contributor Author

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"

if filterDangling {
danglingFilterFunc, err := ic.createDanglingFilterFunc(wantDangling)
if err != nil {
return make([]types.Network, 0), err
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return make([]types.Network, 0), err
return nil, err

test/apiv2/35-networks.at Outdated Show resolved Hide resolved
@Luap99
Copy link
Member

Luap99 commented Jun 21, 2022

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.

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]>
@clobrano clobrano force-pushed the feature/network/list/dangling/dev branch from 3525681 to 4a981c4 Compare June 21, 2022 15:51
@mheon
Copy link
Member

mheon commented Jun 21, 2022

LGTM

One test still running, even though Github shows everything as green except Total Success

@baude
Copy link
Member

baude commented Jun 21, 2022

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 21, 2022

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 21, 2022
@baude
Copy link
Member

baude commented Jun 21, 2022

is this ready for merge?

@rhatdan
Copy link
Member

rhatdan commented Jun 21, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jun 21, 2022
@openshift-ci openshift-ci bot merged commit 8863e13 into containers:main Jun 21, 2022
@clobrano clobrano deleted the feature/network/list/dangling/dev branch June 21, 2022 18:29
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support "podman network ls --filter dangling=true"
5 participants