Skip to content

Commit 81195ee

Browse files
authored
Merge pull request #1377 from projectsyn/feat/catalog-compile-processes
Introduce new parameter `--processes` for `catalog compile`
2 parents 214949e + acc438a commit 81195ee

4 files changed

Lines changed: 33 additions & 1 deletion

File tree

commodore/cli/catalog.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ def _complete_clusters(ctx: click.Context, _, incomplete: str) -> list[str]:
164164
+ "uncommitted changes in tracked files count as local changes."
165165
+ "The parameter has no effect if `--local` is given.",
166166
)
167+
@click.option(
168+
"--processes",
169+
type=int,
170+
default=0,
171+
show_default=True,
172+
help="Control the number of worker processes that are spawned when compiling the catalog. "
173+
+ "A value of `0` will set the number of worker processes to the number of CPUs available "
174+
+ "on the system. Note that this parameter doesn't adjust the number of threads used by "
175+
+ "reclass-rs.",
176+
)
167177
@options.verbosity
168178
@options.pass_config
169179
# pylint: disable=too-many-arguments
@@ -187,6 +197,7 @@ def compile_catalog(
187197
migration,
188198
dynamic_fact: str,
189199
force: bool,
200+
processes: int,
190201
):
191202
config.update_verbosity(verbose)
192203
config.api_url = api_url
@@ -204,6 +215,7 @@ def compile_catalog(
204215
config.fetch_dependencies = fetch_dependencies
205216
config.dynamic_facts = parse_dynamic_facts_from_cli(dynamic_fact)
206217
config.force = not config.local and force
218+
config.processes = processes
207219

208220
if config.push and (
209221
config.global_repo_revision_override or config.tenant_repo_revision_override

commodore/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class Config:
103103
_request_timeout: int
104104
_managed_tools: dict[str, str]
105105
_api_token: Optional[str]
106+
_processes: int
106107

107108
oidc_client: Optional[str]
108109
oidc_discovery_url: Optional[str]
@@ -144,6 +145,7 @@ def __init__(
144145
self._github_token = None
145146
self._request_timeout = 5
146147
self._managed_tools = {}
148+
self._processes = 0
147149

148150
@property
149151
def verbose(self):
@@ -327,6 +329,14 @@ def managed_tools(self) -> dict[str, str]:
327329
def managed_tools(self, managed_tools: dict[str, str]):
328330
self._managed_tools = managed_tools
329331

332+
@property
333+
def processes(self) -> int:
334+
return self._processes
335+
336+
@processes.setter
337+
def processes(self, processes: int):
338+
self._processes = processes
339+
330340
@property
331341
def inventory(self):
332342
return self._inventory

commodore/helpers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,10 @@ def kapitan_compile(
251251
refController = RefController(config.refs_dir)
252252
if fake_refs:
253253
refController.register_backend(FakeVaultBackend())
254+
processes: Optional[int] = config.processes
255+
if config.processes == 0:
256+
processes = cpu_count()
257+
254258
click.secho("Compiling catalog...", bold=True)
255259
# workaround the non-modifiable Namespace() default value for cached.args
256260
cached.args.inventory_backend = "reclass-rs"
@@ -261,7 +265,7 @@ def kapitan_compile(
261265
cached.args.verbose = config.trace
262266
cached.args.output_path = output_dir
263267
cached.args.targets = targets
264-
cached.args.parallelism = cpu_count()
268+
cached.args.parallelism = processes
265269
cached.args.labels = None
266270
cached.args.prune = False
267271
cached.args.indent = 2

docs/modules/ROOT/pages/reference/cli.adoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ With `--no-force`, local changes in global, tenant, or dependency checkouts are
129129
Specifying `--force` has no effect if `--local` is given, and is silently ignored.
130130
Defaults to `--no-force`.
131131

132+
*--processes*::
133+
Control the number of worker processes that are spawned when compiling the catalog.
134+
A value of `0` will set the number of worker processes to the number of CPUs available on the system.
135+
Note that this parameter doesn't adjust the number of threads used by reclass-rs.
136+
Defaults to `0`.
137+
132138
*--help*::
133139
Show catalog clean usage and options then exit.
134140

0 commit comments

Comments
 (0)