Skip to content
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

Raw CustomResource API: Unable to edit CustomResource via InputStream #2717

Closed
rohanKanojia opened this issue Jan 12, 2021 · 2 comments · Fixed by jenkinsci/kubernetes-client-api-plugin#83
Assignees
Labels

Comments

@rohanKanojia
Copy link
Member

let's say I have a CustomResource Dummy present in my kubernetes cluster like this:

jkube : $ kubectl get dummies
NAME           AGE
first-dummy    20m
second-dummy   20m

If I try to edit first-dummy by providing contents via an InputStream like this:

try (KubernetesClient client = new DefaultKubernetesClient()) {
    CustomResourceDefinitionContext context = new CustomResourceDefinitionContext.Builder()
            .withGroup("demo.fabric8.io")
            .withVersion("v1")
            .withScope("Namespaced")
            .withPlural("dummies")
            .build();
    InputStream crInputStream = RawCustomResourceEdit.class.getResourceAsStream("/dummy-cr.yml");

    client.customResource(context).edit("default", "first-dummy", crInputStream);
}

I'm getting this error:

Exception in thread "main" io.fabric8.kubernetes.client.KubernetesClientException: Failure executing: PUT at: https://192.168.39.3:8443/apis/demo.fabric8.io/v1/namespaces/default/dummies/first-dummy. Message: dummies.demo.fabric8.io "first-dummy" is invalid: metadata.resourceVersion: Invalid value: 0x0: must be specified for an update. Received status: Status(apiVersion=v1, code=422, details=StatusDetails(causes=[StatusCause(field=metadata.resourceVersion, message=Invalid value: 0x0: must be specified for an update, reason=FieldValueInvalid, additionalProperties={})], group=demo.fabric8.io, kind=dummies, name=first-dummy, retryAfterSeconds=null, uid=null, additionalProperties={}), kind=Status, message=dummies.demo.fabric8.io "first-dummy" is invalid: metadata.resourceVersion: Invalid value: 0x0: must be specified for an update, metadata=ListMeta(_continue=null, remainingItemCount=null, resourceVersion=null, selfLink=null, additionalProperties={}), reason=Invalid, status=Failure, additionalProperties={}).
	at io.fabric8.kubernetes.client.dsl.base.OperationSupport.requestFailure(OperationSupport.java:570)
	at io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl.makeCall(RawCustomResourceOperationsImpl.java:800)
	at io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl.validateAndSubmitRequest(RawCustomResourceOperationsImpl.java:815)
	at io.fabric8.kubernetes.client.dsl.internal.RawCustomResourceOperationsImpl.validateAndSubmitRequest(RawCustomResourceOperationsImpl.java:808)

I don't face this error when providing the edited resource as a string or Hashmap.

@manusa
Copy link
Member

manusa commented Jan 18, 2021

Your code is not describing an edit procedure but a replacement procedure.

What you are expecting (if I'm not mistaken) is that the client gets the resource defined in your YAML and replaces the one in the cluster.

What I see is that this operation should either not be allowed, or perform a diff operation on both resources.

The outcome of this issue should either be:

A) Remove these methods where I accept an InputStream as an argument to the edit methods.

B) Create some sort of logic that will retrieve the edited resource from the cluster, and a merge operation will be performed with the resource loaded from the local YAML. Fields defined in the local YAML should prevail on top of those existent in the cluster defined resource.

@rohanKanojia
Copy link
Member Author

I think we can cover B separately by providing better patching support #2645

rohanKanojia added a commit to rohanKanojia/kubernetes-client that referenced this issue Feb 1, 2021
…tionsImpl taking InputStream arguments

As discussed in fabric8io#2717, it's not a good idea to take InputStream for
edit() methods which simply does a PATCH to Kubernetes APIServer.
@rohanKanojia rohanKanojia self-assigned this Feb 1, 2021
@manusa manusa closed this as completed in e5e48ca Feb 2, 2021
This was referenced Mar 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment