oVirt / java-client-kubevirt

Kubevirt java client (java-client-kubevirt) for oVirt
13 stars 4 forks source link

how to delete a vm/vmi via kubevirt java client #2

Open yangxiaoliang opened 3 years ago

yangxiaoliang commented 3 years ago

Hi,

I hit some issue when delete VMI through java client, following is my test code snippet:

    V1DeleteOptions options = new V1DeleteOptions();
    options.setApiVersion("V1");
    options.setKind("VirtualMachineInstance");
    options.setGracePeriodSeconds(t);

    try {
        V1Status v1status = api.deleteNamespacedVirtualMachineInstance(options, "default", vmi1name, null, null, null);
    } catch (ApiException e) {
        System.out.println("delete vmi failed: %s" + e);
    }

and the error message is:

    "{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"no kind \"VirtualMachineInstance\" is registered for version \"V1\" in scheme \"k8s.io/apimachinery/pkg/apis/meta/internalversion/register.go:31\"","code":500}"

seem like the V1DeleteOptions object was not set correctly. I have tried to set the api version to : v1/ V1 / kubevirt.io/v1 and set the kind to VirtualMachineInstance/ virtualmachineinstance, VirtualMachineInstances/virtualmachineinstances , VMI/vmi, but all of them got failed with same error like above, could you help give me some guide or examples on how to delete the vmi via java client ?

P.S. The java client version I am using is : 0.5.0, and the kubevirt version is 0.41.0.

Thanks, Xiaoliang

ahadas commented 2 years ago

@yangxiaoliang please note that this library was implemented specifically for oVirt and from oVirt's perspective, there's no reason to delete a VMI (because we don't want to remove a running VM) so we never tested it. You can see how oVirt removes VMs here - if similar code doesn't work for VMIs then maybe some of the modifications we did in the generated code in this library is missing for VMIs..