Skip to content

Commit 621bc07

Browse files
Merge pull request #36 from Kpler/chore/add-exceptions-for-non-compliant-gitops-service-name
chore: add service name length exceptions for existing services
2 parents 7659672 + 0e97ced commit 621bc07

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

kp_pre_commit_hooks/gitops-values-validation.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ def sync_values_files_schema_header_version(self):
206206

207207
class ServiceInstanceConfigValidator:
208208

209+
IGNORED_VALIDATION_ERRORS = {
210+
# These 2 service names are longer than the maximum allowed (36 characters)
211+
# but we ignore these errors as these services were created before the rule was in place
212+
"$.platform-managed-chart.serviceName": [
213+
"earth-observation-product-catalog-api",
214+
"stream-merge-and-apply-matches-export-bol",
215+
]
216+
}
217+
209218
def __init__(self, service_instance_config: ServiceInstanceConfig):
210219
self.service_instance_config = service_instance_config
211220

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

219228
def validate_configuration(self) -> Sequence[Union[ValidationError, SchemaValidationError]]:
220229
try:
221-
validation_errors = list(self.validator.iter_errors((self.service_instance_config.configuration)))
230+
validation_errors = list(
231+
error
232+
for error in self.validator.iter_errors((self.service_instance_config.configuration))
233+
if not self.is_ignored_error(error)
234+
)
222235
schema_validation_errors = list(self.iter_schema_validation_errors())
223236
return validation_errors + schema_validation_errors
224237

@@ -241,6 +254,9 @@ def iter_schema_validation_errors(self) -> Iterator[SchemaValidationError]:
241254
hint="This pre-commit hook will auto-fix this issue. Please commit the values files changes.",
242255
)
243256

257+
def is_ignored_error(self, error: ValidationError):
258+
return self.IGNORED_VALIDATION_ERRORS[error.json_path] == error.instance
259+
244260
def validate_additional_checks(self, validator, additional_checks, value, schema):
245261
for check in additional_checks:
246262
if check_method := getattr(self, f"validate_{camel_to_snake(check)}", None):

0 commit comments

Comments
 (0)