Skip to content

Commit

Permalink
Update unset-memory-requirements and unset-cpu-requirements, fixes #694
Browse files Browse the repository at this point in the history
  • Loading branch information
bgalek committed Feb 26, 2024
1 parent 83eb236 commit 07f4b1c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docs/generated/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ unsafeSysCtls:
```yaml
lowerBoundMillis: 0
requirementsType: any
requirementsType: request
upperBoundMillis: 0
```
## unset-memory-requirements
Expand All @@ -654,7 +654,7 @@ upperBoundMillis: 0
```yaml
lowerBoundMB: 0
requirementsType: any
requirementsType: request
upperBoundMB: 0
```
## use-namespace
Expand Down
20 changes: 6 additions & 14 deletions e2etests/bats-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -903,16 +903,12 @@ get_value_from() {
[ "$status" -eq 1 ]

message1=$(get_value_from "${lines[0]}" '.Reports[0].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[0].Diagnostic.Message')
message2=$(get_value_from "${lines[0]}" '.Reports[1].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[1].Diagnostic.Message')
message3=$(get_value_from "${lines[0]}" '.Reports[2].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[2].Diagnostic.Message')
message4=$(get_value_from "${lines[0]}" '.Reports[3].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[3].Diagnostic.Message')
message2=$(get_value_from "${lines[0]}" '.Reports[2].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[2].Diagnostic.Message')
count=$(get_value_from "${lines[0]}" '.Reports | length')

[[ "${message1}" == "Deployment: container \"app\" has cpu request 0" ]]
[[ "${message2}" == "Deployment: container \"app\" has cpu limit 0" ]]
[[ "${message3}" == "DeploymentConfig: container \"app\" has cpu request 0" ]]
[[ "${message4}" == "DeploymentConfig: container \"app\" has cpu limit 0" ]]
[[ "${count}" == "4" ]]
[[ "${message2}" == "DeploymentConfig: container \"app\" has cpu request 0" ]]
[[ "${count}" == "2" ]]
}

@test "unset-memory-requirements" {
Expand All @@ -924,16 +920,12 @@ get_value_from() {
[ "$status" -eq 1 ]

message1=$(get_value_from "${lines[0]}" '.Reports[0].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[0].Diagnostic.Message')
message2=$(get_value_from "${lines[0]}" '.Reports[1].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[1].Diagnostic.Message')
message3=$(get_value_from "${lines[0]}" '.Reports[2].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[2].Diagnostic.Message')
message4=$(get_value_from "${lines[0]}" '.Reports[3].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[3].Diagnostic.Message')
message2=$(get_value_from "${lines[0]}" '.Reports[2].Object.K8sObject.GroupVersionKind.Kind + ": " + .Reports[2].Diagnostic.Message')
count=$(get_value_from "${lines[0]}" '.Reports | length')

[[ "${message1}" == "Deployment: container \"app\" has memory request 0" ]]
[[ "${message2}" == "Deployment: container \"app\" has memory limit 0" ]]
[[ "${message3}" == "DeploymentConfig: container \"app\" has memory request 0" ]]
[[ "${message4}" == "DeploymentConfig: container \"app\" has memory limit 0" ]]
[[ "${count}" == "4" ]]
[[ "${message2}" == "DeploymentConfig: container \"app\" has memory request 0" ]]
[[ "${count}" == "2" ]]
}

@test "use-namespace" {
Expand Down
4 changes: 2 additions & 2 deletions pkg/builtinchecks/yamls/unset-cpu-requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ scope:
objectKinds:
- DeploymentLike
remediation: >-
Set CPU requests and limits for your container based on its requirements.
Set CPU limits for your container based on its requirements.
Refer to https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits for details.
template: "cpu-requirements"
params:
requirementsType: "any"
requirementsType: "request"
lowerBoundMillis: 0
upperBoundMillis: 0
4 changes: 2 additions & 2 deletions pkg/builtinchecks/yamls/unset-memory-requirements.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: "unset-memory-requirements"
description: "Indicates when containers do not have memory requests and limits set."
remediation: >-
Set memory requests and limits for your container based on its requirements.
Set memory limits for your container based on its requirements.
Refer to https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#requests-and-limits for details.
scope:
objectKinds:
- DeploymentLike
template: "memory-requirements"
params:
requirementsType: "any"
requirementsType: "request"
lowerBoundMB: 0
upperBoundMB: 0

0 comments on commit 07f4b1c

Please sign in to comment.