eclipse-kanto / container-management

container-management
Other
6 stars 10 forks source link

Add the option to remove all containers #205

Closed daniel-milchev closed 10 months ago

daniel-milchev commented 1 year ago

It would be convenient to be able to remove all containers at once. For example add:

kanto-cm remove -all

The point is that when you have to remove many containers one by one it can easily get tedious.

k-gostev commented 1 year ago

Removing all containers at once in random order is a bit harsh and could lead to multiple issue and can potentially have more downsides that benefits. What could be quickly implemented and be convenient is to remove all containers with the same name. WDYT @dimitar-dimitrow

dimitar-dimitrow commented 1 year ago

I think that it is save to remove all non running containers using an all flag. If the user insist on removing all containers(with running status as well) then the force flag should also be specified. The force flag would make the harshness of the operation visible to the user.

If the use case is to remove all containers with the same name, we should specify some new filter flag as all implies that the operation would be executed against every container. Using both name and all flags to remove all containers with some name, does not seem intuitive to me.

k-gostev commented 1 year ago

I know this will be used usually with test scenarios, but still my main concern is that our current implementation of remove does not send SIGKILL immediately, which can make the process to hang a lot. Also, the combination of --all --name can lead to misunderstanding and someone may think that all containers with the given container name will be deleted.

So to summarise:

kanto-cm remove --all will remove all not running containers, so not all at all kanto-cm remove --all --force will remove everything, no SIGKILL and very slow process kanto-cm remove --all --name ?

dimitar-dimitrow commented 1 year ago

A time flag could be added to mitigate the slow sending of SIGKILL. The combination of --all --name should be forbidden and a descriptive error must be returned. The description of the all flag must describe that it can only be used in conjunction with force and time flags.

kanto-cm remove --all will remove all non running containers. It is fine to leave the running ones as the default execution of remove with a single running container does not remove it as well. kanto-cm remove --all --force will remove everything, SIGKILL will be send after a default amount of time kanto-cm remove --all --force --time will remove everything, SIGKILL will be send after the provided time

k-gostev commented 1 year ago

It is unnecessarily complicated IMO. If we are going with this lets just use only kanto-cm remove --all send a warning back + confirmation request and then purge all with immediate SIGKILL.

daniel-milchev commented 1 year ago

I looked into what options similar services provide, such as Podman, Docker and Kubernetes.

# Remove all containers regardless of the run state
podman rm -f -a
k-gostev commented 1 year ago

In a joint sync between me, @daniel-milchev and @dimitar-dimitrow we decided to do the following:

Tasks:

After that the remove and list commands would be able to be combined in a single command like:

kanto-cm remove $(kanto-cm list --filter status=stopped -q)