containers / podman

Podman: A tool for managing OCI containers and pods.
https://podman.io
Apache License 2.0
23.48k stars 2.39k forks source link

support "podman network ls --filter dangling=true" #14595

Closed holgerschurig closed 2 years ago

holgerschurig commented 2 years ago

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind feature

Description

The docker.el module for Emacs (see https://github.com/Silex/docker.el) uses "podman network ls --filter dangling=true"). Unfortunately, Podman doesn't support this yet.

Steps to reproduce the issue:

Emacs runs first

$ podman network ls --format="[{{ json .ID }},{{ json .ID }},{{ json .Name }},{{ json .Driver }}]"

to get all networks available and then it runs

$ podman network ls --filter dangling=true --format="[{{ json .ID }},{{ json .ID }},{{ json .Name }},{{ json .Driver }}]"

to get only the dangling ones. It uses this information to mark the dangling ones for it's GUI display.

This last call however returns an error:

$ podman network ls --filter dangling=true --format="[{{ json .ID }},{{ json .ID }},{{ json .Name }},{{ json .Driver }}]"
Error: invalid filter "dangling"

Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

$ podman version
Client:       Podman Engine
Version:      4.2.0-dev
API Version:  4.2.0-dev
Go Version:   go1.17.11
Git Commit:   9fac1b335f681400a029e9d8014f45fa5634ec40
Built:        Tue Jun 14 13:53:13 2022
OS/Arch:      linux/amd64

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)

Sure

Commands that support dangling=true already

Emacs also uses

These commands support the dangling filter.

rhatdan commented 2 years ago

@cdoern PTAL

clobrano commented 2 years ago

Hey, I am new to podman and I'd like to work on this if possible

rhatdan commented 2 years ago

You got it.

clobrano commented 2 years ago

I had a look at it and, my assumptions are:

A: the filtering function is the one created in common/libnetwork/util/filters.go:createFilterFuncs() B: a similar functionality is already implemented in podman/pkg/domain/infra/abi/network.go:NetworkPrune()

About (A), I think I could even patch libnetwork, but the logic implemented in (B) makes use of the list of all containers, which I believe libnetwork does not have access to, nor it needs to know. I think this is also the reason why the same NetworkPrune() defines its own danglingFilterFunction() and pushes it into the list of filters given by libnetwork, which I think would be the same approach to be used here.

Regarding the tests, I think the new test shall go into test/e2e/network_test.go, together with the other podman network tests, is that right?

If that so, I could use GenerateNetworkConfig for testing the --filter dangling=true, since I believe a newly created network is automatically dangling.