gtsystem / lightkube

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

Problems with the list method and custom resources #25

Closed stonepreston closed 2 years ago

stonepreston commented 2 years ago

I'm experiencing some problems using the list method with custom resources. I will lay out a minimal working example below using the example from the k8s docs

First create the CRD defined here

kubectl apply -f resourcedefinition.yaml

Then create a custom object defined here

kubectl apply -f my-crontab.yaml

Verify it exists:

 kubectl get crontab

I can then use the get method on this newly created object just fine:

cron_resource = create_namespaced_resource(group="stable.example.com",
                                               version="v1",
                                               kind="CronTab",
                                               plural="crontabs",
                                               verbs=None)
cron = client.get(cron_resource, name="my-new-cron-object", namespace="default")
print(cron)

However if I try to list objects of this resource:

cron_list = client.list(cron_resource, namespace="default")
for obj in cron_list:
    print(obj)

Then I end up getting an infinite loop, when there should just be one object.

Another issue is when no objects of the requested resource exist:

cron_list = client.list(cron_resource, namespace="nonexistent-namespace")
for obj in cron_list:
    print(obj)

Then the loop just hangs.

The list method works fine whenever its used with a lightkube resource:

cm_list = client.list(ConfigMap, namespace="default")
    for obj in cm_list:
        print(obj)

so it seems to be specific to custom resources. Let me know if you need any other information from me. Being able to list custom resources is very important to me right now and Id love to help get to the bottom of it.

gtsystem commented 2 years ago

Hi, it seems that the list response for custom resources differ from what is returned for standard resources. I adapted the check to address that. Please take a look at #26.