We could add a classmethod to the CustomResourceDefinition object classes which takes a dataclass and returns an instance of the CRD. This classmethod could follow a similar interface to new_class to set things like the name, version and the group.
Here's an example of what this could look like using the kr8s sync API.
from dataclasses import dataclass, field
from apischema import schema
from kr8s.objects import CustomResourceDefinition
@dataclass
class MyCustomResourceSpecV1:
foo: str
bar: str
baz: list[str] = field(
default_factory=list,
metadata=schema(
description="List of baz",
unique=False,
),
)
my_crd = CustomResourceDefinition.from_dataclass(
"MyCustomResource.example.com", namespaced=True, v1=MyCustomResourceSpecV1
)
my_crd.create()
The CustomResourceDefinition contains some metadata about the resource such as the name, group, etc and whether it is versioned. It then contains a list of specification versions. The implementation in kubecrd assumes only one version but it would be nice to support multiple. These could be passed as **kwargs as v1 is in the example above, or as a versions= kwarg with a list of dicts to allow configuration of which is served and stored.
This could even be CustomResourceDefinitions implementation of #142 and use the name CustomResourceDefinition.gen(...) instead of CustomResourceDefinition.from_dataclass(...).
We could add a classmethod to the
CustomResourceDefinition
object classes which takes a dataclass and returns an instance of the CRD. This classmethod could follow a similar interface tonew_class
to set things like the name, version and the group.Here's an example of what this could look like using the
kr8s
sync API.The
from_dataclass
classmethod would need to behave similarly tokubecrd.KubeResourceBase.crd_schema_dict()
.The
CustomResourceDefinition
contains some metadata about the resource such as the name, group, etc and whether it is versioned. It then contains a list of specification versions. The implementation inkubecrd
assumes only one version but it would be nice to support multiple. These could be passed as**kwargs
asv1
is in the example above, or as aversions=
kwarg with a list of dicts to allow configuration of which is served and stored.This could even be
CustomResourceDefinition
s implementation of #142 and use the nameCustomResourceDefinition.gen(...)
instead ofCustomResourceDefinition.from_dataclass(...)
.