-
Notifications
You must be signed in to change notification settings - Fork 53
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
Rule refactor #45
base: master
Are you sure you want to change the base?
Rule refactor #45
Conversation
Notes from #46
It isn't possible to know annotations of pods because they are dynamic vs the immutable setup of the pod-reaper, but the configuration of the pod-reaper itself should be able to "fail fast" and "fail safe" -- If something isn't configured correctly, I generally like to know as soon as possible. |
Functionally, I'm feeling pretty dang good about this right now. @jdharmon |
Removed WIP: I think this is good to go. From all testing that I have done, there is nothing breaking compatibility for any rule or reaper configurations. The structure of logging has however changed, so it someone is dependent on that, then that could be considered a "breaking change". The more eyes on this the better! Would love feedback (good or bad) -- golang is certainly not my strongest programming language and I'm picking up new go-isms each time I work on this. |
I would expect to see the following events at the debug level:
I can see how a bunch of spare decisions from rules I don't care about would be annoying. That brings up a question: Should all rules be enabled? Maybe there should be an environment variable to specify which rules to enable. i.e. |
This is the big question here, and it's basically at the heart of #44 I think by default, all rules should be there (this would keep backwards compatibility). In my head, that lead me to a simple question: "how would I log which rules are enabled". At first it seemed really simple. With your solution, even with default, just log the rules that are "enabled". But what if those are enabled, but have no configured value? Should that error? If so, there's a backwards compatibility problem. If not, what should it log? "enabled with configuration unset" or something like that. That the question doesn't have an extremely simple answer is making me question the design of this rework. |
I think for backwards compatibility, it's OK to enable all rules by default. If a rule is not configured, or there are no decorated pods, then it does nothing. If
That depends...for this issue, an error would be fine. However, for #44, all rules would need to be able to be enabled without a default configuration. For the latter, I think logging a warning is reasonable. It's not necessarily an error, but it might be. Something like
|
At this point, I'm feeling pretty good about this PR. |
Related to #44
This pull-request fundamentally changes the way that rules are loaded and evaluated with the expressed intent of making #44 easier to implement.
Previously, a rule was a structure the implemented two methods: a
load
method and ashouldReap
method. Rules that were configured (environment variables controlling their behavior) were set, were stored into a list of rules for evaluation. Only if ALL rules returnedtrue
from theshouldReap
method on a specific pod would the pod be reaped.While this worked extremely well, it makes a couple of assumptions. The biggest is that ALL of the configuration related to what will get reaped exists within the environment variables of the pod-reaper itself. As soon as there's anything dynamic (like say from a pod-annotation), then there's the possibility of rules being configured elsewhere that aren't configured within the reaper itself and vice-versa.
In short, it worked well -- but wasn't very flexible to this kind of extension.
Here's a list of changes:
type rule func(v1.Pod) (result, string)
meaning that they are just functions with the proper parameters and return types.Functionally -- the behavior of the reaper should be identical to previous versions. While when and how rules are evaluated has changed, neither the configuration (environment variables) nor the test reaping behavior has been altered in this change.
A version of the reaper built with this change can be found here:
brianberzins/pod-reaper:alpha-02212020
As always, I tread on the paranoid side when working on pod-reaper to help quintuple check that there won't be any accidental annihilation of clusters.