ansible-community / molecule-kubevirt

Molecule Kubevirt Driver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Molecule KubeVirt Plugin

PyPI Package

image

Python Black Code Style

Repository License

Molecule KubeVirt Plugin is designed to allow use of KubeVirt containers for provisioning test resources.

Supported Platforms

Works with any OS distributed as cloud-config compatible image (also known as "Cloud images").

Usage

To use this plugin, you'll need to set the driver and platform variables in your molecule.yml:

Installation

Driver

This driver supports Ansible 2, 3 and 4.

# Ansible >2
python3 -m pip install molecule-kubevirt

# Ansible 2
python3 -m pip install molecule-kubevirt 'openshift<0.12.0' 'kubernetes<12.0'

KubeVirt Installation

Follow KubeVirt guides for kind, minkube, or cloud providers

SSH access

By default, the driver connects onto ssh via VirtualMachineInstance Pod ip and molecule needs to be able to ssh directly to Pod ip:

  • if running local Kubernetes with kind:
IP=$(docker container inspect kind-control-plane --format '{{ .NetworkSettings.Networks.kind.IPAddress }}')
sudo ip route add 10.244.0.0/16 via $IP # Linux
# sudo route -n add 10.244.0.0/16 $IP # MacOSX
  • if running local Kubernetes with minikube:
sudo ip route add 172.17.0.0/16 via $(minikube ip)
# sudo route -n add 172.17.0.0/16 $(minikube ip) # MacOSX
  • if running molecule inside the target Kubernetes cluster, routing is ensured by CNI.

A Kubernetes Service can be created by the driver for SSH access. Current supported Services are ClusterIP and NodePort.

NodePort

NodePort can be set. Static nodePort can be defined, also host target for port can be set:

ClusterIP

Default SSH Service is ClusterIP and a static clusterIP can be set:

Molecule then needs to be able to ssh on the ClusterIP ip:

  • if running local Kubernetes with Kind:
IP=$(docker container inspect kind-control-plane   --format '{{ .NetworkSettings.Networks.kind.IPAddress }}')
sudo ip route add 10.96.0.0/12 via $IP # Linux
# sudo route -n add 10.96.0.0/12 $IP # MacOSX
  • if running local Kubernetes with Minikube, no known solution yet.
  • if running molecule inside the target Kubernetes cluster, routing is ensured by CNI.

Virtual machines customisation

A few defaults are created if not provided in platfom definition:

  • if no interface with name: default is defined in domain.devices.interfaces, then a default one is created with brige: {} and bus: virtio,
  • if no disk with name: boot is defined in domain.devices.disks, then a default one is created with bus: virtio,
  • if no network with name: default is defined in networks, then a default one is created with pod: {} and model: virtio,
  • if no volume with name: boot is defined in volumes, then a default one is created as:
    • a containerDisk
    • with image, path and imagePullPolicy respectively set to plaform image, image_path and image_pull_policy
  • if cloud-config is defined in user_data it is merged default one wich sets ssh public key for 'molecule' user.

Customisation example

This example configuration demonstrates how to:

  • use Kubevirt's CDI in place of an image using dataVolumeTemplates and overriding default boot volume.
  • set customs ressources and annotation
  • and a second interface/network
  • adds a second disk/volume
  • make use of cloud-config to format and mount additional disk

See molecule/tests/molecule.yml from source code for full example.

Run from inside Kubernetes cluster

You can run this driver with a container running tox and/or molecule. Take a look at:

Get Involved

License

The MIT License.

The logo is licensed under the Creative Commons NoDerivatives 4.0 License.

If you have some other use in mind, contact us.

About

Molecule Kubevirt Driver

License:MIT License


Languages

Language:Python 79.7%Language:Shell 18.0%Language:Dockerfile 2.3%