Skip to content

Commit

Permalink
chore: parallelize gitops pre-commit check for faster execution
Browse files Browse the repository at this point in the history
  • Loading branch information
yannrouillard committed Apr 5, 2024
1 parent 48567be commit 8c15efc
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions kp_pre_commit_hooks/gitops-values-validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import re
import sys
import textwrap
from concurrent.futures import ProcessPoolExecutor as WorkerPool
from dataclasses import dataclass, field
from functools import cache, cached_property
from pathlib import Path
Expand Down Expand Up @@ -336,17 +337,23 @@ def display_errors(
# Main code
###############################################################################


def validate_service_instance_config(service_instance_config):
validator = ServiceInstanceConfigValidator(service_instance_config)
return service_instance_config, validator.validate_configuration()


if __name__ == "__main__":
gitops_path = Path(sys.argv[1]) if len(sys.argv) >= 2 else Path.cwd()
gitops_repository = GitOpsRepository(gitops_path)

try:
errors_found = False
for service_instance_config in gitops_repository.iter_service_instances_config():
print(f"Checking {service_instance_config} ", end="")

validator = ServiceInstanceConfigValidator(service_instance_config)
errors = validator.validate_configuration()
worker_pool = WorkerPool(max_workers=10)
service_instances_config_iter = gitops_repository.iter_service_instances_config()
for service_instance_config, errors in worker_pool.map(validate_service_instance_config, service_instances_config_iter):
print(f"Checking {service_instance_config} ", end="")
if not errors:
print(green("PASSED"))
else:
Expand All @@ -365,3 +372,6 @@ def display_errors(
f" More info at {TWINGATE_DOC_URL}\n\n"
)
sys.exit(1)

finally:
worker_pool.shutdown()

0 comments on commit 8c15efc

Please sign in to comment.