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

controller/engine: add queueing index method to NamedController #672

Closed

Conversation

sttts
Copy link
Contributor

@sttts sttts commented Feb 22, 2024

Description of your changes

Using GetCache()'s IndexField method will use the passed context for the life-cycle of informers started at that moment. This is usually not what is desired, but the life-cycle of the cache should match the life-cycle of the controller, and this applies to all informers of course.

This PR adds a IndexField method to queue up index creation until the controller has been started.

Note that the GetCache() method is still useful to e.g. wire it up into other components that want to read from the cache later.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Tested in Crossplane fixing realtime composition issues.

Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@upbound.io>
GetCache() cache.Cache
IndexField(obj client.Object, field string, extractValue client.IndexerFunc)
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a doc string for this method, since the others all have them.

@@ -281,7 +305,18 @@ func (c *namedController) Start(ctx context.Context) error {
return nil
}

// IndexField queues an index for addition to the cache on start.
Copy link
Member

Choose a reason for hiding this comment

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

Would QueueIndexField or IndexFieldOnStart or something similar make this more self-descriptive?

What happens if this is called after the controller/cache is started? Nothing I guess? (Worth mentioning in doc string.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good points.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, standby with this PR. The context passed to GetInformer and with that to IndexField is only used for waiting, not for the informer life-cycle. I think this was a misunderstanding.

indexes []index
}

type index struct {
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to export this type and have Start take a variadic array of it? I'm not sure how this is called, so I'm happy if it's more ergonomic to use the method approach instead.

e.g.:

c.Start(ctx,
    Index{Object: o, Field: "spec.hi", ExtractValue: ifn},
    Index{Object: o, Field: "spec.hello", ExtractValue: ifn2})

@sttts sttts force-pushed the sttts-controller-engine-indexes branch from ffc8dce to c4f6831 Compare February 23, 2024 08:49
Signed-off-by: Dr. Stefan Schimanski <stefan.schimanski@upbound.io>
@sttts sttts force-pushed the sttts-controller-engine-indexes branch from c4f6831 to 956937e Compare February 23, 2024 08:52
@negz
Copy link
Member

negz commented May 20, 2024

#689 moved the engine implementation to c/c. The implementation is being reworked there so this PR may no longer be relevant but either way it won't happen in this repo. 🙂

@negz negz closed this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants