-
Notifications
You must be signed in to change notification settings - Fork 38.8k
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
OpenAPI-based CEL type library #113312
OpenAPI-based CEL type library #113312
Conversation
b6c7697
to
68225fb
Compare
59e4eaf
to
10ccc01
Compare
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.
Note: I guess we don't need the compilation and validation files here(might cause confusion). And the code would be tested in #113314. Currently the conversion(between object and ref.Val) failed(possible reason of lacking ref resolver?). Will retest after changes are made. Thank you!
Maybe worth to also add builtin type tests in this PR?
acdcd86
to
32f791f
Compare
/triage accepted |
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.
Also add tests showing how this can be used with a native types?
// UnstructuredToVal converts a Kubernetes unstructured data element to a CEL Val. | ||
// The root schema of custom resource schema is expected contain type meta and object meta schemas. | ||
// If Embedded resources do not contain type meta and object meta schemas, they will be added automatically. | ||
func UnstructuredToVal(unstructured interface{}, schema *spec.Schema) ref.Val { |
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.
Given that we primarily intend to support native types with this, should this instead be something like ObjectToVal(obj runtime.Object) ref.Val
and we can have the implementation look up the schema and convert the runtime.Object to unstructured using DefaultUnstructuredConverter
? This would allow us to change the implementation in the future (e.g. use a reflection based approach instead of conversion to unstructured) without changing the function signature.
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.
Current implementation let the caller to specify the schema because eventually the schema needs to be cached. It's better for the caller to maintain the cache to avoid having to provide another set of schema cache invalidation.
5accc99
to
f619a34
Compare
/test pull-kubernetes-unit |
f619a34
to
9f98812
Compare
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.
Functionality looks good. The copy-if-changed looks right. The wrapper is nice. Just a few minor comments.
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/model/adaptor.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/model/adaptor.go
Outdated
Show resolved
Hide resolved
4bb675d
to
b29f618
Compare
/cc @alexzielenski |
/lgtm |
LGTM label has been added. Git tree hash: 6d4c70f11001bbb6888a57a3c0ce989f7a28681e
|
All comments addressed, could you take another look when available? @liggitt |
ack, should be able to look later today |
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.
/approve
Thanks for all the iterations on this. There are still a couple spots that would be good to be sure we have benchmarks exercising (we might already? I'm not sure), but I'm very happy to see the full deep copies and recursive conversions go away
for n, prop := range s.Structural.Properties { | ||
s := prop | ||
res[n] = &Structural{Structural: &s} | ||
} |
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 a follow-up, it would be good to make sure we have benchmarks of validation-time calls that verify even this shallow-copy isn't problematic in terms of allocations
unkeyedItems: items, | ||
} | ||
func makeMapList(sts *schema.Structural, items []interface{}) (rv common.MapList) { | ||
return common.MakeMapList(&model.Structural{Structural: sts}, items) |
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.
same comment here about a follow-up benchmark that calls validate with a CRD and CR that ends up exercising this call so we have visibility to allocations
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jiahuif, liggitt 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 |
The Kubernetes project has merge-blocking tests that are currently too flaky to consistently pass. This bot retests PRs for certain kubernetes repos according to the following rules:
You can:
/retest |
What type of PR is this?
/kind feature
What this PR does / why we need it:
kube-openapi
, based on that ofstaging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel
, which usesstructural.Structural
.client-go
OpenAPI v3 discovery mechanism, the other with compiled-in OpenAPI definitions. Compiled-in resolver can be useful for the API server itself while ongoing development of client side CEL evaluation needs the discovery resolver.Special notes for your reviewer:
To limit the size of this PR, it does not include the part where the admission plugin uses the library.
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: