Skip to content

WIP: Fix several issues in realtime-compositions#5422

Closed
sttts wants to merge 4 commits intocrossplane:masterfrom
sttts:sttts-realtime-compositions-xrrev-race
Closed

WIP: Fix several issues in realtime-compositions#5422
sttts wants to merge 4 commits intocrossplane:masterfrom
sttts:sttts-realtime-compositions-xrrev-race

Conversation

@sttts
Copy link
Copy Markdown
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 a team and negz 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
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

// 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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

clarified

}
i.xrCaches[gvk] = ca

// asynchronously mark the cache as synced. We won't list XRs before this
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
sttts added 3 commits March 5, 2024 21:30
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 😉

@haarchri
Copy link
Copy Markdown
Member

this part #5400 is still open - which gets fixed here - so i wonder if we can cherry pick this

@jbw976
Copy link
Copy Markdown
Member

jbw976 commented Dec 19, 2024

Thanks for the reminder on this PR and that you're still seeing issues with realtime compositions even after the big changes in #5651 @haarchri!

I'll make sure to peruse through the changes in this PR and work with @sttts and @negz to see if they can be ported to the state of the world after #5651. This PR can't be re-opened since GitHub says the master branch has been deleted, but I've added it to the beta tracking epic as a reminder to look more deeply soon 🙇‍♂️

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

4 participants