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

✨ make APIExportEndpointSlice consumer aware #3256

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mjudeikis
Copy link
Contributor

@mjudeikis mjudeikis commented Jan 18, 2025

Summary

This part makes APIExportEndpointSlices consumers aware. Meaning it will add or remove URLs if consumers are present or goes away.

In this PR:

  1. Current APIExportEndpointSlice reconcile is split into 2 - status and url

status - status controller checks if API export is valid, partitions are set right, and it can be queried. Most of these objects operate in a single-shard context, so this reconciliation works only in a single-shard context. CAVITE: Based on the partition setup - the shards involved will be different. Hence we store the final computed selector into status for the URL reconciler to pick up.

url - URL reconcile operates cross-shards setup. It takes APIExportEndpointSlice from the cache and local shard and observes APIBindings and APIExports and, based on consumers, will update URLs.

In addition, it uses not a commuter but Server-Side Apply patch to update only its own field, which is owned by shard.

If we want to remove the selector from status - it would require an overload single reconciliation quite a lot. And filter when we can update statuses and when not. Overall, I tried, and the code readability was very poor.

Related issue(s)

Fixes # #3221

Release Notes

make APIExportEndpointSlices consumer aware

@kcp-ci-bot kcp-ci-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: yes Indicates the PR's author has signed the DCO. labels Jan 18, 2025
@kcp-ci-bot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@kcp-ci-bot kcp-ci-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jan 18, 2025
@mjudeikis mjudeikis marked this pull request as ready for review January 18, 2025 20:57
@kcp-ci-bot kcp-ci-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 18, 2025
@mjudeikis mjudeikis force-pushed the mjudeikis/apiexport.ep branch from 4bd9adf to f1b4a98 Compare January 19, 2025 20:54
@kcp-ci-bot kcp-ci-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jan 19, 2025
@mjudeikis mjudeikis marked this pull request as draft January 19, 2025 20:54
@kcp-ci-bot kcp-ci-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 19, 2025
@mjudeikis mjudeikis force-pushed the mjudeikis/apiexport.ep branch from f1b4a98 to 4f51231 Compare January 24, 2025 15:29
@kcp-ci-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from mjudeikis. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

@kcp-ci-bot kcp-ci-bot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 24, 2025
@mjudeikis mjudeikis force-pushed the mjudeikis/apiexport.ep branch from 4f51231 to 84ba80d Compare January 24, 2025 15:31
@mjudeikis mjudeikis changed the title ✨ APIExport noop without APIBinding POC ✨ APIExport with aware consumers Jan 24, 2025
@mjudeikis mjudeikis force-pushed the mjudeikis/apiexport.ep branch from 84ba80d to 4371b8f Compare January 26, 2025 20:14
@kcp-ci-bot kcp-ci-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 26, 2025
@mjudeikis
Copy link
Contributor Author

/retest

@mjudeikis mjudeikis force-pushed the mjudeikis/apiexport.ep branch 2 times, most recently from e6ed986 to 9c6093a Compare January 31, 2025 06:48
@embik embik self-requested a review January 31, 2025 07:57

path := logicalcluster.NewPath(apiExportEndpointSlice.Spec.APIExport.Path)
if path.Empty() {
path = logicalcluster.From(apiExportEndpointSlice).Path()
Copy link
Member

Choose a reason for hiding this comment

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

don't we need both ways to address it?

Copy link
Member

Choose a reason for hiding this comment

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

Depends on how you look it up later in the code.

Copy link
Contributor Author

@mjudeikis mjudeikis Feb 4, 2025

Choose a reason for hiding this comment

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

Not sure I understand this comment.
I don't :D

Copy link
Member

Choose a reason for hiding this comment

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

Now we only index exports as <lcluster>:export or <path>:export. Not both.

@mjudeikis mjudeikis force-pushed the mjudeikis/apiexport.ep branch from 96c29f1 to 705e3bb Compare January 31, 2025 17:17
@mjudeikis
Copy link
Contributor Author

/retest

@mjudeikis mjudeikis force-pushed the mjudeikis/apiexport.ep branch from 705e3bb to cda4f26 Compare February 2, 2025 10:30
@embik embik linked an issue Feb 5, 2025 that may be closed by this pull request
1 task
@@ -1,5 +1,5 @@
/*
Copyright 2022 The KCP Authors.
Copyright 2025 The KCP Authors.
Copy link
Member

Choose a reason for hiding this comment

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

nit: we usually don't update when just changing files.

@@ -93,10 +102,16 @@ type APIExportEndpoint struct {
}

func (in *APIExportEndpointSlice) GetConditions() conditionsv1alpha1.Conditions {
if in == nil {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we want this. It encourages brittle code.

// EndpointSliceReadyForURLs is a condition for APIExportEndpointSlice that reflects the readiness of the slice to
// provide URLs. It is set to True when the slice is ready to provide URLs which will be lifecycled based on existing consumers in the different
// shards.
APIExportEndpointSliceReadyForURLs conditionsv1alpha1.ConditionType = "EndpointReadyForURLs"
Copy link
Member

Choose a reason for hiding this comment

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

ReadyForEndpoints.

Actually not clear why we need this. When is it not ready?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Its more like handover/signal to secondary url controller. I used this a trigger. We could treat all conditions ready as signal too and just drop this all togheter.

Copy link
Member

Choose a reason for hiding this comment

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

Was thinking about the label selector. It must be known, right?

}

s := apiExportEndpointSlice.Status.ShardSelector
if s == "" { // should never happen.
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 what the condition above is guarding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory yes, but I wanted to avoid cases where somebody patched status and now it might give false positive.
And I think now that maybe this be omitempty pointer... Need to check if empty selector is valid case.


_, _ = globalShardClusterInformer.Informer().AddEventHandler(events.WithoutSyncs(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
c.enqueueAllAPIExportEndpointSlices(obj)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we care about other shards?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about a case where a change in shards could impact APIExportSlices flow. But wrong assumptions

}

// enqueueAPIExportEndpointSlicesForAPIExport enqueues APIExportEndpointSlices referencing a specific APIExport.
func (c *controller) enqueueAPIExportEndpointSlicesForAPIExport(obj interface{}) {
Copy link
Member

Choose a reason for hiding this comment

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

why do we care about reconciling when an export changes? Won't APIBindings eventually change and that is enough for us to be triggered?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's one of those wrong assumptions, I think. WIll try

return
}

{ // local to shard
Copy link
Member

Choose a reason for hiding this comment

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

why double code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

readability. It isolates variables and makes it very clear to read two blocks. Its all about reading code and reducing mental overhead when reading the code.
// local to shard
// from cache

@mjudeikis mjudeikis force-pushed the mjudeikis/apiexport.ep branch from 7ec0a3c to d28becd Compare February 9, 2025 12:10
@mjudeikis
Copy link
Contributor Author

/retest

@mjudeikis mjudeikis force-pushed the mjudeikis/apiexport.ep branch from 2b5c364 to 5546531 Compare February 9, 2025 15:09
@mjudeikis
Copy link
Contributor Author

/retest

@kcp-ci-bot
Copy link
Contributor

@mjudeikis: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kcp-test-e2e-sharded 5546531 link true /test pull-kcp-test-e2e-sharded

Full PR test history

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dco-signoff: yes Indicates the PR's author has signed the DCO. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: APIExports VirtualWorkspace without consumer enhancement
3 participants