From 56457498c2dd17e1b5a09862b5bdfa80651c7aa3 Mon Sep 17 00:00:00 2001 From: rnetser Date: Thu, 25 Jul 2024 20:43:56 +0300 Subject: [PATCH] fix comment --- scripts/resource/class_generator.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/resource/class_generator.py b/scripts/resource/class_generator.py index 8caff9b0b7..9d4c5086d9 100644 --- a/scripts/resource/class_generator.py +++ b/scripts/resource/class_generator.py @@ -288,20 +288,24 @@ def parse_explain( LOGGER.debug(f"\n{yaml.dump(resource_dict)}") - if (api_group_real_name := resource_dict.get("GROUP")) or ( - api_group_real_name := resource_dict["VERSION"].split("/")[0] - ): + api_group_real_name = resource_dict.get("GROUP") + # If API Group is not present in resource, try to get it from VERSION + if not api_group_real_name and (api_group_match := re.match(r"(\w+)/", resource_dict["VERSION"])): + api_group_real_name = api_group_match.group(1) # noqa FCN001 + + if api_group_real_name: api_group_for_resource_api_group = api_group_real_name.upper().replace(".", "_") + resource_dict["GROUP"] = api_group_for_resource_api_group missing_api_group_in_resource: bool = not hasattr(Resource.ApiGroup, api_group_for_resource_api_group) if missing_api_group_in_resource: LOGGER.warning( f"Missing API Group in Resource\n" - f"Please add `Resource.ApiGroup.{api_group_real_name} = {api_group_real_name}` " + f"Please add `Resource.ApiGroup.{api_group_for_resource_api_group} = {api_group_real_name}` " "manually into ocp_resources/resource.py under Resource class > ApiGroup class." ) - if not api_group_real_name: + else: api_version_for_resource_api_version = resource_dict["VERSION"].upper() missing_api_version_in_resource: bool = not hasattr(Resource.ApiVersion, api_version_for_resource_api_version)