415 UnsupportedMediaType when running patchNamespacedSecret using version 20.0.1
Closed this issue · 3 comments
Describe the bug
415 received when using the client-java library to patch a k8s secret. The same was executed with kubectl patch and succeeded. I was wondering if there is a something that is obviously wrong about what I am doing or steps to debug further.
V1Patch v1Patch = new V1Patch("{\"op\":\"replace\",\"path\":\"/data\",\"value\":{\"JDBC_USERNAME\":\"base64encode\",\"JDBC_PASSWORD\":\"base64encode\",\"DB_DBNAME\":\"base64encode\",\"DB_HOST\":\"base64encode\",\"DB_PASSWORD\":\"base64encode\",\"DB_PORT\":\"base64encode==\",\"DB_SN\":\"\",\"DB_USER\":\"base64encode\"}}\n");
System.out.println(v1Patch);
CoreV1Api.APIpatchNamespacedSecretRequest apIpatchNamespacedSecretRequest = kapi.patchNamespacedSecret("db-secrets", "namespace", v1Patch);
V1Secret v1Secret = apIpatchNamespacedSecretRequest.execute();
System.out.println(v1Secret);
`
Yields the following stacktrace:
HTTP response code: 415
HTTP response body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"415: Unsupported Media Type","reason":"UnsupportedMediaType","details":{},"code":415}
HTTP response headers: {audit-id=[b6d18e05-642e-49a8-9ea9-682ed51887ed], cache-control=[no-cache, private], content-length=[165], content-type=[application/json], date=[Thu, 22 Aug 2024 20:38:44 GMT], x-kubernetes-pf-flowschema-uid=[a5276ed7-00f8-4572-973a-61000786ac42], x-kubernetes-pf-prioritylevel-uid=[87499acf-6f46-444f-89d1-3ccd458c5dc9]}
at io.kubernetes.client.openapi.ApiClient.handleResponse(ApiClient.java:1116)
at io.kubernetes.client.openapi.ApiClient.execute(ApiClient.java:1029)
at io.kubernetes.client.openapi.apis.CoreV1Api.patchNamespacedSecretWithHttpInfo(CoreV1Api.java:36215)
at io.kubernetes.client.openapi.apis.CoreV1Api.access$56900(CoreV1Api.java:77)
at io.kubernetes.client.openapi.apis.CoreV1Api$APIpatchNamespacedSecretRequest.execute(CoreV1Api.java:36322)
at com.abpadan.k8s.ApplicationMain.main(ApplicationMain.java:26)
Client Version
20.0.1
Kubernetes Version
[user@k8s]$ kubectl version Client Version: v1.29.2 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 Server Version: v1.29.7
Java Version
Java 8
To Reproduce
Run a java main with the above code snippet. The pom.xml has a dependency on the following:
<dependency> <groupId>io.kubernetes</groupId> <artifactId>client-java-api</artifactId> <version>20.0.1</version> </dependency> <dependency> <groupId>io.kubernetes</groupId> <artifactId>client-java</artifactId> <version>20.0.1</version> </dependency>
Expected behavior
Expect the secret to be updated.
KubeConfig
Standard kubeconfig with cluster and kubernetes-admin. Cluster has insecure-skip-tls-verify to true.
Server (please complete the following information):
- OS: Linux (Centos7)
- Environment: Intellij, Jar
- Cloud: NA
Additional context
I realize that the java combability matrix has 20.0.1 tied to 1.28. However, I am wondering if the patchNamespacedSecret is known to not work with k8s 1.29. This eventually runs in a containerized manner, however, I have tried to strip it down to something that is executable in a java main. The values in the JSON above have been redacted (otherwise encoded using base64).
Patching is complicated and not quite compliant w/ the swagger specification.
Instead of doing it yourself directly with that call, please use the PatchUtils
class as shown in the example here:
@brendandburns thanks for the suggestions. Able to get past the issue using PatchUtils.
Closing this as addressed.