A client and CLI for Kubevirt.
To use the client add the following dependency to the pom.xml
<dependency>
<groupId>io.quarkiverse.kubevirt</groupId>
<artifactId>quarkus-kubevirt</artifactId>
</dependency>
To inject the client into your code:
@Inject
private KubevirtClient client;
The client can be used like this:
List<VirtualMachine> virtualMachines = client.v1().virtualmachines().list().getItems();
The project supports the following apiGroup and versions::
- kubevirt.io/v1alpha3 (io.quarkiverse.kubevirt:quarkus-kubevirt-model-v1alpha3)
- kubevirt.io/v1 (io.quarkiverse.kubevirt:quarkus-kubevirt-model-v1)
- pool.kubevirt.io/v1alpha1 (io.quarkiverse.kubevirt:quarkus-kubevirt-pool)
- cdi.kubevirt.io/v1beta1 (io.quarkiverse.kubevirt:quarkus-kubevirt-cdi)
- networkaddonsoperator.kubevirt.io/v1 (io.quarkiverse.kubevirt:quarkus-kubevirt-network)
- networkaddonsoperator.kubevirt.io/v1alpha1 (io.quarkiverse.kubevirt:quarkus-kubevirt-network)
- instancetype.kubevirt.io/v1alpha1 (io.quarkiverse.kubevirt:quarkus-kubevirt-instancetype)
- instancetype.kubevirt.io/v1alpha2 (io.quarkiverse.kubevirt:quarkus-kubevirt-instancetype)
- hco.kubevirt.io/v1beta1 (io.quarkiverse.kubevirt:quarkus-kubevirt-hco)
- export.kubevirt.io/v1alpha1 (io.quarkiverse.kubevirt:quarkus-kubevirt-export)
- hostpathprovisioner.kubevirt.io/v1beta1 (io.quarkiverse.kubevirt:quarkus-kubevirt-hostpathprovisioner)
- snapshot.kubevirt.io/v1alpha1 (io.quarkiverse.kubevirt:quarkus-kubevirt-snapshot)
- ssp.kubevirt.io/v1beta1 (io.quarkiverse.kubevirt:quarkus-kubevirt-ssp)
- tektontasks.kubevirt.io/v1alpha1 (io.quarkiverse.kubevirt:quarkus-kubevirt-tektontasks)
Note That not all APIs are exposed to the client DSL.
The exposed ones are the following:
- kubevirt.io/v1 (io.quarkiverse.kubevirt:quarkus-kubevirt-model-v1)
- pool.kubevirt.io/v1alpha1 (io.quarkiverse.kubevirt:quarkus-kubevirt-pool)
- cdi.kubevirt.io/v1beta1 (io.quarkiverse.kubevirt:quarkus-kubevirt-cdi)
All other API are meant to be used via the kubernetes client resource capability.
For example to list all VirtualMachines using the v1alpha3 API:
@Inject KubernetesClient kubernetesClient;
public void printVirtualMachines() {
List<VirtualMachine> virtualMachines = kubernetesClient.resources(VirtualMachine.class).list().getItems();
}
When adddintg the io.quarkiverse.kubevirt:quarkus-kubevirt
dependency to the pom.xml
you can use the CLI to interact with the Kubevirt API (within any project directory).
The CLI can also be added independently as a Quarkus CLI plugin.
quarkus plug add io.quarkiverse.kubevirt:quarkus-kubevirt-cli:runner:jar:999-SNAPSHOT
The later has value to globally enable the plugin (not just for the current project), or to use version that have not been publicly releashed yet (local builds).
For example to get all the available virtual machines:
quarkus kubevirt vm list
quarkus kubevirt vm create from-file /path/to/vm.yaml
quarkus kubevirt vm create podman
or to create and also wait until readdy:
quarkus kubevirt vm create podman -w
to also replace existing vms:
quarkus kubevirt vm create podman -r