openshift/openshift-restclient-python

Incapable of Handling "Remove" Patching

AndTheDaysGoBy opened this issue · 4 comments

When the body is a list, the appropriate header is 'application/json-patch+json' as seen when performing the oc command:
oc patch dc xyz --type json -p '[{"op": "remove", "path": "/spec/template/spec/imagePullSecrets"}]' --loglevel=10000

However, the openshift-python-client defaults to using application/strategic-merge-patch+json
as seen:

content_type = kwargs.pop('content_type', 'application/strategic-merge-patch+json')

This becomes an issue downstream since first we call the Kubernetes client:
https://github.com/kubernetes-client/python/blob/3739db034d34b035bc8141740e9073c84ab192c0/kubernetes/client/api_client.py#L345

which ultimately calls the REST client:
https://github.com/kubernetes-client/python/blob/3739db034d34b035bc8141740e9073c84ab192c0/kubernetes/client/api_client.py#L387

I.e.:
https://github.com/kubernetes-client/python/blob/3739db034d34b035bc8141740e9073c84ab192c0/kubernetes/client/rest.py#L156

Here it's specifically stated that strategic-merge-patch+json should only be used if not a list, however, since it was defaulted to that upstream, regardless of the conditional, the header is incorrect. Thus, a 400 occurs when the request finishes. In particular, the underlying Go library fails to parse the JSON correctly.

Issues go stale after 90d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle stale

Stale issues rot after 30d of inactivity.

Mark the issue as fresh by commenting /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.
Exclude this issue from closing by commenting /lifecycle frozen.

If this issue is safe to close now please do so with /close.

/lifecycle rotten
/remove-lifecycle stale

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

@openshift-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.

Reopen the issue by commenting /reopen.
Mark the issue as fresh by commenting /remove-lifecycle rotten.
Exclude this issue from closing again by commenting /lifecycle frozen.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.