Skip to content

Make RESTMapper in client cluster-aware #57

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

Merged
merged 4 commits into from
Sep 1, 2024

Conversation

sttts
Copy link
Member

@sttts sttts commented Aug 20, 2024

This PR makes discovery cluster-aware, i.e. the RESTMapper is instantiated per cluster and cached with an LRU cache.

This matters because currently the controller-runtime client is unusable on non-uniform virtual workspaces or even against kcp itself as a scoped client because the used REST mapper talks to the wildcard endpoint only.

@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. dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 20, 2024
var mu sync.RWMutex
cache := expirable.NewLRU[logicalcluster.Path, meta.RESTMapper](1000, nil, time.Minute)
return func(ctx context.Context) (meta.RESTMapper, error) {
c, _ := kontext.ClusterFrom(ctx)

Choose a reason for hiding this comment

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

The error from kontext.ClusterFrom(ctx) is ignored (c, _ := kontext.ClusterFrom(ctx)). We may consider it.

c, err := kontext.ClusterFrom(ctx)
if err != nil {
    // Handle error appropriately, perhaps returning a nil mapper with the error
    return nil, err
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Noticed that the second return value is a boolean, not an error. Will add a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@kcp-ci-bot
Copy link

@soumyadip007: changing LGTM is restricted to collaborators

In response to this:

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.

@sttts sttts force-pushed the sttts-cluster-aware-rest-mapper branch from 0f36a17 to be71e2c Compare August 30, 2024 13:10
@sttts sttts changed the title WIP: make RESTMapper in client cluster-aware make RESTMapper in client cluster-aware Aug 30, 2024
@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 Aug 30, 2024
@sttts sttts force-pushed the sttts-cluster-aware-rest-mapper branch 4 times, most recently from 61933e4 to 440ded2 Compare August 30, 2024 13:33
@sttts sttts changed the title make RESTMapper in client cluster-aware Make RESTMapper in client cluster-aware Aug 30, 2024
@sttts sttts force-pushed the sttts-cluster-aware-rest-mapper branch 4 times, most recently from 0874689 to afafb15 Compare August 30, 2024 14:02
@sttts
Copy link
Member Author

sttts commented Aug 30, 2024

/retest

1 similar comment
@sttts
Copy link
Member Author

sttts commented Aug 30, 2024

/retest

@sttts sttts force-pushed the sttts-cluster-aware-rest-mapper branch from afafb15 to 2272adc Compare August 31, 2024 08:37
@kcp-ci-bot kcp-ci-bot added 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 Aug 31, 2024
@sttts sttts force-pushed the sttts-cluster-aware-rest-mapper branch 4 times, most recently from c11bdf3 to adffd80 Compare August 31, 2024 09:22
@kcp-ci-bot kcp-ci-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 31, 2024
@sttts sttts force-pushed the sttts-cluster-aware-rest-mapper branch from adffd80 to 900a3c9 Compare August 31, 2024 09:29
@kcp-ci-bot kcp-ci-bot added 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 Aug 31, 2024
@sttts sttts force-pushed the sttts-cluster-aware-rest-mapper branch from 900a3c9 to 8a658d8 Compare August 31, 2024 09:30
@sttts sttts force-pushed the sttts-cluster-aware-rest-mapper branch from 8a658d8 to ef8fdeb Compare August 31, 2024 09:35
@embik embik self-requested a review August 31, 2024 15:01
Copy link

@mjudeikis mjudeikis left a comment

Choose a reason for hiding this comment

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

just nit hypotatical question. else - lgtm to me. Will wait for @embik cycle

},
scheme: options.Scheme,
mapper: options.Mapper,
}
mapperCache, err := lru.New[logicalcluster.Name, meta.RESTMapper](1000)

Choose a reason for hiding this comment

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

Would it make sense 1000 to create a global variable? If somebody wants to tune it, its possible this way?

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed.

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 1, 2024
@kcp-ci-bot
Copy link

LGTM label has been added.

Git tree hash: 012e2b48af67a9a94da088abcc0ca6420e82eec7

@kcp-ci-bot kcp-ci-bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 1, 2024
@kcp-ci-bot kcp-ci-bot requested a review from mjudeikis September 1, 2024 16:33
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
@sttts sttts force-pushed the sttts-cluster-aware-rest-mapper branch from 000384b to 83ac60c Compare September 1, 2024 16:41
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
@mjudeikis
Copy link

/lgtm
/approve

@kcp-ci-bot kcp-ci-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 1, 2024
@kcp-ci-bot
Copy link

LGTM label has been added.

Git tree hash: e5fbb599c01580fe2f73c6de2763b38d309d80f3

@kcp-ci-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mjudeikis

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

@kcp-ci-bot kcp-ci-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 1, 2024
@kcp-ci-bot kcp-ci-bot merged commit bfd00bd into kcp-dev:kcp-0.18 Sep 1, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates the PR's author has signed the DCO. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants