Skip to content

cannot label pod #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ceeaspb opened this issue Feb 3, 2018 · 1 comment
Closed

cannot label pod #176

ceeaspb opened this issue Feb 3, 2018 · 1 comment

Comments

@ceeaspb
Copy link
Contributor

ceeaspb commented Feb 3, 2018

$ kubectl label pods test a=b  -v=8 
I0203 22:41:41.332842    1929 loader.go:357] Config loaded from file /Users/nn/.kube/config
I0203 22:41:41.339256    1929 round_trippers.go:414] GET https://192.168.99.100:8443/api/v1/namespaces/default/pods/test
I0203 22:41:41.339268    1929 round_trippers.go:421] Request Headers:
I0203 22:41:41.339272    1929 round_trippers.go:424]     Accept: application/json
I0203 22:41:41.339275    1929 round_trippers.go:424]     User-Agent: kubectl/v1.9.2 - kubernetes/5fa2db2
I0203 22:41:41.350411    1929 round_trippers.go:439] Response Status: 200 OK in 11 milliseconds
I0203 22:41:41.350437    1929 round_trippers.go:442] Response Headers:
I0203 22:41:41.350455    1929 round_trippers.go:445]     Content-Type: application/json
I0203 22:41:41.350464    1929 round_trippers.go:445]     Content-Length: 3506
I0203 22:41:41.350468    1929 round_trippers.go:445]     Date: Sat, 03 Feb 2018 22:41:41 GMT
I0203 22:41:41.350524    1929 request.go:873] Response Body: {"kind":"Pod","apiVersion":"v1","metadata":{"name":"test"
...,
"labels":{"controller-revision-hash":"test-67cb67b4c4",
...
I0203 22:41:41.352115    1929 request.go:873] Request Body: {"metadata":{"labels":{"a":"b"}}}
I0203 22:41:41.352146    1929 round_trippers.go:414] PATCH https://192.168.99.100:8443/api/v1/namespaces/default/pods/test
I0203 22:41:41.352151    1929 round_trippers.go:421] Request Headers:
I0203 22:41:41.352155    1929 round_trippers.go:424]     Accept: application/json
I0203 22:41:41.352159    1929 round_trippers.go:424]     Content-Type: application/merge-patch+json
I0203 22:41:41.352162    1929 round_trippers.go:424]     User-Agent: kubectl/v1.9.2 - kubernetes/5fa2db2
I0203 22:41:41.362097    1929 round_trippers.go:439] Response Status: 200 OK in 9 milliseconds
I0203 22:41:41.362115    1929 round_trippers.go:442] Response Headers:
I0203 22:41:41.362122    1929 round_trippers.go:445]     Date: Sat, 03 Feb 2018 22:41:41 GMT
I0203 22:41:41.362128    1929 round_trippers.go:445]     Content-Type: application/json
I0203 22:41:41.362133    1929 round_trippers.go:445]     Content-Length: 3540
I0203 22:41:41.362193    1929 request.go:873] Response Body: {"kind":"Pod","apiVersion":"v1","metadata":{"name":"test",
...
"labels":{"a":"b"
...

but with the api I get similar/same error to #127 .

CoreV1Api api = new CoreV1Api();
api.patchNamespacedPod("test", "default", "{\"metadata\":{\"labels\":{\"a\":\"b\"}}}", "false");

content type above is application/merge-patch+json.

So it terms of trying to debug/fix this these changes made it work for me. They are not proper fixes...:

$ git diff kubernetes/src/main/java/io/kubernetes/client/ApiClient.java  kubernetes/src/main/java/io/kubernetes/client/apis/CoreV1Api.java
diff --git a/kubernetes/src/main/java/io/kubernetes/client/ApiClient.java b/kubernetes/src/main/java/io/kubernetes/client/ApiClient.java
index c6bccd3..7d27bfa 100644
--- a/kubernetes/src/main/java/io/kubernetes/client/ApiClient.java
+++ b/kubernetes/src/main/java/io/kubernetes/client/ApiClient.java
@@ -696,7 +696,9 @@ public class ApiClient {
             return RequestBody.create(MediaType.parse(contentType), (File) obj);
         } else if (isJsonMime(contentType)) {
             String content;
-            if (obj != null) {
+            if (obj != null && obj instanceof String) {
+               content = (String)obj;
+            } else if (obj != null) {
                 content = json.serialize(obj);
             } else {
                 content = null;
diff --git a/kubernetes/src/main/java/io/kubernetes/client/apis/CoreV1Api.java b/kubernetes/src/main/java/io/kubernetes/client/apis/CoreV1Api.java
index d1f8530..53291ca 100644
--- a/kubernetes/src/main/java/io/kubernetes/client/apis/CoreV1Api.java
+++ b/kubernetes/src/main/java/io/kubernetes/client/apis/CoreV1Api.java
@@ -20761,7 +20761,7 @@ public class CoreV1Api {
         if (localVarAccept != null) localVarHeaderParams.put("Accept", localVarAccept);
 
         final String[] localVarContentTypes = {
-            "application/json-patch+json", "application/merge-patch+json", "application/strategic-merge-patch+json"
+            "application/merge-patch+json", "application/strategic-merge-patch+json"
         };
         final String localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);
         localVarHeaderParams.put("Content-Type", localVarContentType);

Ie. force a merge patch and don't serialize the json string.

Is it possible for anyone to review the findings and prepare a proper fix? thanks

@ceeaspb
Copy link
Contributor Author

ceeaspb commented Feb 25, 2018

Although kubectl defaults to strategic merge and the kubernetes python api supports strategic merge, the java api doesn't yet. The information to get this working was there, just not immediately obvious.

JSON patch add/remove works with a patch string like
"{\"op\":\"add\",\"path\":\"/metadata/labels/" + label + "\", \"value\": \"" + value + "\" }"

@ceeaspb ceeaspb closed this as completed Feb 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant