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

fix(kubernetes): fix in CPURequests check #3727

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions checkov/kubernetes/checks/resource/k8s/CPURequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def scan_container_conf(self, metadata: Dict[str, Any], conf: Dict[str, Any]) ->
self.evaluated_container_keys = ["resources/requests/cpu"]
res = conf.get("resources")
if res:
if not isinstance(res, dict):
return CheckResult.UNKNOWN
requests = res.get("requests")
if requests and requests.get("cpu"):
return CheckResult.PASSED
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Pod
metadata:
name: frontend
spec:
containers:
- name: db
image: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "password"
resources:
- requests:
memory: "64Mi"
cpu: "250m"
ephemeral-storage: "2Gi"
limits:
memory: "128Mi"
cpu: "500m"
ephemeral-storage: "4Gi"
2 changes: 1 addition & 1 deletion tests/kubernetes/checks/test_CPURequests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_summary(self):
current_dir = os.path.dirname(os.path.realpath(__file__))

test_files_dir = current_dir + "/example_Requests_Limits"
report = runner.run(root_folder=test_files_dir,runner_filter=RunnerFilter(checks=[check.id]))
report = runner.run(root_folder=test_files_dir, runner_filter=RunnerFilter(checks=[check.id]))
summary = report.get_summary()

self.assertEqual(summary['passed'], 1)
Expand Down