Skip to content

Commit

Permalink
Merge pull request #36 from Kpler/chore/add-exceptions-for-non-compli…
Browse files Browse the repository at this point in the history
…ant-gitops-service-name

chore: add service name length exceptions for existing services
  • Loading branch information
yannrouillard authored Mar 26, 2024
2 parents 7659672 + 0e97ced commit 621bc07
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion kp_pre_commit_hooks/gitops-values-validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,15 @@ def sync_values_files_schema_header_version(self):

class ServiceInstanceConfigValidator:

IGNORED_VALIDATION_ERRORS = {
# These 2 service names are longer than the maximum allowed (36 characters)
# but we ignore these errors as these services were created before the rule was in place
"$.platform-managed-chart.serviceName": [
"earth-observation-product-catalog-api",
"stream-merge-and-apply-matches-export-bol",
]
}

def __init__(self, service_instance_config: ServiceInstanceConfig):
self.service_instance_config = service_instance_config

Expand All @@ -218,7 +227,11 @@ def validator(self) -> Validator:

def validate_configuration(self) -> Sequence[Union[ValidationError, SchemaValidationError]]:
try:
validation_errors = list(self.validator.iter_errors((self.service_instance_config.configuration)))
validation_errors = list(
error
for error in self.validator.iter_errors((self.service_instance_config.configuration))
if not self.is_ignored_error(error)
)
schema_validation_errors = list(self.iter_schema_validation_errors())
return validation_errors + schema_validation_errors

Expand All @@ -241,6 +254,9 @@ 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 is_ignored_error(self, error: ValidationError):
return self.IGNORED_VALIDATION_ERRORS[error.json_path] == error.instance

def validate_additional_checks(self, validator, additional_checks, value, schema):
for check in additional_checks:
if check_method := getattr(self, f"validate_{camel_to_snake(check)}", None):
Expand Down

0 comments on commit 621bc07

Please sign in to comment.