Migrate CRD generation to Python dataclasses
- Dominant language
- Python
- Stars
- 324
- Forks
- 157
- PR merge metrics
- No merged PRs in 30d
Description
The Dask operator has a number of Custom Resource Definitions. Many of these definitions have specs from other resources nested within them. For example the `scheduler` and `worker` parameters within `DaskCluster` have nested `PodSpec` specifications because these will ultimately be created as Pods by the controller.
https://github.com/dask/dask-kubernetes/blob/734d001836fad228cca809093feec3d07cd634a6/dask_kubernetes/operator/customresources/templates.yaml#L36
To generate the Custom Resource Definitions that we ship in the [Dask Kubernetes Operator Helm Chart](http://helm.dask.org/#dask-kubernetes-operator) we have a [whole pile of yaml](https://github.com/dask/dask-kubernetes/tree/main/dask_kubernetes/operator/customresources) that contains the definition templates. Then we have a [`pre-commit` hook](https://github.com/dask/dask-kubernetes/blob/734d001836fad228cca809093feec3d07cd634a6/ci/pre-commit-crd.py) that runs [`k8s-crd-resolver`](https://github.com/elemental-lf/k8s-crd-resolver) which renders the templates into the [helm chart crds directory](https://github.com/dask/dask-kubernetes/tree/main/dask_kubernetes/operator/deployment/helm/dask-kubernetes-operator/crds).
I'm conscious that `k8s-crd-resolver` appears to be unmaintained and has not had new schema definitions introduced since Kubernetes `1.25` which went EOL in October 2023. I also opened https://github.com/elemental-lf/k8s-crd-resolver/issues/6 over a year ago which has not had any response.
It could be interesting to explore migrating the CRD generation to Python Dataclasses instead of YAML templates. There is a library that can do this called [`kubecrd`](https://github.com/maxking/kubecrd) but this also appears to be unmaintained. It also does not support having multiple version schemas and so would stop us from impementing #753.
As a response to this I'm exploring generating Custom Resource Definition objects in `kr8s` from dataclasses (https://github.com/kr8s-org/kr8s/issues/456). Putting this code in `kr8s` will help ensure it is tested and maintained. It would also allow you to create multiple dataclasses, one for each version of the schema.
Contributor guide
Assessment
This issue has not been assessed yet.