Skip to content

Commit

Permalink
fix(kustomize): Added support for case where no parents are found for…
Browse files Browse the repository at this point in the history
… the relative fie path (#5332)

Added support for case where no parents are found for the relative file path
  • Loading branch information
bo156 committed Jul 13, 2023
1 parent 18b5597 commit d8bb400
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion checkov/kustomize/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ def _get_caller_file_path(k8s_file_dir: pathlib.Path, origin_relative_path: str,
"""
amount_of_parents = str.count(origin_relative_path, '..')
directory_prefix_path = k8s_file_dir
if amount_of_parents:
if amount_of_parents == 0:
# In case we don't have any relative paths, we need to remove the first directory parent
# (as the first directory is the same one of the kustomization.yaml file)
directory_prefix_path = k8s_file_dir.parent
elif amount_of_parents:
directory_prefix_path = k8s_file_dir.parents[amount_of_parents - 1]

directory_prefix = str(directory_prefix_path)
Expand Down

0 comments on commit d8bb400

Please sign in to comment.