Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for kubecrd style dataclasses for creating CRDs #315

Open
2 tasks
jacobtomlinson opened this issue Feb 20, 2024 · 1 comment
Open
2 tasks

Add support for kubecrd style dataclasses for creating CRDs #315

jacobtomlinson opened this issue Feb 20, 2024 · 1 comment
Labels
enhancement New feature or request good second issue Clearly described and reproducible, but solution less clear than "good first issue" help wanted Extra attention is needed

Comments

@jacobtomlinson
Copy link
Member

jacobtomlinson commented Feb 20, 2024

Which project are you requesting an enhancement for?

kr8s

What do you need?

The kubecrd project allows you to define a Custom Resource Definition (CRD) as a Python dataclass and then export the YAML.

Today I noticed a project where someone is using kubecrd with kr8s and they are creating a custom kr8s API object from the kubecrd dataclass.

Something like this

from dataclasses import dataclass, field
from kubecrd import schemabase
from apischema import schema
from kr8s.asyncio.objects import APIObject


@dataclass()
class MyCustomResourceDefinition(schemabase.KubeResourceBase):
    __group__ = "example.com"
    __version__ = "v1"

    foo: str
    bar: str
    baz: list[str] = field(
        default_factory=list,
        metadata=schema(
            description="List of baz",
            unique=False,
        ),
    )


class MyCustomResourceObject(APIObject):
    version = f"{MyCustomResourceDefinition.__group__}/{MyCustomResourceDefinition.__version__}"
    kind = MyCustomResourceDefinition.__name__.lower()
    singular = MyCustomResourceDefinition.singular()
    plural = MyCustomResourceDefinition.plural()
    endpoint = MyCustomResourceDefinition.plural()
    namespaced = True

I wonder if there is anything we could do in kr8s to make this more seamless?

Tasks

  1. enhancement kr8s
  2. enhancement kr8s
@jacobtomlinson jacobtomlinson added the enhancement New feature or request label Feb 20, 2024
@jacobtomlinson jacobtomlinson added the help wanted Extra attention is needed label Mar 13, 2024
@jacobtomlinson
Copy link
Member Author

I spent some time thinking about this today.

Firstly it looks like kubecrd is unmaintained, there has been no activity on the project for a couple of years and issues/PRs are not being responded to. Also looking into the code it seems pretty lightweight and most of the work is being done by apischema to convert the dataclass to an OpenAPI schema.

Thinking about the core goal here there seem to be two things we want to achieve:

  • Define a Custom Resource Definition version spec in Python as a dataclass and create/update/delete the CRD.
  • Create a kr8s object class based on APIObject to enable creating/updating/deleting of those Custom Resources

Thinking about it this way this could be achieved in two independent stages so I'm going to open to separate issues to track each one.

@jacobtomlinson jacobtomlinson changed the title Add support for kubecrd interoperability Add support for kubecrd style dataclasses for creating CRDs Jul 31, 2024
@jacobtomlinson jacobtomlinson added the good second issue Clearly described and reproducible, but solution less clear than "good first issue" label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good second issue Clearly described and reproducible, but solution less clear than "good first issue" help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant