lwolf / kube-cleanup-operator

Kubernetes Operator to automatically delete completed Jobs and their Pods
MIT License
498 stars 109 forks source link

Add Label Selector to available parameters #71

Closed RocketRaccoon closed 3 years ago

RocketRaccoon commented 3 years ago

It can be useful to manage jobs/pods in the same namespace by different rules. It is easy to achieve by running several kube-cleanup-operator instances with different label selectors. This PR supports such ability.
I didn't add any tests because it is functionality of underlying library, but have tested manually with empty value and something like --label-selector=component=worker,housekeeping=true

lwolf commented 3 years ago

Hi, is there a specific use case that you're trying to solve here? Could you tell me more abou it please?

RocketRaccoon commented 3 years ago

I have "infra" namespace which manages lot of different jobs e.g. ones run small scripts and other execute long-running terraform tasks. I need to manage their cleanup in different ways, small one should be cleaned up in 5 minutes and long tasks should keep their log for 24 hours. I want to have some kind of ownership for different flows.

lwolf commented 3 years ago

I see, thanks for the info. Originally I planned to support this use case by introducing job/pod annotations. Let me think about it.

RocketRaccoon commented 3 years ago

Annotations probably work better here, labels were just easy and fast option for me. I can rework it if you need.

lwolf commented 3 years ago

If you're interested in implementing it - that's awesome.

Before the rework, we need to come up with a list of annotations to use and the workflow that won't break anything. I'm a bit oversubscribed at the moment, but I'll try to come up with some ideas for the annotations over weekend. If you have any - please post to the ticket that I just created - https://github.com/lwolf/kube-cleanup-operator/issues/72

Let's leave the PR open for now, we might decide along the way that it not worth it and go with the labels instead.

lwolf commented 3 years ago

I think it doesn't contradict annotation-based customizations. Merging. Thank you!