gtsystem / lightkube

Modern lightweight kubernetes module for python
https://lightkube.readthedocs.io
MIT License
109 stars 13 forks source link

Unable to gather a list of daemonsets #29

Closed addyess closed 2 years ago

addyess commented 2 years ago
from lightkube import Client
from lightkube.models.apps_v1 import DaemonSet

client = Client(namespace="default", field_manager="lightkube")
fetched = list(client.list(DaemonSet, namespace="kube-system"))

this yields a Traceback

Traceback (most recent call last):
  File "/home/user/.tox/unit/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3340, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-6-f1919e43688d>", line 1, in <cell line: 1>
    list(client.list(
  File "/home/user/.tox/unit/lib/python3.9/site-packages/lightkube/core/client.py", line 134, in list
    br = self._client.prepare_request(
  File "/home/user/.tox/unit/lib/python3.9/site-packages/lightkube/core/generic_client.py", line 118, in prepare_request
    api_info = r.api_info(res)
  File "/home/user/.tox/unit/lib/python3.9/site-packages/lightkube/core/resource.py", line 25, in api_info
    return res._api_info
AttributeError: type object 'DaemonSet' has no attribute '_api_info'

Surely this is an obvious mistake on my part?

addyess commented 2 years ago

YEP! Here's the right solution. Things i've learned :)

from lightkube import Client
from lightkube.resources.apps_v1 import DaemonSet

client = Client(namespace="default", field_manager="lightkube")
fetched = list(client.list(DaemonSet, namespace="kube-system"))