Skip to content

Commit 56f8257

Browse files
committed
refactor: move the maxLocalTopicBytes validation at topic declaration level
The check was done at the platform-managed-chart level before to have access to the env value. But in fact we already have access to it through self.service_instance_config.env. So we now move back the check at the topic declaration which makes the code simpler since we don't even need to iterate.
1 parent 28ae5c8 commit 56f8257

1 file changed

Lines changed: 17 additions & 24 deletions

File tree

kp_pre_commit_hooks/gitops_values_validation.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import re
22
import sys
33
import textwrap
4-
from collections import defaultdict
54
from dataclasses import dataclass, field
65
from functools import cache, cached_property
76
from pathlib import Path
@@ -437,32 +436,26 @@ def validate_topic_name_compliance(self, value, schema):
437436

438437
def validate_max_local_topic_bytes_compliance(self, value, schema):
439438

440-
topics = value.get("managedResources", {}).get("mskTopics", {})
441-
topic_env = value.get("env")
442-
443-
if not topics:
439+
topic_max_local_bytes = value.get("maxLocalTopicBytes")
440+
if topic_max_local_bytes is None:
444441
return
445442

446-
for topic_config in topics.values():
447-
topic_name = topic_config.get("topicName")
448-
topic_max_local_bytes = topic_config.get("maxLocalTopicBytes")
449-
450-
if topic_max_local_bytes is None:
451-
continue
443+
topic_name = value.get("topicName")
444+
topic_env = self.service_instance_config.env
452445

453-
max_allowed_values = ALLOWED_MAX_LOCAL_TOPIC_BYTES_BY_TOPIC_AND_ENV.get(topic_name, {}).get(topic_env, {}).get("max_limit")
454-
if not max_allowed_values:
455-
yield ValidationError(
456-
"maxLocalTopicBytes can only be used with allowed topics"
457-
f" and topic '{topic_name}' is not allowed in environment '{topic_env}'."
458-
" See https://kpler.atlassian.net/wiki/x/BgGKS for more information."
459-
)
460-
elif topic_max_local_bytes > max_allowed_values:
461-
yield ValidationError(
462-
f"maxLocalTopicBytes exceeds the allowed maximum of {max_allowed_values} "
463-
f"for topic '{topic_name}' in environment '{topic_env}'.\n"
464-
" See https://kpler.atlassian.net/wiki/x/BgGKS for more information."
465-
)
446+
max_allowed_values = ALLOWED_MAX_LOCAL_TOPIC_BYTES_BY_TOPIC_AND_ENV.get(topic_name, {}).get(topic_env, {}).get("max_limit")
447+
if not max_allowed_values:
448+
yield ValidationError(
449+
"maxLocalTopicBytes can only be used with allowed topics"
450+
f" and topic '{topic_name}' is not allowed for environment '{topic_env}'."
451+
" See https://kpler.atlassian.net/wiki/x/BgGKS for more information."
452+
)
453+
elif topic_max_local_bytes > max_allowed_values:
454+
yield ValidationError(
455+
f"maxLocalTopicBytes exceeds the allowed maximum of {max_allowed_values} "
456+
f"for topic '{topic_name}' in environment '{topic_env}'.\n"
457+
" See https://kpler.atlassian.net/wiki/x/BgGKS for more information."
458+
)
466459

467460

468461
def validate_forbidden_environment_variables(self, value, schema):

0 commit comments

Comments
 (0)