Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtomlinson committed Jul 3, 2024
1 parent f2cdf46 commit 8d1195e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions docs/object.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,21 @@ CustomScalableObject = new_class(
)
```

```{danger}
Manually subclassing `APIObject` is considered an advanced topic and requires strong understanding of `kr8s` internals and how the sync/async wrapping works. For now it is recommended that you do not do this.
```

### Using custom objects with other `kr8s` functions

When using the [`kr8s` API](client) some methods such as `kr8s.get("pods")` will want to return kr8s objects, in this case a `Pod`. The API client handles this by looking up all of the subclasses of [`APIObject`](#kr8s.objects.APIObject) and matching the `kind` against the kind returned by the API. If the API returns a kind of object that there is no kr8s object to deserialize into it will raise an exception.
When using the [`kr8s` API](client) some methods such as `kr8s.get("pods")` will want to return kr8s objects, in this case a `Pod`. The API client handles this by looking up all of the subclasses of [`APIObject`](#kr8s.objects.APIObject) and matching the `kind` against the kind returned by the API. If the API returns a kind of object that there is no kr8s object to deserialize into it will create a new class for you automatically.

```python
import kr8s

cos = kr8s.get("customobjects") # If a resource called `customobjects` exists on the server a class will be created dynamically for it
```

When you create your own custom objects that subclass [`APIObject`](#kr8s.objects.APIObject) the client is then able to use those objects in its response.
When you create your own custom objects with `new_class` the client is then able to use those objects in its response.

```python
import kr8s
Expand Down

0 comments on commit 8d1195e

Please sign in to comment.