Skip to content

ResourcesList drops list metadata (resourceVersion) — breaks watch continuations #498

@loks0n

Description

@loks0n

Summary

ResourcesList currently extends Collection with no additional state, so the resourceVersion from the Kubernetes list response is silently discarded. This means callers cannot use the list's resourceVersion to resume a watch from a known point.

Current behaviour

makeRequest in MakesHttpCalls builds the list as:

return new ResourcesList($results);

The resourceVersion in the API response's metadata block (e.g. "metadata": { "resourceVersion": "12345" }) is never stored.

Expected behaviour

After calling e.g. $cluster->getAllPods(), callers should be able to do:

$list = $cluster->getAllPods();
$rv   = $list->getResourceVersion(); // "12345"

// Resume watch from exactly this point — no missed or duplicate events
$pod->watchAll(function ($type, $pod) { ... }, ['resourceVersion' => $rv]);

This is the standard Kubernetes watch pattern documented in the Efficient detection of changes guide.

Proposed fix

Extend ResourcesList to carry the metadata and expose getResourceVersion():

class ResourcesList extends Collection
{
    protected ?string $resourceVersion = null;

    public static function fromResponse(array $items, array $metadata): static
    {
        $list = new static($items);
        $list->resourceVersion = $metadata['resourceVersion'] ?? null;
        return $list;
    }

    public function getResourceVersion(): ?string
    {
        return $this->resourceVersion;
    }
}

And in MakesHttpCalls::makeRequest:

return ResourcesList::fromResponse($results, $json['metadata'] ?? []);

This is a non-breaking additive change, so existing code that ignores the return value is unaffected. Happy to open a PR if the approach looks good.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions