diff --git a/kr8s/_objects.py b/kr8s/_objects.py index 021eb2a5..096caf80 100644 --- a/kr8s/_objects.py +++ b/kr8s/_objects.py @@ -485,6 +485,10 @@ async def adopt(self, child: APIObject) -> None: """ await child._set_owner(self) + def to_dict(self) -> dict: + """Return a dictionary representation of this object.""" + return self.raw + def to_lightkube(self) -> Any: """Return a lightkube representation of this object.""" try: diff --git a/kr8s/tests/test_objects.py b/kr8s/tests/test_objects.py index 10a6d9d3..57042390 100644 --- a/kr8s/tests/test_objects.py +++ b/kr8s/tests/test_objects.py @@ -720,6 +720,13 @@ async def test_cast_to_from_pykube_ng(example_pod_spec): assert pykube_pod.namespace == example_pod_spec["metadata"]["namespace"] +async def test_to_dict(example_pod_spec): + pod = await Pod(example_pod_spec) + to_spec = pod.to_dict() + assert to_spec == example_pod_spec + assert isinstance(to_spec, dict) + + async def test_pod_exec(ubuntu_pod): ex = await ubuntu_pod.exec(["date"]) assert isinstance(ex, CompletedExec)