Open nightkr opened 2 years ago
I think this comes down to a larger issue about when things are Option
al, and how we handle patches. Currently, (AFAIK) the policy is that all properties that are not required
(in the OpenAPI) are wrapped in Option
, which makes some sense for standard CRUD operations.
However, this makes less sense for patches, where almost no field is statically required since a missing value just means that it falls through to the old value.
On the other hand, non-atomic values (objects that are not explicitly tagged as atomic
, as well as list-maps) don't have much of a point in being Option
al either, since a missing value is essentially equivalent to an empty value ({}
or []
, respectively).
Maybe we will end up needing separate types to handle CRUD vs patch properly (either completely separate like Go handles it, or parametrized with some type mode mechanism). That seems unfortunate (both in terms of compile time and teachability), but I'm not sure I see a way around it... :/
Don't know if you've seen, but this is something they had to tackle on the go side as well with Apply* variants of all the structs. Basically an entirely parallel world of structs where everything is optional to get around this problem for server side apply.
Stuff for it is under KEP 2155 and some of my notes under https://github.com/kube-rs/kube-rs/issues/649
Stuff for it is under KEP 2155 and some of my notes under kube-rs/kube-rs#649
Thanks for those links.
For my reference:
https://github.com/kubernetes/kubernetes/blob/b8af116327cd5d8e5411cbac04e7d4d11d22485d/pkg/apis/apps/types.go#L135 vs https://github.com/kubernetes/kubernetes/blob/b8af116327cd5d8e5411cbac04e7d4d11d22485d/staging/src/k8s.io/client-go/applyconfigurations/apps/v1/statefulsetspec.go#L29
https://github.com/kubernetes/kubernetes/commit/03d242665dbe39b3ceeb8562850602480e5788b8 + https://github.com/kubernetes/kubernetes/commit/e688f22da07465a88728210412470e14330f1563
Repro
Expected
Produced
Why is this a problem?
LabelSelector
andstring
are both atomic (see incurl $K8S_API/openapi/v2 | jq '.definitions."io.k8s.apimachinery.pkg.apis.meta.v1.LabelSelector"'
that"x-kubernetes-map-type": "atomic"
), which means that server-side apply will replace them outright rather than trying to merge them. This prevents server-side apply from updatingStatefulSet
objects safely.Versions