gtsystem / lightkube

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

Resources fetched via list operation have apiVersion and kind fields set to None #65

Closed benfiola closed 3 months ago

benfiola commented 3 months ago

Hey there!

When I list resources using the lightkube async client, the resources that are returned are missing their apiVersion and kind fields.

This might be because the underlying kubernetes list apis return *List resources whose members actually don't have these fields populated - but I figure I'd let you know to see how you'd want to proceed.

Environment

Example

import asyncio
import pathlib

import lightkube.config.kubeconfig
import lightkube.core.async_client
from lightkube.resources.core_v1 import Service

async def main():
    config = lightkube.config.kubeconfig.KubeConfig.from_file(
        pathlib.Path("/root/.kube/config")
    )
    kube_client = lightkube.core.async_client.AsyncClient(config)
    async for item in kube_client.list(Service):
        assert item.apiVersion is None
        assert item.kind is None

if __name__ == "__main__":
    asyncio.run(main())
gtsystem commented 3 months ago

I'm not sure that fixing the issue in all the clients is the way to go, it would be better to have this fixed in kubernetes itself (kubernetes/kubernetes#3030). However if this is blocking you in some way, I guess it's fine to have a temporary fix in place.

benfiola commented 3 months ago

Yeah, it's probably something that should be handled by kubernetes - but it looks like the various PRs that have been opened to address it never landed. It's unclear why there's no momentum behind landing those changes (could be low priority, could be complicated).

Ultimately, this isn't blocking me (I can always patch in the behavior if I need it on my end) - just felt like trying to tackle the problem after filing the issue. I could see an argument being made for fixing this behavior for those who want to use kind and apiVersion fields to disambiguate between resources in a collection - though they could accomplish the same thing with isinstance checks, too.

benfiola commented 3 months ago

Closing the issue - thanks (again) for the merge!