You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was writing some Rego policies for Kubernetes Admission Control objects the other day and wanted to create some example rules regarding resource usage. One barrier that I ran into is that it's quite difficult in Rego to work with strings like 100Mi, 5gb, and 100KB (i.e. the system described here). A built-in function converting those strings into an integer number of bytes would make it dramatically easier to, for example, make comparisons, assign limits, etc. Here's an example:
@lucperkins and I discussed this offline. This would be fairly useful for writing k8s admission control policies. In fact, @timothyhinrichs put together a video where he implemented conversions inside of Rego: https://www.youtube.com/watch?v=iBHf7Nzf-Lg. As long as we construct the ast.Number value using math/big operations we won't have to worry about loss of precision.
I was writing some Rego policies for Kubernetes Admission Control objects the other day and wanted to create some example rules regarding resource usage. One barrier that I ran into is that it's quite difficult in Rego to work with strings like
100Mi
,5gb
, and100KB
(i.e. the system described here). A built-in function converting those strings into an integer number of bytes would make it dramatically easier to, for example, make comparisons, assign limits, etc. Here's an example:I have a PR basically ready to go for this if it sounds useful to others.
The text was updated successfully, but these errors were encountered: