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

Adds support for CEL marker comments #445

Merged
merged 4 commits into from
Jan 17, 2024

Conversation

alexzielenski
Copy link
Contributor

@alexzielenski alexzielenski commented Jan 6, 2024

Adds CEL marker comments support to kube-openapi. Previous extension support only allowed strings. This PR makes use of new marker comment system introduced in #435 to emit CEL vendor extensions.

Multiline syntax is not yet supported. Proposed syntax is 1:1 with CEL CRD fields:

	// +k8s:validation:cel[0]:rule="self.length() > 0"
	// +k8s:validation:cel[0]:message="string message"
	// +k8s:validation:cel[1]:rule="self.length() % 2 == 0"
	// +k8s:validation:cel[1]:messageExpression="self + ' hello'"
	// +optional
	CELField string `json:"celField"`

There are linter errors to help keep the indexing straight

/assign @Jefftree
/cc @Schnides123

@k8s-ci-robot
Copy link
Contributor

@alexzielenski: GitHub didn't allow me to request PR reviews from the following users: Schnides123.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

Adds CEL marker comments support to kube-openapi. Previous extension support only allowed strings. This PR makes use of new marker comment system introduced in #435 to emit CEL vendor extensions.

Multiline syntax is not yet supported. Proposed syntax is 1:1 with CEL CRD fields:

  // +k8s:validation:cel[0]:rule="self.length() > 0"
  // +k8s:validation:cel[0]:message="string message"
  // +k8s:validation:cel[1]:rule="self.length() % 2 == 0"
  // +k8s:validation:cel[1]:messageExpression="self + ' hello'"
  // +optional
  CELField string `json:"celField"`

/assign @Jefftree
/cc @Schnides123

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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 6, 2024
@alexzielenski
Copy link
Contributor Author

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 8, 2024
Copy link
Member

@Jefftree Jefftree left a comment

Choose a reason for hiding this comment

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

Mostly looks good. Still familiarizing myself with parts of CEL so lmk if any comments don't make sense.

pkg/generators/markers.go Show resolved Hide resolved
pkg/generators/markers.go Outdated Show resolved Hide resolved
pkg/generators/markers.go Show resolved Hide resolved
pkg/generators/markers.go Outdated Show resolved Hide resolved
pkg/generators/markers_test.go Outdated Show resolved Hide resolved
pkg/generators/markers_test.go Outdated Show resolved Hide resolved
pkg/generators/markers_test.go Show resolved Hide resolved
pkg/generators/markers_test.go Show resolved Hide resolved
pkg/generators/markers.go Show resolved Hide resolved
pkg/generators/markers.go Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 10, 2024
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 10, 2024
subscriptIdx := strings.Index(line, "[")
split := strings.Split(line, "=")
if len(split) < 2 {
// Ignore malformed key in linter.
Copy link
Member

Choose a reason for hiding this comment

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

no error?

Copy link
Member

Choose a reason for hiding this comment

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

actually, just realized this is possible with bool, so in a sense it's not malformed?

The error would still get caught later on when validating empty CEL tags, not sure if you'd like to error earlier though?

Test case:

				`+k8s:validation:cel[0]:rule="oldSelf == self"`,
				`+k8s:validation:cel[6]:optionalOldSelf`,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The error would still get caught later on when validating empty CEL tags, not sure if you'd like to error earlier though?

The linter is not meant to catch those types of errors. Just avoid common mistakes labelling array indices

actually, just realized this is possible with bool, so in a sense it's not malformed?

That's a good catch. Ill add a test and fix that case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed & added tests

@Jefftree
Copy link
Member

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexzielenski, Jefftree

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:
  • OWNERS [Jefftree,alexzielenski]

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 removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 17, 2024
@alexzielenski
Copy link
Contributor Author

squashed, @Jefftree can you re-lgtm?

@alexzielenski
Copy link
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 17, 2024
@Jefftree
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 17, 2024
@k8s-ci-robot k8s-ci-robot merged commit 2086090 into kubernetes:master Jan 17, 2024
4 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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", 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