Cannot get CRD
Closed this issue · 5 comments
Which project are you reporting a bug for?
kr8s
What happened?
Hello,
I am trying to get a CRD with kr8s.get
, but it does not detect my CRD:
>>> kr8s.get("OpenSearchCluster", namespace="my-namespace")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/mathieu/env/lib/python3.10/site-packages/kr8s/__init__.py", line 93, in get
return _run_sync(partial(_get, _asyncio=False))(*args, **kwargs)
File "/home/mathieu/env/lib/python3.10/site-packages/kr8s/_io.py", line 75, in wrapped
return portal.call(wrapped)
File "/home/mathieu/env/lib/python3.10/site-packages/kr8s/_io.py", line 50, in call
return self._portal.call(func, *args, **kwargs)
File "/home/mathieu/env/lib/python3.10/site-packages/anyio/from_thread.py", line 288, in call
return cast(T_Retval, self.start_task_soon(func, *args).result())
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 458, in result
return self.__get_result()
File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
raise self._exception
File "/home/mathieu/env/lib/python3.10/site-packages/anyio/from_thread.py", line 217, in _call_func
retval = await retval_or_awaitable
File "/home/mathieu/env/lib/python3.10/site-packages/kr8s/asyncio/_helpers.py", line 65, in get
return await api._get(
File "/home/mathieu/env/lib/python3.10/site-packages/kr8s/_api.py", line 370, in _get
async with self._get_kind(
File "/usr/lib/python3.10/contextlib.py", line 199, in __aenter__
return await anext(self.gen)
File "/home/mathieu/env/lib/python3.10/site-packages/kr8s/_api.py", line 297, in _get_kind
obj_cls = get_class(kind, _asyncio=self._asyncio)
File "/home/mathieu/env/lib/python3.10/site-packages/kr8s/_objects.py", line 1594, in get_class
raise KeyError(f"No object registered for {kind}{'.' + group if group else ''}")
KeyError: 'No object registered for opensearchcluster'
I can get it with kubectl
:
k get opensearchclusters -n my-namespace
NAME AGE
opensearch 31m
And when listing CRDs with kr8s.objects.CustomResourceDefinition.list()
I can see the CRD : in the list : <CustomResourceDefinition opensearchclusters.opensearch.opster.io>
.
Did I do something wrong ?
I also tried to get an istiogateway, which is another CRD, but same issue.
Anything else?
No response
Could you share how you're defining the object for your CRD? I wonder if you're running into the same issue described here #199 (comment)
Not sure what you want, the yaml manifest of the CRD object ?
You need to first define a class for your custom object. Have you done this?
https://docs.kr8s.org/en/latest/object.html#extending-the-objects-api
Thank you for pointing the doc. I was using it wrong.
This works
>>> import kr8s; from kr8s.objects import new_class; obj = new_class(kind="OpenSearchCluster", version="opensearch.opster.io/v1", namespaced=True, asyncio=False)
>>> kr8s.get("OpenSearchCluster")
[<OpenSearchCluster opensearch>]
No worries. I've raised #328 to add that documentation link to the exception.