Skip to content

occasional KeyError: 'resourceVersion' during a long running list+watch #108

Description

@asteven

I have long running processes using the typical ListWatch pattern.

Occasionally I get this Error:

            |   File "lightkube/core/generic_client.py", line 425, in watch
            |     yield wd.process_one_line(line)
            |           ^^^^^^^^^^^^^^^^^^^^^^^^^
            |   File "lightkube/core/generic_client.py", line 86, in process_one_line
            |     self._version = obj["metadata"]["resourceVersion"]
            |                     ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
            | KeyError: 'resourceVersion'
            +------------------------------------

Line numbers are slightly off as I added some debug information before.

The problem is that the API server responds to this request:

BasicRequest(method='GET',
             url='api/v1/namespaces/default/pods',
             response_type=<class 'lightkube.resources.core_v1.Pod'>,
             params={'resourceVersion': '464635228', 'watch': 'true'},
             data=None,
             headers=None)

With this response line:

{'object': {'apiVersion': 'v1',
            'code': 410,
            'kind': 'Status',
            'message': 'too old resource version: 464635228 (464639593)',
            'metadata': {},
            'reason': 'Expired',
            'status': 'Failure'},
 'type': 'ERROR'}

which results in this obj dict:

{'apiVersion': 'v1',
 'code': 410,
 'kind': 'Status',
 'message': 'too old resource version: 464635228 (464639593)',
 'metadata': {},
 'reason': 'Expired',
 'status': 'Failure'}

which does not have the 'resourceVersion' key.

I guess lightkube should handle the Status object here explicitly and raise an ApiError instead of letting the KeyError through?
Other ideas or requirements on how to address this?
Are you willing to accept a patch to fix that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions