diff --git a/kube_hunter/__main__.py b/kube_hunter/__main__.py index fb244c8d..9fda8207 100755 --- a/kube_hunter/__main__.py +++ b/kube_hunter/__main__.py @@ -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, diff --git a/kube_hunter/conf/__init__.py b/kube_hunter/conf/__init__.py index a2bf8d8c..334a6ad1 100644 --- a/kube_hunter/conf/__init__.py +++ b/kube_hunter/conf/__init__.py @@ -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 @@ -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 diff --git a/kube_hunter/conf/parser.py b/kube_hunter/conf/parser.py index 3b3bd023..d5c54300 100644 --- a/kube_hunter/conf/parser.py +++ b/kube_hunter/conf/parser.py @@ -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): """ diff --git a/kube_hunter/core/events/handler.py b/kube_hunter/core/events/handler.py index 8224d0b6..05def730 100644 --- a/kube_hunter/core/events/handler.py +++ b/kube_hunter/core/events/handler.py @@ -366,4 +366,5 @@ def free(self): self.queue.clear() -handler = EventQueue(800) +config = get_config() +handler = EventQueue(config.num_worker_threads)