From 431588c45eb81ba63fe9b497b50375b70c7cd5fb Mon Sep 17 00:00:00 2001 From: vincent Date: Fri, 20 Jun 2025 10:25:37 +0800 Subject: [PATCH 1/5] chore: add minimal chart version requirement --- .../gitops_values_validation.py | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/kp_pre_commit_hooks/gitops_values_validation.py b/kp_pre_commit_hooks/gitops_values_validation.py index 7f1bf9e..44fce8a 100755 --- a/kp_pre_commit_hooks/gitops_values_validation.py +++ b/kp_pre_commit_hooks/gitops_values_validation.py @@ -38,6 +38,9 @@ TWINGATE_DOC_URL = "https://kpler.atlassian.net/wiki/spaces/KSD/pages/243562083/Install+and+configure+the+Twingate+VPN+client" +MIN_PLATFORM_MANAGED_CHART_VERSION_STR = "0.1.100" +MIN_PLATFORM_MANAGED_CHART_VERSION = semver.VersionInfo.parse(MIN_PLATFORM_MANAGED_CHART_VERSION_STR) + # Environment variables that should not be overridden FORBIDDEN_ENVIRONMENT_VARIABLES = { "KAFKA_APPLICATION_ID": """KAFKA_APPLICATION_ID is automatically set in your container and should not be overridden. @@ -385,7 +388,8 @@ def validate_configuration(self) -> Sequence[Union[ValidationError, SchemaValida ] validation_errors = [error for error in raw_validation_errors if not self.is_ignored_error(error)] schema_validation_errors = list(self.iter_schema_validation_errors()) - return validation_errors + schema_validation_errors + chart_validation_errors = list(self.iter_chart_validation_errors()) + return validation_errors + schema_validation_errors + chart_validation_errors except MissingSchema as error: version = self.service_instance_config.helm_chart.platform_managed_chart_version @@ -407,6 +411,36 @@ def iter_schema_validation_errors(self) -> Iterator[SchemaValidationError]: hint="This pre-commit hook will auto-fix this issue. Please commit the values files changes.", ) + def iter_chart_validation_errors(self) -> Iterator[SchemaValidationError]: + """Validate Chart.yaml and Chart-dev.yaml for minimum platform-managed-chart version.""" + chart_files_to_check = ["Chart.yaml", "Chart-dev.yaml"] + for chart_filename in chart_files_to_check: + chart_file_path = self.service_instance_config.path / chart_filename + if not chart_file_path.exists(): + continue + + helm_chart = HelmChart.from_chart_file(chart_file_path) + chart_version_str = helm_chart.platform_managed_chart_version + if chart_version_str: + try: + # To treat pre-release versions like '0.1.169-pr123' as '0.1.169', + # we strip the pre-release part before parsing. + core_version_str = chart_version_str.split('-')[0] + chart_version = semver.VersionInfo.parse(core_version_str) + if chart_version.compare(MIN_PLATFORM_MANAGED_CHART_VERSION) < 0: + yield SchemaValidationError( + f"platform-managed-chart version {chart_version_str} is far behind the latest version", + location=f"file {chart_file_path.relative_to(self.service_instance_config.gitops_repository.gitops_path)}", + hint="Please upgrade the platform-managed-chart dependency to the latest version." + ) + except ValueError: + # Not a valid semver string. + yield SchemaValidationError( + f"platform-managed-chart version '{chart_version_str}' is not a valid semantic version.", + location=f"file {chart_file_path.relative_to(self.service_instance_config.gitops_repository.gitops_path)}", + hint="Please use a valid semver version for platform-managed-chart." + ) + def enrich_error_message(self, error: ValidationError) -> ValidationError: if error.message.endswith("is too long") and isinstance(error.schema, Mapping) and error.schema.get("maxLength"): error.message += f', the maximum length is {error.schema["maxLength"]}' From 096b2385b7b8989969f7b333bfbfb34a71700cfc Mon Sep 17 00:00:00 2001 From: vincent Date: Fri, 20 Jun 2025 10:41:57 +0800 Subject: [PATCH 2/5] chore: omit name and version in chart-dev --- kp_pre_commit_hooks/gitops_values_validation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kp_pre_commit_hooks/gitops_values_validation.py b/kp_pre_commit_hooks/gitops_values_validation.py index 44fce8a..9d8ee41 100755 --- a/kp_pre_commit_hooks/gitops_values_validation.py +++ b/kp_pre_commit_hooks/gitops_values_validation.py @@ -164,8 +164,8 @@ def platform_managed_chart_version(self) -> Optional[str]: def from_chart_file(chart_file: Path): chart = cast(dict, yaml.safe_load(chart_file.read_text())) return HelmChart( - name=chart["name"], - version=chart["version"], + name=chart.get("name", ""), + version=chart.get("version", ""), dependencies=[HelmChart(dep["name"], dep["version"]) for dep in chart.get("dependencies", [])], ) From fd4a84eac74cb40d260e969f18dbb52e3373c73c Mon Sep 17 00:00:00 2001 From: vincent Date: Fri, 20 Jun 2025 10:56:18 +0800 Subject: [PATCH 3/5] add exception for tab --- kp_pre_commit_hooks/gitops_values_validation.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kp_pre_commit_hooks/gitops_values_validation.py b/kp_pre_commit_hooks/gitops_values_validation.py index 9d8ee41..0c74d27 100755 --- a/kp_pre_commit_hooks/gitops_values_validation.py +++ b/kp_pre_commit_hooks/gitops_values_validation.py @@ -15,6 +15,7 @@ from jsonschema_specifications import REGISTRY from referencing import Registry, Resource from termcolor import colored +from yaml.scanner import ScannerError # Disable insecure request warnings urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) @@ -419,7 +420,16 @@ def iter_chart_validation_errors(self) -> Iterator[SchemaValidationError]: if not chart_file_path.exists(): continue - helm_chart = HelmChart.from_chart_file(chart_file_path) + try: + helm_chart = HelmChart.from_chart_file(chart_file_path) + except ScannerError as e: + yield SchemaValidationError( + f"Invalid YAML: {e.problem}", + location=f"file {chart_file_path.relative_to(self.service_instance_config.gitops_repository.gitops_path)} at line {e.problem_mark.line + 1}", + hint="YAML does not allow tab characters. Please use spaces for indentation." + ) + continue # Skip further checks on this broken file + chart_version_str = helm_chart.platform_managed_chart_version if chart_version_str: try: From 34a0fd681675d2b7315cfcf9adb0fd5412dee3e5 Mon Sep 17 00:00:00 2001 From: vincent Date: Fri, 20 Jun 2025 11:05:40 +0800 Subject: [PATCH 4/5] revert --- kp_pre_commit_hooks/gitops_values_validation.py | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/kp_pre_commit_hooks/gitops_values_validation.py b/kp_pre_commit_hooks/gitops_values_validation.py index 0c74d27..5ffb75f 100755 --- a/kp_pre_commit_hooks/gitops_values_validation.py +++ b/kp_pre_commit_hooks/gitops_values_validation.py @@ -15,7 +15,6 @@ from jsonschema_specifications import REGISTRY from referencing import Registry, Resource from termcolor import colored -from yaml.scanner import ScannerError # Disable insecure request warnings urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) @@ -420,15 +419,7 @@ def iter_chart_validation_errors(self) -> Iterator[SchemaValidationError]: if not chart_file_path.exists(): continue - try: - helm_chart = HelmChart.from_chart_file(chart_file_path) - except ScannerError as e: - yield SchemaValidationError( - f"Invalid YAML: {e.problem}", - location=f"file {chart_file_path.relative_to(self.service_instance_config.gitops_repository.gitops_path)} at line {e.problem_mark.line + 1}", - hint="YAML does not allow tab characters. Please use spaces for indentation." - ) - continue # Skip further checks on this broken file + helm_chart = HelmChart.from_chart_file(chart_file_path) chart_version_str = helm_chart.platform_managed_chart_version if chart_version_str: From c3a349d4c2932ad31f9f44021ca2580ffbd83c6a Mon Sep 17 00:00:00 2001 From: Vincent Liu <128127889+vl-kp@users.noreply.github.com> Date: Wed, 15 Oct 2025 12:43:55 +0800 Subject: [PATCH 5/5] Update gitops_values_validation.py --- kp_pre_commit_hooks/gitops_values_validation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kp_pre_commit_hooks/gitops_values_validation.py b/kp_pre_commit_hooks/gitops_values_validation.py index d93689d..d7ecd1a 100755 --- a/kp_pre_commit_hooks/gitops_values_validation.py +++ b/kp_pre_commit_hooks/gitops_values_validation.py @@ -199,9 +199,9 @@ def from_chart_file(chart_file: Path, env: Optional[str] = None): merged = deep_merge(*charts_data) return HelmChart( - name=chart.get("name", ""), - version=chart.get("version", ""), - dependencies=[HelmChart(dep["name"], dep["version"]) for dep in chart.get("dependencies", [])], + name=merged.get("name", ""), + version=merged.get("version", ""), + dependencies=[HelmChart(dep["name"], dep["version"]) for dep in merged.get("dependencies", [])], )