Skip to content

Commit

Permalink
Solves: Make thread count configurable #433
Browse files Browse the repository at this point in the history
  • Loading branch information
florianbachmann authored and danielsagi committed May 7, 2022
1 parent e6a3c12 commit 6c4ad4f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions kube_hunter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
log_file=args.log_file,
mapping=args.mapping,
network_timeout=args.network_timeout,
num_worker_threads=args.num_worker_threads,
pod=args.pod,
quick=args.quick,
remote=args.remote,
Expand Down
2 changes: 2 additions & 0 deletions kube_hunter/conf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Config:
- log_file: Log File path
- mapping: Report only found components
- network_timeout: Timeout for network operations
- num_worker_threads: Add a flag --threads to change the default 800 thread count of the event handler
- pod: From pod scanning mode
- quick: Quick scanning mode
- remote: Hosts to scan
Expand All @@ -36,6 +37,7 @@ class Config:
log_file: Optional[str] = None
mapping: bool = False
network_timeout: float = 5.0
num_worker_threads: int = 800
pod: bool = False
quick: bool = False
remote: Optional[str] = None
Expand Down
5 changes: 5 additions & 0 deletions kube_hunter/conf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ def parser_add_arguments(parser):

parser.add_argument("--network-timeout", type=float, default=5.0, help="network operations timeout")

parser.add_argument("--num-worker-threads", type=int, default=800,
help="In some environments the default thread count of 800 is too much. "
"This crashes the process when trying to open more threads."
"In that case feel free to try a lower number, like 400 for example.")


def parse_args(add_args_hook):
"""
Expand Down
3 changes: 2 additions & 1 deletion kube_hunter/core/events/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,5 @@ def free(self):
self.queue.clear()


handler = EventQueue(800)
config = get_config()
handler = EventQueue(config.num_worker_threads)

0 comments on commit 6c4ad4f

Please sign in to comment.