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

WIP: Fix several issues in realtime-compositions #5422

Closed

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Feb 22, 2024

Description of your changes

In collaboration with @haarchri, fixing a number of issues in realtime-compositions. In particular, ensure the right life-cycle of watches and informers to match that of the composite controller:

Depends on crossplane/crossplane-runtime#672.

Fixes #5400

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • [ ] Added or updated unit tests.
  • Added or updated e2e tests.
  • [ ] Linked a PR or a docs tracking issue to document this change.
  • [ ] Added backport release-x.y labels to auto-backport this PR.

Need help with this checklist? See the cheat sheet.

@sttts sttts requested review from negz and a team as code owners February 22, 2024 16:48
@sttts sttts requested a review from phisco February 22, 2024 16:48
@sttts sttts force-pushed the sttts-realtime-compositions-xrrev-race branch from 5e40e58 to fddd833 Compare February 22, 2024 16:50
@@ -712,6 +712,7 @@ func EnqueueForCompositionRevisionFunc(of resource.CompositeKind, list func(ctx
log.Info("cannot list in CompositionRevision handler", "type", schema.GroupVersionKind(of).String(), "error", err)
return
}
log.Debug("Enqueueing composite resources because a new CompositionRevision was created", "count", len(xrs.Items))
Copy link
Member

Choose a reason for hiding this comment

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

It might be useful to include the GVK of the XRs that will be enqueued, like the log line above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -63,12 +70,16 @@ type composedResourceInformers struct {
// composites referencing a certain composed resource GVK. If no composite
// is left doing so, a composed resource informer is stopped.
xrCaches map[schema.GroupVersionKind]cache.Cache
sinks map[string]func(ev runtimeevent.UpdateEvent) // by some uid
// xrCachesSynced holds the composite resource informers that are synced. We
// don't
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this trails off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

i.lock.Lock()
defer i.lock.Unlock()
if _, ok := i.xrCaches[gvk]; ok {
i.log.Debug("Composite resource cache seen synced", "gvk", gvk.String(), "after", time.Since(startAt))
Copy link
Member

Choose a reason for hiding this comment

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

Nit: In the informers above the GVK uses type rather than gvk. Being consistent would help anyone processing these structured logs who wanted to filter on GVK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have switched to gvk.

@@ -105,15 +116,34 @@ func (i *composedResourceInformers) Start(ctx context.Context, h handler.EventHa

// RegisterComposite registers a composite resource cache with its GVK.
// Instances of this GVK will be considered to keep composed resource informers
// alive.
// alive. The cache does not have to be synced yet.
Copy link
Member

Choose a reason for hiding this comment

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

Is this saying that it's safe to call this method before the cache is synced? It reads a little ambiguously to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clarified

if i.xrCaches == nil {
i.xrCaches = make(map[schema.GroupVersionKind]cache.Cache)
}
i.xrCaches[gvk] = ca

// asynchronously mark the cache as synced. We won't list XRs before this
Copy link
Member

Choose a reason for hiding this comment

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

Style nit: The prevailing pattern is for comments to use proper grammar, i.e. start with a capital letter, unless the first word is the name of an unexported type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 481 to 486
controller.TriggeredBy(&lazySyncingSource{Create: func() source.SyncingSource {
return source.Kind(xrCache, &v1.CompositionRevision{})
}}, handler.Funcs{
CreateFunc: composite.EnqueueForCompositionRevisionFunc(ck, func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error {
return xrCache.List(ctx, list, opts...)
}, r.log),
Copy link
Member

Choose a reason for hiding this comment

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

Style nit: This is a bit of a handful to read due to the nested function definitions with long signatures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have made it similar to the other source. A little bit easier to read. The closured for delaying evaluation are little ugly. But Go doesn't allow a better syntax. Wished there was a foo(bla, lazy xrCache, ...).

@sttts sttts force-pushed the sttts-realtime-compositions-xrrev-race branch 2 times, most recently from 82136ca to 199edad Compare February 23, 2024 09:15
@sttts sttts changed the title Fix several issues in realtime-compositions WIP: Fix several issues in realtime-compositions Feb 23, 2024
@sttts sttts marked this pull request as draft February 23, 2024 09:37
@sttts sttts force-pushed the sttts-realtime-compositions-xrrev-race branch 4 times, most recently from 26a1b40 to d8b23b9 Compare February 28, 2024 12:46
@sttts sttts force-pushed the sttts-realtime-compositions-xrrev-race branch from d8b23b9 to 2aa0c76 Compare March 1, 2024 07:52
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@upbound.io>
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@upbound.io>
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@upbound.io>
@sttts sttts force-pushed the sttts-realtime-compositions-xrrev-race branch from 2aa0c76 to 6cf5e57 Compare March 5, 2024 20:30
This reverts commit 53b143f.

Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@upbound.io>
@jbw976
Copy link
Member

jbw976 commented Mar 11, 2024

Looks like confidence in this approach is growing as per #5400 (comment). I've added the backport labels for v1.14 and v1.15 so once this is merged we can likely get patch releases out with this fix 💪

@sttts
Copy link
Contributor Author

sttts commented Mar 11, 2024

@jbw976 this PR is not ready yet. It includes a couple of improvement all in one PR, not all ready. #5437 merged into master already. That one should be backported.

@jbw976
Copy link
Member

jbw976 commented Apr 23, 2024

ah and this one may be the most impactful of the bunch @sttts if you're able to make progress on this for v1.16. Sorry for the multiple notifications, just going through all the open PRs now that could be impactful for v1.16 😉

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

Successfully merging this pull request may close these issues.

Crossplane fails to synchronize claims with XRs
3 participants