Description
Currently we have a set of optional struct literal fields in our API, e.G: (This is an incomplete list):
cluster-api/pkg/apis/cluster/v1alpha1/cluster_types.go
Lines 52 to 53 in 19551f1
cluster-api/pkg/apis/cluster/v1alpha1/machinedeployment_types.go
Lines 42 to 43 in 19551f1
cluster-api/pkg/apis/cluster/v1alpha1/machine_types.go
Lines 68 to 69 in 19551f1
These are impossible to default via a MutatingAdmissionWebhook
, because the only supported patch type currently is Jsonpatch
. A jsonpatch
is generated by marshalling an object original
and an object current
, then calculating the json patch for the diff. However the marshaled representation the Webhook that knows the types will always contain an empty object field ({}
) for the optional property when it is a literal, even when omitempty
is set. Consequently, the resulting Jsonpatch will not try to add the main object but only its children. This patch will then get rejected by the APIServer with an error like doc is missing path: "/spec/strategy/type
because it doesn't know anything about the main object (here: /spec/strategy
).