lwolf / kube-cleanup-operator

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

Add support for annotation-based customizations #72

Open lwolf opened 3 years ago

lwolf commented 3 years ago

There is a use case when jobs/pods need to be "cleaned up" after a different timeout. It should be possible to support it by considering annotations on pods/jobs before making a "clean up" decision.

https://github.com/lwolf/kube-cleanup-operator/pull/71#issuecomment-804241375

RocketRaccoon commented 3 years ago

The main idea behind using labels is an option to use LabelSelector on ListFunc and WatchFunc. So it looks like that implementing labelSelector does not contradicts with annotation-based logic in general, but the same logic could be implemented with FieldSelector on annotations. Any way, solution with annotations could be done in this way:

  1. Support configuration option like --respect-annotations with false by default for compatibility
  2. Add at least main annotation which disables cleanup on exact job/pod kube-cleanup-operator.lwolf.github.com/disabled to disable cleanup for the specific class of pods/jobs for debugging purposes.
  3. Support configurable options for jobs/pods delete-successful-after, delete-failed-after
  4. Support pods only configuration delete-orphaned-after, delete-evicted-after, delete-pending-after
lwolf commented 3 years ago

I agree that labelSelector doesn't contradict annotation-based logic. Merged the PR.

Your plan for the annotations looks great. The only thing I'd change is the prefix for the annotations: kleaner.lwolf.org instead of kube-cleanup-operator.lwolf.github.com/.