Skip to content

Commit 0244547

Browse files
authored
fix(class-generator): prevent duplicate class generation for resources with multiple API groups (#2495)
1 parent aff7c4d commit 0244547

File tree

6 files changed

+11267
-6918
lines changed

6 files changed

+11267
-6918
lines changed

class_generator/parsers/explain_parser.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ def parse_explain(kind: str) -> list[dict[str, Any]]:
4646
for schema in _kinds_schema:
4747
gvk_list = schema.get("x-kubernetes-group-version-kind", [])
4848
if gvk_list:
49-
group = gvk_list[0].get("group", "")
49+
# Prefer non-empty groups over empty groups to avoid duplicates
50+
preferred_gvk = next((gvk for gvk in gvk_list if gvk.get("group")), gvk_list[0])
51+
group = preferred_gvk.get("group", "")
5052
if group not in schemas_by_group:
5153
schemas_by_group[group] = []
5254
schemas_by_group[group].append(schema)
@@ -60,17 +62,22 @@ def parse_explain(kind: str) -> list[dict[str, Any]]:
6062
for schema in group_schemas:
6163
gvk_list = schema.get("x-kubernetes-group-version-kind", [])
6264
if gvk_list:
63-
version = gvk_list[0].get("version", "")
65+
# Use same preference logic as grouping
66+
preferred_gvk = next((gvk for gvk in gvk_list if gvk.get("group")), gvk_list[0])
67+
version = preferred_gvk.get("version", "")
6468
versions.append(version)
6569

6670
latest_version = get_latest_version(versions=versions)
6771

6872
# Add only the schema with the latest version
6973
for schema in group_schemas:
7074
gvk_list = schema.get("x-kubernetes-group-version-kind", [])
71-
if gvk_list and gvk_list[0].get("version") == latest_version:
72-
filtered_schemas.append(schema)
73-
break
75+
if gvk_list:
76+
# Use same preference logic as grouping
77+
preferred_gvk = next((gvk for gvk in gvk_list if gvk.get("group")), gvk_list[0])
78+
if preferred_gvk.get("version") == latest_version:
79+
filtered_schemas.append(schema)
80+
break
7481
else:
7582
# Single version in this group
7683
filtered_schemas.extend(group_schemas)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.32.6
1+
v1.33.2
20.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)