Skip to content

Error when trying to call patchNode #263

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
ohadmuch opened this issue May 10, 2018 · 5 comments
Closed

Error when trying to call patchNode #263

ohadmuch opened this issue May 10, 2018 · 5 comments

Comments

@ohadmuch
Copy link

Using version 1.0.0

When calling CoreV1Api patchNode method the call fails because the inner methods set the wrong content type, the content type should be : "application/merge-patch+json"

when setting it manually the call succeed

@karthikkondapally
Copy link
Contributor

know issue #127

will arise for all patch calls

use JSON PATCH, which will not throw any error:
example: https://github.com/kubernetes-client/java/blob/master/examples/src/main/java/io/kubernetes/client/examples/PatchExample.java

@brendandburns
Copy link
Contributor

closing as duplicate.

@costimuraru
Copy link

costimuraru commented Jul 7, 2018

The PatchExample shows how to patch a Deployment.

ExtensionsV1beta1Api api = new ExtensionsV1beta1Api();
ExtensionsV1beta1Deployment deploy =
    api.patchNamespacedDeployment(deployName, namespace, body, pretty);

But there is no api.patchNode() method there.

Ideas?

@Baaamm
Copy link

Baaamm commented Jul 30, 2018

Same problem here. I want to make this call with the api: kubectl taint nodes testKey=value:NoExecute

is it possible? I got:

Internal Server Error, Response Error: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"json: cannot unmarshal object into Go value of type jsonpatch.Patch","code":500}

I got the solution to patch the Node with coreV1Api.patchNode

The body need to be a JsonPatch Object.
For my issue, an json example can look like this:

String jsonPatchString= {\"op\":\"add\",\"path\":\"/spec/taints\",\"value\":[{\"effect\":\"NoSchedule\",\"key\":\"testKey\",\"value\":\"testValue\"}]}";

As @kondapally1989 mention, you need to create the body like in the PatchExample and than you can use the coreV1Api.patchNode( .. ) to patch the Node
Java Example:

	public V1Node patchNode(String jsonPatchString, String nodeId) {
		ArrayList<JsonObject> arr = new ArrayList<>();
		arr.add(((JsonElement) deserialize(jsonPatchString, JsonElement.class)).getAsJsonObject());
		V1Node nodeV1;
		try {
			nodeV1 = this.coreV1Api.patchNode(nodeName, arr, "false");
			LOG.info("patchNode | patching node {} was successful", 
                        nodeV1.getMetadata().getName());
		} catch (ApiException e) {
			throw new RuntimeException("Patching node fail", e);
		}

		return nodeV1;
	}

@karthikkondapally
Copy link
Contributor

patchNode sample:
https://github.com/kubernetes-client/java/blob/master/kubernetes/docs/CoreV1Api.md#patchNode

add -v=8 for kubectl command to see how kubectl is hitting the server api with jsonPayloads

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

5 participants