fabric8io / kubernetes-model

JSON schema generator for OpenShift Origin API objects
36 stars 72 forks source link

Differentiate between missing and empty arrays #190

Open dhirajsb opened 7 years ago

dhirajsb commented 7 years ago

The model currently initializes all array fields with new ArrayList<...>, which makes it difficult to know whether the field was empty or not set at all in the original json/yaml source.

This causes a serious issue in k8 client JSON patch request, since it generates a different request for the two cases.

If the array is missing, it generates a patch request to add a new array if it exists and to set the element at '0' if its empty respectively.

K8 model should distinguish the two use cases, by lazily initializing all collections on add calls.

jimmidyson commented 7 years ago

This is a serious issue that if we fix it properly as suggested would break backwards compatibility for consumers that rely on these being initialised. I cannot think of any functionality other than patch that this causes problems with & if that's the case should we defer the "proper" fix until v2 of the model (which I have in the works btw) & do the hack in kube client to handle empty arrays as @dhirajsb has already done?

dhirajsb commented 7 years ago

@jimmidyson that's also my assessment so far. It has only broken json patch, due to the way OpenShift and I suspect K8s ignore empty arrays. For example, if one tries to add an empty array using {{oc edit..}} it is actually dropped altogether, hence the approach I took to fixing it for json patch.

piyush-garg commented 6 years ago

280 is related to this as far as I can conclude.