-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.
Description
Describe the bug
Hello,
I'm trying to patch a custom resource following this official example:
https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/CustomObjectsApi.md#patchNamespacedCustomObject
Object result = apiInstance.patchNamespacedCustomObject(group, version, namespace, plural, name, body).execute();
No matter what I specify in the body param (json patch string, yaml patch, a Map with CRD attributes), the result is always an HTTP 415 error response from the server:
{"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}
Java client Version
20.0.0
Kubernetes Version
1.28
Java Version
Corretto-21.0.2
To Reproduce
Steps to reproduce the behavior:
CustomObjectsApi apiInstance = new CustomObjectsApi(defaultClient);
...
String body = "[\n" +
" {\n" +
" \"op\": \"add\",\n" +
" \"path\": \"/metadata/annotations/new-annotation\",\n" +
" \"value\": \"value of the new annotation\"\n" +
" }\n" +
"]";
Object result = apiInstance.patchNamespacedCustomObject(group, version, namespace, plural, name, body).execute();
Results in:
2024-02-22T14:58:56.876+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : Content-Length: 215
2024-02-22T14:58:56.876+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : Accept: application/json
2024-02-22T14:58:56.876+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : Content-Type: application/json
2024-02-22T14:58:56.876+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : User-Agent: Kubernetes Java Client/20.0.0-SNAPSHOT
2024-02-22T14:58:56.876+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient :
2024-02-22T14:58:56.876+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : "[\n {\n \"op\": \"add\",\n \"path\": \"/metadata/annotations/new-annotation\",\n \"value\": \"value of the new annotation\"\n }\n ]"
2024-02-22T14:58:56.876+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : --> END PATCH (215-byte body)
2024-02-22T14:58:56.881+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : audit-id: 9c309609-0e88-4ee1-9399-c438249fe8d2
2024-02-22T14:58:56.881+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : cache-control: no-cache, private
2024-02-22T14:58:56.881+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : content-type: application/json
2024-02-22T14:58:56.881+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : x-kubernetes-pf-flowschema-uid: 891cc6ff-2e12-450f-b9c8-94f26b2adda8
2024-02-22T14:58:56.881+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : x-kubernetes-pf-prioritylevel-uid: dbc7143a-c8fc-4f36-a0b9-451153992497
2024-02-22T14:58:56.881+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : content-length: 293
2024-02-22T14:58:56.881+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : date: Thu, 22 Feb 2024 03:58:56 GMT
2024-02-22T14:58:56.881+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient :
2024-02-22T14:58:56.882+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : {"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}
2024-02-22T14:58:56.882+11:00 INFO 81582 --- [nio-8080-exec-1] okhttp3.OkHttpClient : <-- END HTTP (293-byte body)
2024-02-22T14:58:56.884+11:00 ERROR 81582 --- [nio-8080-exec-1] c.a.a.homa.k8s.api.http.ExceptionHelper : ApiException: Message:
HTTP response code: 415
HTTP response body: {"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}
Expected behavior
The expectation is that the above code would modify the CRD.
Using PatchUtils
doesn't seem an alternative for custom resources since the class to be patched (which would be Object
for a CRD) must be supplied:
public static <ApiType> ApiType patch(Class<ApiType> apiTypeClass, PatchCallFunc callFunc, String patchFormat, ApiClient apiClient) throws ApiException {
`
daliborfilus
Metadata
Metadata
Assignees
Labels
kind/bugCategorizes issue or PR as related to a bug.Categorizes issue or PR as related to a bug.