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

feat: support for numeric operators #1536

Conversation

yashvardhan-kukreja
Copy link
Contributor

@yashvardhan-kukreja yashvardhan-kukreja commented Feb 3, 2021

Signed-off-by: Yashvardhan Kukreja yash.kukreja.98@gmail.com

Related issue

#1512

What type of PR is this?

/kind feature

Proposed changes

The newly added operators which can be applied to validate.deny.conditions and preconditions over kyverno policy rules are the following:

  • GreaterThanOrEquals : key >= value?
  • GreaterThan : key > value?
  • LessThanOrEquals : key <= value?
  • LessThan : key < value?

Checklist

Further comments

Here, the key will only be expected to be int, int64, float, float64, string (for the cases like "2", "2.4" only)
In rest of the cases, an error with saying "Unknown key type found" would be generated because clearly, these are numeric operators and these operations can't be applied on types which can't be casted to int or float.

@yashvardhan-kukreja
Copy link
Contributor Author

yashvardhan-kukreja commented Feb 3, 2021

@JimBugwadia for now I have implemented the support for GreaterThanOrEquals operator. Please give it a look and if it looks fine, I'll implement GreaterThan, LessThan and LessThanOrEquals operators as well in the same way.

@yashvardhan-kukreja yashvardhan-kukreja force-pushed the issue-1512/support-for-numeric-operator branch from 6fe45f1 to b08b066 Compare February 3, 2021 21:36
@JimBugwadia
Copy link
Member

@yashvardhan-kukreja - looks good! I would suggest factoring out reusable code wherever possible as you implement the other operators. This package seems to have a lot of duplication we can improve. Thanks!

@yashvardhan-kukreja
Copy link
Contributor Author

@yashvardhan-kukreja - looks good! I would suggest factoring out reusable code wherever possible as you implement the other operators. This package seems to have a lot of duplication we can improve. Thanks!

True. I was thinking of creating one NumericOperatorHandler which will handle the work of all the GreaterThanOrEquals, GreaterThan, LessThan, LessThanOrEquals operators.

…no policies

Signed-off-by: Yashvardhan Kukreja <yash.kukreja.98@gmail.com>
@yashvardhan-kukreja yashvardhan-kukreja force-pushed the issue-1512/support-for-numeric-operator branch from b08b066 to f7e775f Compare February 4, 2021 08:27
@yashvardhan-kukreja
Copy link
Contributor Author

yashvardhan-kukreja commented Feb 4, 2021

@JimBugwadia @realshuting I have implemented a generic NumericOperator which will help in dealing with all the numeric operations. PTAL and let me know if it looks fine.
Thanks :)

Copy link
Member

@realshuting realshuting left a comment

Choose a reason for hiding this comment

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

Looks good!

@realshuting
Copy link
Member

Please use closing keywords in the pull request's description, the issue will be closed when merging into the default branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants