Molecule aids in the development and testing of Ansible roles
Project description
Molecule KubeVirt Plugin is designed to allow use of KubeVirt containers for provisioning test resources.
Very alpha version - All configuration fields and behaviours may be subject to breaking changes
Scope
Molecule-kubevirt enables running ansible roles tests in a Kubernetes cluster.
Usage
To use this plugin, you’ll need to set the driver and platform variables in your molecule.yml:
driver:
name: kubevirt
platforms:
- name: instance
image: quay.io/kubevirt/fedora-cloud-container-disk-demo
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 de 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:
ssh_service:
type: NodePort
# optional static port
nodePort: 32569
# host where nodePort can be reached
nodePort_host: localhost
ClusterIP
Default SSH Service is ClusterIP and a static clusterIP can be set:
ssh_service:
type: ClusterIP
clusterIP: 10.96.102.231
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
Virtual machines can be customised using domain, volumes, networks and user_data.
Since the driver already sets some values for molecule to start VMs with no customisation, values set in those fields will be merged with default configuration.
Full example
VirtualMachines setup can be fine tuned:
annotations is empty by default
domain is combined recursive with default, defaults lists are prepend
user_data cloud-config is combined recursive with default, defaults lists are prepend
volumes are appended to defaults
networks is empty by default
This example configures a specific network, adds a disk backed by an empty volume, then disk is formated and mounted via cloud config:
# ask for static IP with Calico
annotations:
- cni.projectcalico.org/ipAddrs: "[\"10.244.25.25\"]"
# combine domain to default
domain:
devices:
disks:
# add a new disk
- name: emptydisk
disk:
bus: virtio
interfaces:
# prefer masquerade instead of default bridge
- masquerade: {}
name: default
networks:
- name: default
# prefer multus instead of pod network as first network
multus:
default: true
networkName: macvlan-test
volumes:
- name: emptydisk
# create a disk inside the VM Pod
# can also be backed by PVC, hotspath, etc...
emptyDisk:
capacity: 2Gi
# custom cloud config - additional disks starts at index 3
# because both boot and cloud-config disks are created by driver
# therefore example additional disk is named 'vd**c**'
user_data:
fs_setup:
- label: data_disk
filesystem: 'ext4'
device: /dev/vdc
overwrite: true
mounts:
- [ /dev/vdc, /var/lib/software, "auto", "defaults,nofail", "0", "0" ]
Please take a look at KubeVirt examples to get more information about more uses cases including PersistenVolumes, Multus, Multi node bridge, and more.
Run from inside Kubernetes cluster
You can run this driver with a container running tox and/or molecule. Take a look at:
Dockerfile as a base image
test-rolebinding file for ServiceAccount example
github_workflow in step named “Launch test” for a Kubernetes Job running tox
Demo
Testing nginx ansible role with KubeVirt, via github actions: jseguillon/ansible-role-nginx
Get Involved
Join us in the #ansible-molecule channel on Freenode.
Join the discussion in molecule-users Forum.
Join the community working group by checking the wiki.
Want to know about releases, subscribe to ansible-announce list.
For the full list of Ansible email Lists, IRC channels see the communication page.
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file molecule-kubevirt-0.0.5.tar.gz
.
File metadata
- Download URL: molecule-kubevirt-0.0.5.tar.gz
- Upload date:
- Size: 24.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5ad2aecaedee716bdedd58fb95f1809bc94ae6cf3e17798b95d135e8f4bfed7 |
|
MD5 | 0f919fd0b79ca1158bf118e3b6d85dcd |
|
BLAKE2b-256 | 718e7a37641fa85b8ba05ba12e914e78738777d3261319f4a789065ca0ef9b79 |
File details
Details for the file molecule_kubevirt-0.0.5-py3-none-any.whl
.
File metadata
- Download URL: molecule_kubevirt-0.0.5-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0bb1fea348ab18d17f34ed83495b17a28078520344d08967e0b65c8a73eedb67 |
|
MD5 | 8ef9e1b19866374f1b27aa3b3b2ff663 |
|
BLAKE2b-256 | 6459860cc65a0d0080a7133d8d224d3853e6d55ef67dbf1c504c841a2a27456f |