We can use the CustomResourceDefinition objects to create/update/delete Custom Resource Definitions. But if we want to create the Custom Resources themselves we need to call new_class() with the name of the CRD and some options to generate a class that we can use to create resources.
It would be nice if CustomResourceDefinition had a utility method to do this for us automatically.
Now we have a CRD for shirts.stable.example.com/v1 we might want to make a new Shirt resource. Currently we would need to use new_class() and pass a lot of the same information that we passed to the CRD.
from kr8s.objects import new_class
Shirt = new_class("shirts.stable.example.com/v1", namespaced=True) # If Shirt was scalable this would be even more complex
Instead we could add a method to CustomResourceDefinition to do this for us.
# Create an object class for `shirts.stable.example.com/v1`
Shirt = shirts_crd.as_class(version="v1") # The version could be optional and just use the first as a default
Alternatively we could update new_class() to accept a CRD.
from kr8s.objects import new_class
Shirt = new_class(shirts_crd) # Would need to think about how to handle which schema version is used
We can use the
CustomResourceDefinition
objects to create/update/delete Custom Resource Definitions. But if we want to create the Custom Resources themselves we need to callnew_class()
with the name of the CRD and some options to generate a class that we can use to create resources.It would be nice if
CustomResourceDefinition
had a utility method to do this for us automatically.For example if we start by making a new CRD.
Now we have a CRD for
shirts.stable.example.com/v1
we might want to make a new Shirt resource. Currently we would need to usenew_class()
and pass a lot of the same information that we passed to the CRD.Instead we could add a method to
CustomResourceDefinition
to do this for us.Alternatively we could update
new_class()
to accept a CRD.Then we can finally define and create a Shirt.