Skip to content

Commit

Permalink
Merge pull request #553 from kubescape/fix_c_0004
Browse files Browse the repository at this point in the history
fix control C-0004
  • Loading branch information
kooomix authored Dec 11, 2023
2 parents 9679743 + c010f45 commit 84db4a8
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
18 changes: 11 additions & 7 deletions rules/resources-memory-limit-and-request/raw.rego
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ is_min_request_exceeded_memory(memory_req) {
compare_min(memory_req_min, memory_req)
}


##############
# helpers

Expand All @@ -305,23 +306,23 @@ compare_max(max, given) {
endswith(given, "Mi")
split_max := split(max, "Mi")[0]
split_given := split(given, "Mi")[0]
split_given > split_max
to_number(split_given) > to_number(split_max)
}

compare_max(max, given) {
endswith(max, "M")
endswith(given, "M")
split_max := split(max, "M")[0]
split_given := split(given, "M")[0]
split_given > split_max
to_number(split_given) > to_number(split_max)
}

compare_max(max, given) {
endswith(max, "m")
endswith(given, "m")
split_max := split(max, "m")[0]
split_given := split(given, "m")[0]
split_given > split_max
to_number(split_given) > to_number(split_max)
}

compare_max(max, given) {
Expand All @@ -337,29 +338,32 @@ compare_min(min, given) {
endswith(given, "Mi")
split_min := split(min, "Mi")[0]
split_given := split(given, "Mi")[0]
split_given < split_min
to_number(split_given) < to_number(split_min)
}

compare_min(min, given) {
endswith(min, "M")
endswith(given, "M")
split_min := split(min, "M")[0]
split_given := split(given, "M")[0]
split_given < split_min
to_number(split_given) < to_number(split_min)

}

compare_min(min, given) {
endswith(min, "m")
endswith(given, "m")
split_min := split(min, "m")[0]
split_given := split(given, "m")[0]
split_given < split_min
to_number(split_given) < to_number(split_min)

}

compare_min(min, given) {
not is_special_measure(min)
not is_special_measure(given)
given < min
to_number(given) < to_number(min)

}

# Check that is same unit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"postureControlInputs": {
"memory_limit_max": ["256Mi"],
"memory_request_max": ["128Mi"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: frontend
spec:
containers:
- name: app
image: images.my-company.example/app:v4
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"

0 comments on commit 84db4a8

Please sign in to comment.