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

Refactor reconciler #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

HomayoonAlimohammadi
Copy link

@HomayoonAlimohammadi HomayoonAlimohammadi commented Jan 24, 2025

Proposal

This PR simplifies this module and provides an interface that more closely resembles the Kubernetes controller semantics.

Copy link
Member

@addyess addyess left a 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.

Comment on lines +29 to +30
custom_events: Optional[list[BoundEvent]] = None,
exit_status: StatusBase = BlockedStatus("Reconcile failed"),
Copy link
Member

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

Suggested change
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")
Copy link
Member

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)
Copy link
Member

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()
Copy link
Member

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?

Comment on lines -37 to +55
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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants