Remove unneeded fields from spec

This commit is contained in:
Tobias Kunze 2025-03-28 13:46:55 +01:00
parent 6e644dfe44
commit 2f769e0e2e

View file

@ -28,12 +28,15 @@ def generate_django_model(schema, group, version, kind):
""" """
Generates a virtual Django model from a Kubernetes CRD's OpenAPI v3 schema. Generates a virtual Django model from a Kubernetes CRD's OpenAPI v3 schema.
""" """
spec = schema["properties"].get("spec") or {} # We always need these three fields to know our own name and our full namespace
# defaults = {"apiVersion": f"{group}/{version}", "kind": kind}
model_fields = {"__module__": "crd_models"} model_fields = {"__module__": "crd_models"}
for field_name in ("name", "organization", "context"): for field_name in ("name", "organization", "context"):
model_fields[field_name] = duplicate_field(field_name, ServiceInstance) model_fields[field_name] = duplicate_field(field_name, ServiceInstance)
# All other fields are generated from the schema, except for the
# resourceRef object
spec = schema["properties"].get("spec") or {}
spec["properties"].pop("resourceRef", None)
model_fields.update(build_object_fields(spec, "spec")) model_fields.update(build_object_fields(spec, "spec"))
meta_class = type("Meta", (), {"app_label": "crd_models"}) meta_class = type("Meta", (), {"app_label": "crd_models"})