-
Notifications
You must be signed in to change notification settings - Fork 402
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
✨ Add DynamicRESTMapper #3316
base: main
Are you sure you want to change the base?
✨ Add DynamicRESTMapper #3316
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
Skipping CI for Draft Pull Request. |
pluralToSingular map[schema.GroupVersionResource]schema.GroupVersionResource | ||
|
||
// Protects all DynamicRESTMapper's mappings. | ||
mapperLock sync.RWMutex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usual convention: put the lock just above (without empty lines) what it protects.
"k8s.io/apimachinery/pkg/runtime/schema" | ||
) | ||
|
||
type DynamicRESTMapper struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure where this is going. The data structures below are just the DefaultRESTMapper
ones, right?
What we need is that for every logical cluster in the system, i.e. something like map[logicalcluster.Name]DefaultRESTMapper
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed async, this needs to comply with the DefaultRestMapper interface but be logicalcluster compabile so every process in the shard could resolve particular cluster mappings. And as inspiration index https://github.com/kcp-dev/kcp/blob/main/pkg/index/index.go#L79 code could be referred.
Basically what sttts said :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking something under lines:
m := mapper.For(logicalcluster)
or
mapper.For(logicalcluster). KindFor()
which is basically same. Not sure if we want "global restmapper per shard at this point".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the examples! It would be great if we could use DefaultRESTMapper
as-is, but if I understood correctly, we'll need to delete the mappings too (when a CRD is removed), and since DefaultRESTMapper
doesn't implement deletion, we'd need to copy-paste all its code first :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"global restmapper per shard at this point".
This is only for the local shard.
and since DefaultRESTMapper doesn't implement deletion, we'd need to copy-paste all its code first :/
The existing code is pretty complex. Wondering how we can soft-fork it. I could see that with one additional constructor and some wrapping with locking we could reuse all the existing code, while being able to change the involved maps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking out loud:
soft-fork = maybe copy over through go generate and add a removal method in another file.
Sorry for early review. This somehow hit my timeline 😀 I figure this is super early. Let me know when it's ready for a real review. |
Commits more or less clean, and mapping for APIBindings, CRDs and built-in types should work. We're still missing tests though so I'm keeping this in Draft still. @sttts I've added the generator and a wrapper around the (generated) forked version of |
@@ -178,6 +180,8 @@ func NewServer(c CompletedConfig) (*Server, error) { | |||
} | |||
} | |||
|
|||
s.DynRESTMapper = dynamicrestmapper.NewDynamicRESTMapper(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this would be global mapper every controller can pull In? Can we add a comment here tell how this can be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment. Something like that?
@@ -0,0 +1,122 @@ | |||
#!/usr/bin/env bash |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this now part of the rebathe se procedure? Do you think we should add it to the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The script is now run as a part of make codegen
(5d2cf25) ; that way we don't need to rely on docs.
In general it really should be in the docs too, but the rebase docs are missing a lot of things. I can open a ticket and work on updating them, and mention the need to run the various generators we have. Would that be ok?
I've added unit tests and I feel like the code is ready for a review now. PTAL, thank you! |
4e79e56
to
b1bd7ef
Compare
On-behalf-of: SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
On-behalf-of: SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
We need to fork upstream's DefaultRESTMapper to be able to update and delete its contents dynamically. The script added in this commit does it automatically. On-behalf-of: SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
Ran: hack/gen-patch-defaultrestmapper.sh Generated from k8s.io/apimachinery v0.31.6. On-behalf-of: SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
On-behalf-of: SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
On-behalf-of: SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
On-behalf-of: SAP [email protected] Signed-off-by: Robert Vasek <[email protected]>
/retest all |
@gman0: The
Use
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. |
/test all |
The CI is failing on following error:
I ran the test locally without this PR (just the
Is this a test known to be flaky? In any case, it doesn't seem to be caused by this PR. |
/test pull-kcp-test-e2e-multiple-runs |
Summary
This PR adds DynamicRESTMapper. See the linked issue for details.
Related issue(s)
Fixes #3293
Release Notes