-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor reconciler #4
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do appreciate the sentiment with unifying the ReconcilerErrorWithStatus
but there's much more going on here than that. I'm not quite ready to bump the reconciler around this way and i'm not sure changing this horse now is a good idea.
custom_events: Optional[list[BoundEvent]] = None, | ||
exit_status: StatusBase = BlockedStatus("Reconcile failed"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um, let's not swap the order here... also use List
b/c py38 is special
custom_events: Optional[list[BoundEvent]] = None, | |
exit_status: StatusBase = BlockedStatus("Reconcile failed"), | |
exit_status: StatusBase = BlockedStatus("Reconcile failed"), | |
custom_events: Optional[List[BoundEvent]] = None, |
): | ||
super().__init__(charm, "reconciler") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Um? i don't think ops will let you do this.
self.charm = charm | ||
self.reconcile_function = reconcile_function | ||
self.stored.set_default(reconciled=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, i'm not ready to eliminate this state. We don't want to reconcile on EVERY hook. Update-status hook could run every second. We'd melt things into the ground constantly reconciling an already reconciled unit. There's no value with this
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class Reconciler(Object): | ||
stored = StoredState() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please, can we leave this?
def reconcile(self, event): | ||
if isinstance(event, UpdateStatusEvent) and self.stored.reconciled: | ||
def reconcile(self: "Reconciler", event: EventBase) -> None: | ||
try: | ||
self.reconcile_function(event) | ||
except ReconcileErrorWithStatus as e: | ||
log.exception(f"reconcile failed: {e}") | ||
self.charm.unit.status = e.status | ||
return | ||
|
||
self.stored.reconciled = False | ||
|
||
with status.context(self.charm.unit, self.exit_status): | ||
try: | ||
self.reconcile_function(event) | ||
self.stored.reconciled = True | ||
except status.ReconcilerError: | ||
log.exception("Caught ReconcilerError") | ||
self.charm.unit.status = self.exit_status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, i don't understand what's going on here. How are we getting away with not using the status.context
anymore?
something isn't right here anymore and i'm not sure i see the imrpovement
Proposal
This PR simplifies this module and provides an interface that more closely resembles the Kubernetes controller semantics.