Problem with patching NetNamespace (add egressIP)
xforze opened this issue · 1 comments
Hi all,
Im running into a Problem while try to patch a NetNamespace (add an egressIP).
Here is the Code Im using:
v1_netnamespace = dyn_client.resources.get(api_version='network.openshift.io/v1', kind='NetNamespace')
data = {
'kind': 'NetNamespace',
'apiVersion': 'network.openshift.io/v1',
'metadata': {'name': project, 'namespace': project },
'egressIPs': ['192.168.1.101']
}
v1_netnamespace.patch(body=data, namespace=project)
The error I get is:
openshift.dynamic.exceptions.DynamicApiError: 415
Reason: Unsupported Media Type
HTTP response headers: HTTPHeaderDict({'Audit-Id': '5f9ac551-c82c-44ab-906a-82a31e4e5e1d', 'Cache-Control': 'no-cache, private', 'Content-Type': 'application/json', 'X-Kubernetes-Pf-Flowschema-Uid': '6802724d-d8a4-439d-8c6d-14204e356766', 'X-Kubernetes-Pf-Prioritylevel-Uid': '1049f336-41c4-4436-b593-54dcd0a01c0e', 'Date': 'Tue, 06 Oct 2020 07:43:18 GMT', 'Content-Length': '293'})
HTTP response body: b'{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"the body of the request was in an unknown format - accepted media types include: application/json-patch+json, application/merge-patch+json, application/apply-patch+yaml","reason":"UnsupportedMediaType","code":415}\n'
When I try to Patch a ResourceLimit, it works fine and the process of patching looks almost the the same to me:
v1_resourcequota = dyn_client.resources.get(api_version='v1', kind='ResourceQuota')
data = {
'kind': 'ResourceQuota',
'apiVersion': 'v1',
'metadata': {'name': 'mem-cpu', 'namespace': project },
'spec': {
'hard': {'requests.cpu': v['cpu-request'], 'requests.memory': v['ram-request'], 'limits.cpu': v['cpu-limit'], 'limits.memory': v['ram-limit']},
}
}
v1_resourcequota.patch(body=data, namespace=project)
Any Ideas what Im doing wrong ?
Cheers!
Update:
As the error message shows: accepted media types include: application/json-patch+json which is a definded web-standard (https://en.wikipedia.org/wiki/JSON_Patch), I tried to add an egressIP with the following json patch String:
[{ "op": "add", "path": "/egressIPs", "value": ["192.168.10.10"] }]
Unfortunately, it results in the same error message as shown above.
The same problem occurs if I try to patch the netnamespace with oc command:
# oc patch netnamespace default -p '[{"op": "add", "path": "/egressIPs", "value": ["192.168.10.10"]}]'
Error from server (UnsupportedMediaType): the body of the request was in an unknown format - accepted media types include: application/json-patch+json, application/merge-patch+json, application/apply-patch+yaml
After adding the --type json Parameter, it works fine:
# oc patch netnamespace default --type json -p '[{"op": "add", "path": "/egressIPs", "value": ["192.168.10.110"]}]'
netnamespace.network.openshift.io/default patched
Is there a similar switch in the openshift rest client ?
I was able now to patch the netnamespace by defining the patch type with:
kwargs = {'name': projetname, 'content_type': 'application/json-patch+json'}
egress.patch(body=b, namespace=p, **kwargs)