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

Invalid parsing of ResourceQuota yaml file #928

Closed
mkucharsky opened this issue Mar 8, 2024 · 1 comment
Closed

Invalid parsing of ResourceQuota yaml file #928

mkucharsky opened this issue Mar 8, 2024 · 1 comment

Comments

@mkucharsky
Copy link

mkucharsky commented Mar 8, 2024

ResourceQuota object definition involves limits keys with dots and there is issue to get the value of the limits:

policy.rego

package main

deny_incorrect_memory_unit[msg] {
  input.kind == "ResourceQuota"
  memoryLimit := input.spec.hard.limits.memory

  not regex.match("^[0-9]+M$", memoryLimit)
  msg := sprintf("%s: Incorrect value %s. Memory Limit in ResourceQuota must be defined in Megabytes (M) unit", [input.metadata.namespace, memoryLimit])
}

resource-quota.yaml

apiVersion: v1
kind: ResourceQuota
metadata:
  name: app
  namespace: backend
spec:
  hard:
    pods: 1
    limits.cpu: 3
    limits.memory: "1G"

In above example test finishes with success, despite of wrong unit in limits.memory
After replacing yaml file to the below structure (which are not supported by k8s) test finish with expected result - failure:

spec:
  hard:
    pods: 1
    limits:
        cpu: 3
        memory: "1G"

Tested on version 0.32.0 and 0.50.0

@mkucharsky
Copy link
Author

I found solution. I need use input.spec.hard["limits.memory"]

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

No branches or pull requests

1 participant