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

MessageExpression for ValidatingAdmissionPolicy #116397

Conversation

jiahuif
Copy link
Member

@jiahuif jiahuif commented Mar 9, 2023

What type of PR is this?

/kind feature
/kind api-change

What this PR does / why we need it:

This PR adds support for messageExpression to ValidatingAdmissionPolicy, to set a custom message when the policy rejects a request.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

API REVIEW Please take a look at the first commit labeled [API REVIEW]
Please note that the API is mirrored from #115969, which already got API approved.

Does this PR introduce a user-facing change?

Added `messageExpression` to `ValidatingAdmissionPolicy`, to set custom failure message via CEL expression.

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


@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. 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. labels Mar 9, 2023
@k8s-ci-robot k8s-ci-robot added kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 9, 2023
@cici37
Copy link
Contributor

cici37 commented Mar 9, 2023

/triage accepted
/assign

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Mar 9, 2023
@jiahuif jiahuif force-pushed the feature/validating-admission-policy/message-expression branch from 19434f7 to ff7f5c7 Compare March 9, 2023 18:10
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. area/code-generation and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 9, 2023
@jiahuif jiahuif force-pushed the feature/validating-admission-policy/message-expression branch from ff7f5c7 to 1cad54b Compare March 9, 2023 18:28
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/apiserver and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 9, 2023
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 13, 2023
@jiahuif jiahuif force-pushed the feature/validating-admission-policy/message-expression branch from 80a2288 to 2ac6120 Compare March 13, 2023 21:23
@jiahuif jiahuif force-pushed the feature/validating-admission-policy/message-expression branch from 2ac6120 to 46fcb76 Compare March 13, 2023 21:40
@liggitt
Copy link
Member

liggitt commented Mar 13, 2023

/approve
for API changes
@cici37 or @jpbetz have lgtm for message impl

@liggitt liggitt moved this from Changes requested to API review completed, 1.27 in API Reviews Mar 13, 2023
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 13, 2023
// runtimeCELCostBudget was added for testing purpose only. Callers should always use const RuntimeCELCostBudget from k8s.io/apiserver/pkg/apis/cel/config.go as input.
ForInput(ctx context.Context, versionedAttr *admission.VersionedAttributes, request *v1.AdmissionRequest, optionalVars OptionalVariableBindings, runtimeCELCostBudget int64) ([]EvaluationResult, error)
// If cost budget is calculated, the filter should return the remaining budget.
ForInput(ctx context.Context, versionedAttr *admission.VersionedAttributes, request *v1.AdmissionRequest, optionalVars OptionalVariableBindings, runtimeCELCostBudget int64) ([]EvaluationResult, int64, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test case for returned remaining budget?

Copy link
Member Author

Choose a reason for hiding this comment

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

added.

@jiahuif jiahuif force-pushed the feature/validating-admission-policy/message-expression branch 5 times, most recently from 159082b to 51a9c91 Compare March 13, 2023 22:28
@@ -43,11 +44,17 @@ type fakeCelFilter struct {
throwError bool
}

func (f *fakeCelFilter) ForInput(context.Context, *admission.VersionedAttributes, *admissionv1.AdmissionRequest, cel.OptionalVariableBindings, int64) ([]cel.EvaluationResult, error) {
func (f *fakeCelFilter) ForInput(_ context.Context, _ *admission.VersionedAttributes, _ *admissionv1.AdmissionRequest, _ cel.OptionalVariableBindings, costBudget int64) ([]cel.EvaluationResult, int64, error) {
if costBudget <= 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

<0?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really. the expression itself costs one. Needs at least 1 to cover it.

@jiahuif jiahuif force-pushed the feature/validating-admission-policy/message-expression branch 2 times, most recently from 7e6fb37 to 327a633 Compare March 13, 2023 22:39
},
},
{
name: "messageExpression out of budget after successful eval of expression",
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to see the test for budget shared between expression and messageExpression

Copy link
Member Author

Choose a reason for hiding this comment

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

:)

@jiahuif jiahuif force-pushed the feature/validating-admission-policy/message-expression branch 2 times, most recently from 074ac6d to e1678f2 Compare March 13, 2023 22:51
@cici37
Copy link
Contributor

cici37 commented Mar 13, 2023

/lgtm
/approve

Thank you!

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

LGTM label has been added.

Git tree hash: ddf4f31b9795dc949c3237c87f5daab21dba1a55

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cici37, 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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 6b3e2b7 into kubernetes:master Mar 14, 2023
@jiahuif
Copy link
Member Author

jiahuif commented Mar 14, 2023

Thank you all for reviewing.

@jiahuif jiahuif deleted the feature/validating-admission-policy/message-expression branch March 14, 2023 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/code-generation cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.27
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

9 participants