fix: Validation for Resource Limits #2201
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Intermittently we are observing unexpected and invalid memory resource limits being set for the ScanJob pods.
Example:
trivy-system scan-vulnerabilityreport-5594588b7b-w9m7l 500m (3%) 750m (4%) 512Mi (1%) 1288490188800m (3%) 7s
Operator Log:
{"level":"info","ts":"2024-07-26T07:42:18Z","logger":"KubeAPIWarningLogger","msg":"spec.template.spec.containers[6].resources.limits[memory]: fractional byte value \"1288490188800m\" is invalid, must be an integer"}
As such, this PR introduces validations in config.go for ResourceMemory, ResourceEphemeralStorage, and ResourceCPU to ensure the values passed from the configuration (or default) are valid as well as validating the parsed values match the expected values to prevent unexpected resource allocations.
Additionally, this PR updates the documentation to use the Mi unit for memory allocation as it is more commonly used in Kubernetes configurations
Related issues
Checklist