Repository navigation
Why didn't you use Pydantic instead of msgspec? #1318
|
Pydantic has waaayyy more facilities and options for validation than msgspec, instant validation, many many tnx for the explanation for msgspec |
Replies: 1 comment 1 reply
|
Hi. I do not know what msgspec is, and I do not use it. Pydantic was not much popular when Kopf was created (2019-2021) or I did not know about it, and therefore did not put it into design. Its usage was discussed in a few issues. As far as I know, there are other Pydantic-based libraries working as API clients. Kopf is not an API client library. Today, I find the use of Pydantic or any other validation library impractical: the refactoring will be huge, the backwards compatibility broken, will bring a heavy dependency tree, but the win will be near-zero and for a small share of users. Specifically: Kopf receives its data from Kubernetes, not from users. Kubernetes cannot be wrong about the schemas, its schemas are the source of truth. And even if it does send the wrong data, what do we do with it? There is nowhere you can send the validation errors to, except as disconnecting from the stream; and nobody/nothing will correct them. On creation/modification, k8s itself validates the user data against the builtin or crd schemas, no need to duplicate that functionality. If anyone still wishes to use Pydantic or any other model library, it is a one-liner in every handler: take a raw dict from k8s and wrap it into a model (and validate it if you wish; and fail the handler if the data does mot match the schema). There is even a decorator that makes this automatically: Hope this helps. |
Hi. I do not know what msgspec is, and I do not use it.
Pydantic was not much popular when Kopf was created (2019-2021) or I did not know about it, and therefore did not put it into design.
Its usage was discussed in a few issues. As far as I know, there are other Pydantic-based libraries working as API clients. Kopf is not an API client library.
Today, I find the use of Pydantic or any other validation library impractical: the refactoring will be huge, the backwards compatibility broken, will bring a heavy dependency tree, but the win will be near-zero and for a small share of users.
Specifically: Kopf receives its data from Kubernetes, not from users. Kubernetes cannot be wrong about th…