-
Notifications
You must be signed in to change notification settings - Fork 318
multiproject: centralize informers; harden manager; add docs #2972
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
Conversation
69aec65 to
438d992
Compare
72a34fc to
2eb739c
Compare
2eb739c to
3f6e8d2
Compare
3f6e8d2 to
291e886
Compare
pkg/multiproject/manager/manager.go
Outdated
| pcLatest, err := pccm.providerConfigClient.CloudV1().ProviderConfigs().Get(context.Background(), pc.Name, metav1.GetOptions{}) | ||
| if err != nil { | ||
| pcCopy := pc.DeepCopy() | ||
| pcCopy.Finalizers = append(pcCopy.Finalizers, finalizer.ProviderConfigNEGCleanupFinalizer) |
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.
We should optionally add this finalizer if it doesn't exist.
Is this to cover the case our cache hasn't updated to after us putting it on ?
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.
Maybe this is a bit overengineering, but this function is only used to get PC on deletion
Idea is -- if by some case "get" failed (idk, some transient error), we don't want to leave PC hanging and still want to try to remove finalizer, so that's the logic besides this function
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 think we should instead throw an error in this situation. Is there a reason we don't think the version in the cache is not up to date?
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.
Yeah, I agree actually, removed this, inlined getting providerconfig
Replace factory-based informer creation with centralized InformerSet that: - Creates base SharedIndexInformers directly without factories - Manages lifecycle and synchronization in one place - Provides filtered views for ProviderConfig-specific controllers - Reduces boilerplate and improves maintainability Using informers directly without factories simplifies the logic and eliminates potential mistakes from unnecessary factory usage, such as cidentally creating duplicate informers or incorrect factory scoping.
- Add manager_test.go covering: - Start adds NEG cleanup finalizer and is idempotent - Start failure and GCE client creation failure roll back finalizer - Stop closes controller channel and removes finalizer - Concurrent starts for same ProviderConfig are single-shot - Improve manager.go: - Introduce test seam via package var startNEGController - Ensure finalizer is added before start; roll back on any startup error - Delete finalizer using latest ProviderConfig from API to avoid stale updates - Wrap errors with %w and add GoDoc comments - Rename exported ControllerSet to unexported controllerSet - No expected behavior change in the happy path; robustness and testability improved.
291e886 to
ea200f4
Compare
- Fix bug: preserve pre-existing finalizer on startup failure - Expand informerset tests to verify multiple informers sync - Add tests for controller restart with existing finalizer - Add comment explaining closeProvider bool in neg_test
ea200f4 to
ce5c037
Compare
|
Ready for re-review @swetharepakula |
pkg/multiproject/manager/manager.go
Outdated
| pcLatest, err := pccm.providerConfigClient.CloudV1().ProviderConfigs().Get(context.Background(), pc.Name, metav1.GetOptions{}) | ||
| if err != nil { | ||
| pcCopy := pc.DeepCopy() | ||
| pcCopy.Finalizers = append(pcCopy.Finalizers, finalizer.ProviderConfigNEGCleanupFinalizer) |
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 think we should instead throw an error in this situation. Is there a reason we don't think the version in the cache is not up to date?
pkg/multiproject/manager/manager.go
Outdated
| // happens in that window, cleanup could be skipped. We roll this back on | ||
| // any subsequent startup error. | ||
| // any subsequent startup error only if we added it. | ||
| err := finalizer.EnsureProviderConfigNEGCleanupFinalizer(pc, pccm.providerConfigClient, logger) |
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.
move this to right before we start the controller, so we ensure all clients are up. This way we don't have to remove because GCE client didn't initialize.
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.
Done
- Create GCE client before adding finalizer (no rollback needed on fail) - Return errors from StopControllersForProviderConfig for requeue - Remove silent fallback in latestPCWithCleanupFinalizer
|
Ready for re-review @swetharepakula |
swetharepakula
left a comment
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.
One more nit and this PR lgtm. Thanks!
swetharepakula
left a comment
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.
/lgtm
/approve
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: panslava, swetharepakula The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/assign @swetharepakula