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

Find Empty namespaces #92

Open
yonahd opened this issue Sep 27, 2023 · 13 comments
Open

Find Empty namespaces #92

yonahd opened this issue Sep 27, 2023 · 13 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@yonahd
Copy link
Owner

yonahd commented Sep 27, 2023

Find namespaces with no resources

@yonahd yonahd added enhancement New feature or request good first issue Good for newcomers labels Sep 27, 2023
@liornoy
Copy link

liornoy commented Oct 12, 2023

hey @yonahd I would like to work on that, please.
Is it fair to say that we call a namespace empty if there are not resources in there at all? is that correct?

@yonahd
Copy link
Owner Author

yonahd commented Oct 12, 2023

Yes. It should be with no resources except for the default service account

@liornoy
Copy link

liornoy commented Oct 12, 2023

Thanks, I already started working on this, and on my Kind cluster there is an auto-generated "kube-root-ca.crt' configmap that we might also want to add as an exception. wdyt?

@liornoy
Copy link

liornoy commented Oct 12, 2023

I see we even have a exceptionconfigmaps var for it

@yonahd
Copy link
Owner Author

yonahd commented Oct 12, 2023

Thanks, I already started working on this, and on my Kind cluster there is an auto-generated "kube-root-ca.crt' configmap that we might also want to add as an exception. wdyt?

Yes. This is default as well

@roopeshsn
Copy link

Hi @yonahd, I'd like to address this issue. Are the default resources, such as the service account and kube-root-ca.crt configmap, consistent across Kubernetes distributions? If so, can we determine whether a namespace is unused by checking for the presence of these default resources, and concluding that it is unused if there are no additional resources in that namespace?

@yonahd
Copy link
Owner Author

yonahd commented Dec 16, 2023

Hi @yonahd, I'd like to address this issue. Are the default resources, such as the service account and kube-root-ca.crt configmap, consistent across Kubernetes distributions? If so, can we determine whether a namespace is unused by checking for the presence of these default resources, and concluding that it is unused if there are no additional resources in that namespace?

This is consistent. We want to take an approach similar to https://github.com/corneliusweig/ketall/tree/master

@roopeshsn
Copy link

roopeshsn commented Dec 19, 2023

I took time to view the implementation of Ketall. It constructs a slice of resource names with the API resources ([configmaps endpoints pods ...]). It creates a new resource builder from the kubernetes/cli-runtime package, passes the slice, and calls the methods Do().Object() which prints the resources from all the namespaces or from a specific namespace when the --namespace=<namespace> flag is passed.

Do you want me to see the logic of Do().Object() @yonahd?

@roopeshsn
Copy link

The thing I am confused about is that though we find all the resource types, create a builder from cli-runtime, and pass the resource types it will return an object with all the namespaced and default resources in a namespace. How it will be useful to find an unused namespace?

@yonahd
Copy link
Owner Author

yonahd commented Dec 26, 2023

@roopeshsn We don't find all resources.
We don't even interact with all of them.
The user can know which namespace he can consider empty(and avoid thinking its used by the default resources) and delete it. Not sure I completely understand the question

@roopeshsn
Copy link

roopeshsn commented Dec 28, 2023

@roopeshsn We don't find all resources. We don't even interact with all of them. The user can know which namespace he can consider empty(and avoid thinking its used by the default resources) and delete it. Not sure I completely understand the question

Exactly! Ketall finds the namespace resources using the cli-runtime package. How does that implementation help to find an unused namespace? However, we need to check and conclude a namespace is empty if it contains only default resources.
@yonahd

@isindir
Copy link
Contributor

isindir commented Apr 28, 2024

The above PR is still WIP - lacks parallel namespace processing and unit tests

@isindir
Copy link
Contributor

isindir commented Dec 2, 2024

Added some unit tests and recently rabased once more, @yonahd would it be possible for you to review and either accept or refuse this PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants