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

Cannot get CRD #325

Closed
matteyeux opened this issue Mar 8, 2024 · 5 comments
Closed

Cannot get CRD #325

matteyeux opened this issue Mar 8, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@matteyeux
Copy link

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

@matteyeux matteyeux added the bug Something isn't working label Mar 8, 2024
@jacobtomlinson
Copy link
Member

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)

@matteyeux
Copy link
Author

Not sure what you want, the yaml manifest of the CRD object ?

@jacobtomlinson
Copy link
Member

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

@matteyeux
Copy link
Author

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>]

@jacobtomlinson
Copy link
Member

No worries. I've raised #328 to add that documentation link to the exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants