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

Promote feature CustomResourceValidationExpressions to beta #111158

Closed
wants to merge 1 commit into from

Conversation

cici37
Copy link
Contributor

@cici37 cici37 commented Jul 14, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR is to promote feature CustomResourceValidationExpressions to beta as it's proposed in KEP.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

The feature is in alpha since v1.23. For v1.25 cycle, we focus on performance optimization, test coverage, bug fix, metrics adding, dependency bumping, etc. The related PR FYI:

Graduation to beta criteria from the KEP

  • Resolve topic of what support we should provide for access to the previous versions of object (ie. 'oldSelf' feature) -- resolved in
    {name: "transition rules",
    obj: map[string]interface{}{
    "v": "new",
    },
    oldObj: map[string]interface{}{
    "v": "old",
    },
    schema: objectTypePtr(map[string]schema.Structural{
    "v": stringType,
    }),
    valid: []string{
    "oldSelf.v != self.v",
    "oldSelf.v == 'old' && self.v == 'new'",
    },
    },
    {name: "skipped transition rule for nil old primitive",
    expectSkipped: true,
    obj: "exists",
    oldObj: nil,
    schema: &stringType,
    valid: []string{
    "oldSelf == self",
    },
    },
    {name: "skipped transition rule for nil old array",
    expectSkipped: true,
    obj: []interface{}{},
    oldObj: nil,
    schema: listTypePtr(&stringType),
    valid: []string{
    "oldSelf == self",
    },
    },
    {name: "skipped transition rule for nil old object",
    expectSkipped: true,
    obj: map[string]interface{}{"f": "exists"},
    oldObj: nil,
    schema: objectTypePtr(map[string]schema.Structural{
    "f": stringType,
    }),
    valid: []string{
    "oldSelf.f == self.f",
    },
    },
    {name: "skipped transition rule for old with non-nil interface but nil value",
    expectSkipped: true,
    obj: []interface{}{},
    oldObj: nilInterfaceOfStringSlice(),
    schema: listTypePtr(&stringType),
    valid: []string{
    "oldSelf == self",
    },
    },
  • x-kubernetes-int-or-string is upgraded to use a union type of just int or string, not a dynamic type (CEL go support is planned in lates 2021) -- resolved in
    {name: "string in intOrString",
    obj: map[string]interface{}{
    "something": "25%",
    },
    schema: objectTypePtr(map[string]schema.Structural{
    "something": intOrStringType(),
    }),
    valid: []string{
    // In Kubernetes 1.24 and later, the CEL type returns false for an int-or-string comparison against the
    // other type, making it safe to write validation rules like:
    "self.something == '25%'",
    "self.something != 1",
    "self.something == 1 || self.something == '25%'",
    "self.something == '25%' || self.something == 1",
    // In Kubernetes 1.23 and earlier, all int-or-string access must be guarded by a type check to prevent
    // a runtime error attempting an equality check between string and int types.
    "type(self.something) == string && self.something == '25%'",
    "type(self.something) == int ? self.something == 1 : self.something == '25%'",
    // Because the type is dynamic it receives no type checking, and evaluates to false when compared to
    // other types at runtime.
    "self.something != ['anything']",
    },
    },
    {name: "int in intOrString",
    obj: map[string]interface{}{
    "something": int64(1),
    },
    schema: objectTypePtr(map[string]schema.Structural{
    "something": intOrStringType(),
    }),
    valid: []string{
    // In Kubernetes 1.24 and later, the CEL type returns false for an int-or-string comparison against the
    // other type, making it safe to write validation rules like:
    "self.something == 1",
    "self.something != 'some string'",
    "self.something == 1 || self.something == '25%'",
    "self.something == '25%' || self.something == 1",
    // In Kubernetes 1.23 and earlier, all int-or-string access must be guarded by a type check to prevent
    // a runtime error attempting an equality check between string and int types.
    "type(self.something) == int && self.something == 1",
    "type(self.something) == int ? self.something == 1 : self.something == '25%'",
    // Because the type is dynamic it receives no type checking, and evaluates to false when compared to
    // other types at runtime.
    "self.something != ['anything']",
    },
    },
  • Understanding of upper bounds of CPU/memory usage and appropriate limits set to prevent abuse.(Done in Add CEL runtime cost into CR validation #108482; Update CEL runtime cost limit #108595; Calculate CEL cost totals #108612; Reduce CEL runtime cost limits by 1/2 based on latency goals #109122)
  • Build-in macro/function library is comprehensive and stable (any changes to this will be a breaking change) - The later addition of quantity appears to complicate this. See CEL Validation Use Cases where it is postponed as a use-case (Add CEL function library #108312)
  • CEL numeric comparison issue is resolved (e.g. ability to compare ints to doubles) (Added test here)
  • Reduce noise of invalid data messages reported from cel.UnstructuredToVal #106440 Asking for clarification of the fix
  • Benchmark cel.UnstructuredToVal and optimize away repeated wrapper object construction #106438
  • Demonstrate adoption and successful feature usage in the community -- confirmed against the list in CEL Validation Use Cases. quantity to be rejected by supported releases when it is added.
  • Optimization on super-linear complexity growth (Optimize away repeated structural schema and CEL DeclType construction in CRD validation #110135)
  • Adding metric of the latency of CEL evaluation for CRD evaluation

Does this PR introduce a user-facing change?

Graduated `CustomResourceValidationExpressions` to `beta`. The `CustomResourceValidationExpressions` feature gate is now enabled by default.

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

- [KEP]: https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/2876-crd-validation-expression-language/README.md

@k8s-ci-robot
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

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 14, 2022
@cici37 cici37 marked this pull request as ready for review July 14, 2022 20:13
@k8s-ci-robot k8s-ci-robot added do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Jul 14, 2022
@cici37 cici37 added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Jul 14, 2022
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jul 14, 2022
@cici37 cici37 added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Jul 14, 2022
@k8s-ci-robot k8s-ci-robot removed the needs-priority Indicates a PR lacks a `priority/foo` label and requires one. label Jul 14, 2022
@cici37 cici37 added this to the v1.25 milestone Jul 14, 2022
@cici37
Copy link
Contributor Author

cici37 commented Jul 14, 2022

/sig api-machinery

@cici37 cici37 removed the do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. label Jul 14, 2022
@cici37
Copy link
Contributor Author

cici37 commented Jul 14, 2022

cc @jpbetz @liggitt

@jiahuif
Copy link
Member

jiahuif commented Jul 14, 2022

Don't forget to update pkg/features/kube_features.go too

@jiahuif
Copy link
Member

jiahuif commented Jul 14, 2022

/cc

@liggitt
Copy link
Member

liggitt commented Jul 14, 2022

updated the description to a bulleted list of the PRs, so we can see they all merged before merging this one

@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. area/conformance Issues or PRs related to kubernetes conformance tests sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jul 26, 2022
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jul 26, 2022
@cici37
Copy link
Contributor Author

cici37 commented Jul 26, 2022

The e2e test associated with this feature will be handled in separate PR: #111448

@deads2k
Copy link
Contributor

deads2k commented Jul 26, 2022

I'm diffing against the list in https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/2876-crd-validation-expression-language/README.md#beta

I'm assessing "Demonstrate adoption and successful feature usage in the community" based on use-cases contained in https://docs.google.com/document/d/1KatwZJ3O0lTThs1Lg8YqY-PipbNM8aaUDDdPCLd3lic/edit?resourcekey=0-YeuQhCZlstVjL61WVqrz_w# that have specific reference and relating them back to the unit tests that ensure they work.

I'll also come back to the rest of the criteria and check them as well.

@deads2k
Copy link
Contributor

deads2k commented Jul 26, 2022

note to self, int-or-string evaluation is confirmed here:

{name: "string in intOrString",
obj: map[string]interface{}{
"something": "25%",
},
schema: objectTypePtr(map[string]schema.Structural{
"something": intOrStringType(),
}),
valid: []string{
// In Kubernetes 1.24 and later, the CEL type returns false for an int-or-string comparison against the
// other type, making it safe to write validation rules like:
"self.something == '25%'",
"self.something != 1",
"self.something == 1 || self.something == '25%'",
"self.something == '25%' || self.something == 1",
// In Kubernetes 1.23 and earlier, all int-or-string access must be guarded by a type check to prevent
// a runtime error attempting an equality check between string and int types.
"type(self.something) == string && self.something == '25%'",
"type(self.something) == int ? self.something == 1 : self.something == '25%'",
// Because the type is dynamic it receives no type checking, and evaluates to false when compared to
// other types at runtime.
"self.something != ['anything']",
},
},
{name: "int in intOrString",
obj: map[string]interface{}{
"something": int64(1),
},
schema: objectTypePtr(map[string]schema.Structural{
"something": intOrStringType(),
}),
valid: []string{
// In Kubernetes 1.24 and later, the CEL type returns false for an int-or-string comparison against the
// other type, making it safe to write validation rules like:
"self.something == 1",
"self.something != 'some string'",
"self.something == 1 || self.something == '25%'",
"self.something == '25%' || self.something == 1",
// In Kubernetes 1.23 and earlier, all int-or-string access must be guarded by a type check to prevent
// a runtime error attempting an equality check between string and int types.
"type(self.something) == int && self.something == 1",
"type(self.something) == int ? self.something == 1 : self.something == '25%'",
// Because the type is dynamic it receives no type checking, and evaluates to false when compared to
// other types at runtime.
"self.something != ['anything']",
},
},

@deads2k
Copy link
Contributor

deads2k commented Jul 27, 2022

/lgtm
/approve
/hold

holding for the comment update. Feel free to re-lgtm and unhold after that.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 27, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cici37, deads2k

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 27, 2022
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 27, 2022
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@k8s-ci-robot
Copy link
Contributor

@cici37: 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-kubernetes-integration 64e6cf1 link true /test pull-kubernetes-integration

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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.

@jpbetz
Copy link
Contributor

jpbetz commented Jul 28, 2022

The pull-kubernetes-integration failures for k8s.io/kubernetes/test/integration/apiserver/apply: TestApplyCRDUnhandledSchema are from #110135. Looking into it.

@jpbetz
Copy link
Contributor

jpbetz commented Jul 28, 2022

Fix for TestApplyCRDUnhandledSchema failure: #111483

@cici37
Copy link
Contributor Author

cici37 commented Jul 28, 2022

Proposed a fix in #111504. Will hold current PR until either of them merged.

Fix for TestApplyCRDUnhandledSchema failure: #111483

@cici37
Copy link
Contributor Author

cici37 commented Jul 29, 2022

This PR got accidentally closed and cannot be reopen due to a force-push. Open #111524 as a duplication

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. area/apiserver area/conformance Issues or PRs related to kubernetes conformance tests area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/feature Categorizes issue or PR as related to a new feature. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants