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

EVEREST-1811 | dynamically configure watches for controllers #630

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mayankshah1607
Copy link
Member

@mayankshah1607 mayankshah1607 commented Jan 8, 2025

CHANGE DESCRIPTION

Problem:
EVEREST-1811

Everest operator sometimes does not restart when new DBEngines and CRDs are installed. Due to this, the newly added APIs are not registered to scheme, the watches not configured, and the operator is indefinitely stuck in an error state.

Cause:

With the addition of Helm installation, we made it possible to install the core components and DBNamespaces separately. One issue this brought was that the Everest operator now needed to restart so that the newly added CRDs are registered to the client scheme, and the watchers can be configured during bootstrap. So we added some mechanism to detect if a new DBEngine is installed, and restart the pod.

But this mechanism fails sometimes if there are delays in the CRD creation, which can lead to a race condition. For example, if some CRDs are created late, the operator will restart regardless, and can fail to observe those CRDs. As a result, the watchers are only partially configured. Moreover, the restart logic checks only the GroupVersion in the scheme and assumes that all Kinds are registered.

Solution:

This PR removes the need to restart the Everest operator by dynamically registering watchers based on the installed DBEngines:

  • We register the PXC, PSMDB and PG schemes to the controller during boot up, regardless of whether its DBEngine is installed or not. This is done to simplify code since it poses no harm.
  • We use the underlying Controller interface exposed by controller-runtime to add watchers (to other controllers) during DBEngine reconciliation
  • Each of the controllers (db, dbb, dbr) expose a ReconcileWatchers function that updates its watchers based on the DBEngines. This ReconcileWatchers is called during the DBEngine reconciliation

With such a mechanism, the various watchers are constantly being reconciled by the DBEngine controller. Such an approach requires no restart since the watchers are configured dynamically during runtime, and also makes no assumptions based on the scheme's registered groups (rather it ensures that the correct watchers are configured)

tl;dr - DBEngines reconciler reconciles the watchers on other reconcilers

CHECKLIST

Helm chart

  • Is the helm chart updated with the new changes? (if applicable)

Jira

  • Is the Jira ticket created and referenced properly?

Tests

  • Is an Integration test/test case added for the new feature/change?
  • Are unit tests added where appropriate?

@mayankshah1607 mayankshah1607 added the test/e2e Run full E2E test suite label Jan 8, 2025
Signed-off-by: Mayank Shah <[email protected]>
Signed-off-by: Mayank Shah <[email protected]>
@mayankshah1607 mayankshah1607 changed the title EVEREST-1811 EVEREST-1811 | add the ability to dynamically configure watches for controllers Jan 8, 2025
@mayankshah1607 mayankshah1607 changed the title EVEREST-1811 | add the ability to dynamically configure watches for controllers EVEREST-1811 | dynamically configure watches for controllers Jan 8, 2025
Signed-off-by: Mayank Shah <[email protected]>
@mayankshah1607 mayankshah1607 marked this pull request as ready for review January 9, 2025 08:46
Comment on lines +104 to +107

utilruntime.Must(pgv2.SchemeBuilder.AddToScheme(scheme))
utilruntime.Must(psmdbv1.SchemeBuilder.AddToScheme(scheme))
utilruntime.Must(pxcv1.SchemeBuilder.AddToScheme(scheme))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will it work if initially any of the operators have not been installed?

Copy link
Member Author

@mayankshah1607 mayankshah1607 Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the scheme only holds a mapping between the APIs/GVK and the Go structs to facilitate encoding/decoding responses from the Kube API server. It does not talk to Kubernetes

Copy link
Collaborator

@recharte recharte left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so much more elegant than killing the pod 🙈 congratulations 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test/e2e Run full E2E test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants