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

Wait for the Namespace and Account informers to sync before controller startup #154

Merged
merged 1 commit into from
Aug 1, 2024

Conversation

a-hilaly
Copy link
Member

@a-hilaly a-hilaly commented Aug 1, 2024

Add a new functionality to help waiting for the Namespace and Account cache
informers to sync before proceeding with the creation of the reconcilers.

Key changes:

  • Publish informer.HasSynced to the top level structs for namespace and
    accout caches
  • Use these informer.HasSynced to wait for the caches to sync using
    "k8s.io/client-go/tools/cache".
  • We call the wait mechanism right after the function that spins the informers
    a.k.a caches.Run.

Last to note, we are using a context.TODO() context, as a temporary workaround
until we figure out a better mechanism for context cancellation.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-prow ack-prow bot requested a review from jlbutler August 1, 2024 02:09
@ack-prow ack-prow bot added the approved label Aug 1, 2024
@michaelhtm
Copy link
Member

/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2024
@a-hilaly a-hilaly changed the title Add functionality to wait for the Namespace and Account cache Wait for the Namespace and Account informers to sync before controller startup Aug 1, 2024
@a-hilaly
Copy link
Member Author

a-hilaly commented Aug 1, 2024

/retest

@@ -233,6 +234,10 @@ func (c *serviceController) BindControllerManager(mgr ctrlrt.Manager, cfg ackcfg
// Run the caches. This will not block as the caches are run in
// separate goroutines.
cache.Run(clientSet)
// Wait for the caches to sync
ctx := context.TODO()
Copy link
Member

Choose a reason for hiding this comment

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

can we do 1 minute for this instead

Copy link
Member Author

Choose a reason for hiding this comment

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

I think indeed this will solve the failing unit tests, but imposes risk of race condition

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe we can configure that specific failing unit test to not use CARM caches? it is only supposed to tests that the controller build happen correctly

Copy link
Member Author

Choose a reason for hiding this comment

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

what's happening here is that: the unit tests attempt to initialize a cache, but WaitForCachesToSync requires communication with the api server, which is not running during unit tests. so... the function waits indefinitely an eventually leads to timeouts..

informers to sync before proceeding with the creation of the reconcilers.

Key changes:
- Publish `informer.HasSynced` to the top level structs for namespace and
  accout caches
- Use these `informer.HasSynced` to wait for the caches to sync using
  `"k8s.io/client-go/tools/cache"`.
- We call the wait mechanism right after the function that spins the informers
  a.k.a `caches.Run`.

Last to note, we are using a `context.TODO()` context, as a temporary workaround
until we figure out a better mechanism for context cancellation.
@ack-prow ack-prow bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2024
@michaelhtm
Copy link
Member

/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2024
Copy link

ack-prow bot commented Aug 1, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: a-hilaly, michaelhtm

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ack-prow ack-prow bot merged commit dda2022 into aws-controllers-k8s:main Aug 1, 2024
4 of 5 checks passed
ack-prow bot pushed a commit to aws-controllers-k8s/iam-controller that referenced this pull request Aug 1, 2024
Mainly bringing the new bug fixes from runtime to the iam controller:
- aws-controllers-k8s/runtime#154
- aws-controllers-k8s/runtime#153

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants