Skip to content

Commit

Permalink
Ensure kind and apiVersion are always included in raw specs (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson authored Jun 11, 2024
1 parent 786a390 commit f4c9252
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kr8s/_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def api(self, value):
@property
def raw(self) -> str:
"""Raw object returned from the Kubernetes API."""
return self._raw
raw_spec = {"kind": self.kind, "apiVersion": self.version}
raw_spec.update(self._raw)
return raw_spec

@raw.setter
def raw(self, value: Any) -> None:
Expand Down
13 changes: 13 additions & 0 deletions kr8s/tests/test_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@ async def test_nonexistant():
await pod.exists(ensure=True)


async def test_pod_kind_api_raw():
pod = await Pod(
{
"metadata": {"name": "foo"},
"spec": {"containers": [{"name": "foo", "image": "nginx"}]},
}
)
assert "kind" in pod.raw
assert "apiVersion" in pod.raw
assert pod.raw["kind"] == "Pod"
assert pod.raw["apiVersion"] == "v1"


async def test_pod_metadata(example_pod_spec, ns):
pod = await Pod(example_pod_spec)
await pod.create()
Expand Down

0 comments on commit f4c9252

Please sign in to comment.