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

Default error_policy could be defined in Controller builder #297

Open
clux opened this issue Jul 30, 2020 · 5 comments · May be fixed by #314
Open

Default error_policy could be defined in Controller builder #297

clux opened this issue Jul 30, 2020 · 5 comments · May be fixed by #314
Labels
api Api abstraction related question Direction unclear; possibly a bug, possibly could be improved. runtime controller runtime related

Comments

@clux
Copy link
Member

clux commented Jul 30, 2020

As it stands the error_policy fn for Controller is not async, so it's actually hard to do anything useful inside of them short of changing/retrieving state (and even that can be hard if it's locked), so can only see it being useful to return an instance of the enum, possibly keeping track of backoff numbers in Context.

I think we could have two builder variants here:

  • Controller::new(...).error_policy(myReconcileAction) (flat retry / backoff retry ideally configurable)
  • Controller::new(...).error_handler(my_async_error_handler)

The first one provides an easy way to replace, and the builder can guarantee we only use one. (It can in fact turn it into the second).

The second is then used, but might require some rejigging of how the function is called within the applier.

@clux clux added question Direction unclear; possibly a bug, possibly could be improved. runtime controller runtime related labels Jul 30, 2020
@nightkr
Copy link
Member

nightkr commented Jul 30, 2020

I've been looking at implementing an error_policy on top of backoff. It mostly seems to work, just need to get around to hooking it all together.

@nightkr nightkr added the api Api abstraction related label Jul 30, 2020
@nightkr nightkr linked a pull request Aug 30, 2020 that will close this issue
@clux clux added this to Kube Roadmap Nov 3, 2021
@clux clux moved this to Defining in Kube Roadmap Nov 3, 2021
@pando85
Copy link

pando85 commented Nov 22, 2024

I just hit this situation where a backoff policy per object would be great in case of a reconciliation error.

What would be the steps to move this forward after all the changes have been made to kube-rs since this issue was created?

@clux
Copy link
Member Author

clux commented Nov 22, 2024

We didn't really get too far with this, unfortunately. It's perhaps a little overkill to have by default - I've generally used fixed 300s requeues for failures and that's usually OK. We also gotta replace the backoff library first #1635

That said, a pattern I've seen used is to make the reconciler (which is async) be a fn that wraps an inner_reconciler (which does the regular reconciliation and returns a regular error). Then the outer fn can call the inner reconciler, keep track of those errors, and return appropriate Action::requeue durations there, kind of bypassing the need for an error_policy.

If you want you could do a per-gvk/per-object hashmap there and create backoffs - possibly storing it on the controller context.

@pando85
Copy link

pando85 commented Nov 23, 2024

@clux , thanks for your comment. It really clarifies to me how to proceed with this.

In that case I don't know if make sense just to close this as we have to handle this outside the project because not all people need it and the controller is flexible enough for this implementation.

Also, good point about the backon crate. I will take a look.

@pando85
Copy link

pando85 commented Nov 24, 2024

If someone needs to implement something similar, I finally follow @clux advice.

I created a wrapper function for reconciler.

And implemented a backoff per object.

For a more detailed explanation, all the changes can be found in this commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Api abstraction related question Direction unclear; possibly a bug, possibly could be improved. runtime controller runtime related
Projects
Status: Defining
Development

Successfully merging a pull request may close this issue.

3 participants