Patching deployments via kubernetes/client-go
You have mixed up JSONPatchType with MergePatchType
; JSONPatchType
wants the input to be RFC 6902 formatted "commands", and in that case can be a JSON array, because there can be multiple commands applied in order to the input document
However, your payload looks much closer to you wanting MergePatchType
, in which case the input should not be a JSON array because the source document is not an array of "spec"
objects.
Thus, I'd bet just dropping the leading [
and trailing ]
, changing the argument to be types.MergePatchType
will get you much further along
Actually you should use types.StrategicMergePatchType
and remove leading([
) and trailing(]
) parenthesis from patching string.
Merge-patch: With a JSON merge patch, if you want to update a list, you have to specify the entire new list. And the new list completely replaces the existing list.
Strategic-merge-patch: With a strategic merge patch, a list is either replaced or merged depending on its patch strategy. The patch strategy is specified by the value of the patchStrategy
key in a field tag in the Kubernetes source code. For example, the Containers field of PodSpec
struct has a patchStrategy
of merge:
type PodSpec struct { ... Containers []Container `json:"containers" patchStrategy:"merge" patchMergeKey:"name" ...`
N.B: kubectl by-default uses strategic merge patch to patch kubernetes resources.