Skip to content

Commit

Permalink
Go stable (#39)
Browse files Browse the repository at this point in the history
All fields from VM spec are now supported.

Default domain, network and volume can be supercharged in easy to understand way.

Code clean + test cover supercharge mechanism

And also doc
  • Loading branch information
jseguillon authored Apr 29, 2022
1 parent 77583d4 commit d76e426
Show file tree
Hide file tree
Showing 14 changed files with 666 additions and 223 deletions.
52 changes: 44 additions & 8 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,21 @@ jobs:
- tox_env: lint
# - tox_env: docs
- tox_env: py36-ansible_2
PREFIX: PYTEST_REQPASS=2
PYTHON_BASE_IMAGE: python:3.6
KUBERNETES_VERSION: v1.22.2
- tox_env: py36-ansible_2-devel
PREFIX: PYTEST_REQPASS=2
PYTHON_BASE_IMAGE: python:3.6
KUBERNETES_VERSION: v1.22.2
- tox_env: py37-ansible_3
PREFIX: PYTEST_REQPASS=2
PYTHON_BASE_IMAGE: python:3.7
KUBERNETES_VERSION: v1.22.2
- tox_env: py38-ansible_4
PREFIX: PYTEST_REQPASS=2
PYTHON_BASE_IMAGE: python:3.8
KUBERNETES_VERSION: v1.22.2
- tox_env: py39-ansible_2
PREFIX: PYTEST_REQPASS=2
PYTHON_BASE_IMAGE: python:3.9
KUBERNETES_VERSION: v1.22.2
- tox_env: py39-ansible_2-devel
PREFIX: PYTEST_REQPASS=2
PYTHON_BASE_IMAGE: python:3.9
KUBERNETES_VERSION: v1.22.2
- tox_env: packaging
Expand Down Expand Up @@ -149,7 +143,7 @@ jobs:
if: ${{ contains(matrix.tox_env, 'py') }}

- name: Install virtcl
- name: Install KubeVirt virtcl
uses: nick-invision/retry@v2
with:
timeout_minutes: 5
Expand All @@ -161,6 +155,48 @@ jobs:
sudo install virtctl /usr/local/bin
if: ${{ contains(matrix.tox_env, 'py') }}

- name: Install KubeVirt's CDI
run: |
export VERSION=$(curl -s https://github.com/kubevirt/containerized-data-importer/releases/latest | grep -o "v[0-9]\.[0-9]*\.[0-9]*")
kubectl create -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-operator.yaml
kubectl create -f https://github.com/kubevirt/containerized-data-importer/releases/download/$VERSION/cdi-cr.yaml
- name: Install calico
run: |
kubectl apply -f https://projectcalico.docs.tigera.io/manifests/calico.yaml
echo "*******************************"
# FIXME activate wait for less flakyness
sleep 30 && kubectl -n kube-system set env daemonset/calico-node FELIX_IGNORELOOSERPF=true
- name: Install Multus and configure one net-attach
run: |
curl -Ls https://raw.githubusercontent.com/k8snetworkplumbingwg/multus-cni/master/deployments/multus-daemonset.yml | kubectl apply -f -
cat <<EOF | kubectl create -f -
---
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: macvlan-conf
spec:
config: '{
"cniVersion": "0.3.0",
"type": "macvlan",
"master": "eth0",
"mode": "bridge",
"ipam": {
"type": "host-local",
"subnet": "192.168.1.0/24",
"rangeStart": "192.168.1.200",
"rangeEnd": "192.168.1.216",
"routes": [
{ "dst": "0.0.0.0/0" }
],
"gateway": "192.168.1.1"
}
}'
EOF
- name: Build molecule test container for ${{ matrix.tox_env }}
run: |
eval $(minikube docker-env)
Expand Down Expand Up @@ -245,7 +281,7 @@ jobs:
args: ["(tox -e ${{ matrix.tox_env }} -c /opt/molecule_kubevirt/tox.ini ; kubectl create configmap molecule-result --from-literal exitCode=\$?); kubectl delete configmap molecule-job-running"]
env:
- name: PYTEST_REQPASS
value: "2"
value: "6"
restartPolicy: Never
backoffLimit: 0
EOF
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ repos:
- id: yamllint
files: \.(yaml|yml)$
types: [file, yaml]
exclude: 'molecule_kubevirt/test/refs/.*'
entry: yamllint --strict
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.790
Expand Down
143 changes: 90 additions & 53 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ Molecule KubeVirt Plugin

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**

.. _`KubeVirt`: https://kubevirt.io

Scope
Expand Down Expand Up @@ -130,66 +128,105 @@ Molecule then needs to be able to ssh on the ClusterIP ip:
Virtual machines customisation
==============================

Virtual machines can be customised using `domain`, `volumes`, `networks` and `user_data`.
A few defaults are created if not provided in platfom definition:

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.
* if no interface with :code:`name: default` is defined in :code:`domain.devices.interfaces`, then a default one is created with :code:`brige: {}` and :code:`bus: virtio`,
* if no disk with :code:`name: boot` is defined in :code:`domain.devices.disks`, then a default one is created with :code:`bus: virtio`,
* if no network with :code:`name: default` is defined in :code:`networks`, then a default one is created with :code:`pod: {}` and :code:`model: virtio`,
* if no volume with :code:`name: boot` is defined in :code:`volumes`, then a default one is created as:

* a :code:`containerDisk`
* with :code:`image`, :code:`path` and :code:`imagePullPolicy` respectively set to plaform :code:`image`, :code:`image_path` and :code:`image_pull_policy`

Full example
------------
* if cloud-config is defined in :code:`user_data` it is merged default one wich sets ssh public key for 'molecule' user.

VirtualMachines setup can be fine tuned:
Customisation example
---------------------

* `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 configuration demonstrates how to:

This example configures a specific network, adds a disk backed by an empty volume, then disk is formated and mounted via cloud config:
* use Kubevirt's CDI in place of an :code:`image` using :code:`dataVolumeTemplates` and overriding default :code:`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

.. code-block:: yaml
# 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.
---
dependency:
name: galaxy
driver:
name: kubevirt
platforms:
- name: instance
# annotate for calico static ip
annotations:
cni.projectcalico.org/ipAddrs: "[\"10.244.25.25\"]"
# use data volume facility in place of using 'image:'
dataVolumeTemplates:
- metadata:
name: disk-dv
spec:
pvc:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
preallocation: true
source:
http:
url: https://download.fedoraproject.org/pub/fedora/linux/releases/35/Cloud/x86_64/images/Fedora-Cloud-Base-35-1.2.x86_64.raw.xz
domain:
resources:
limits:
cpu: "1"
memory: 3Gi
requests:
cpu: 200m
memory: 1Gi
devices:
interfaces:
# add a second device interface
- bridge: {}
name: multus
model: virtio
ports:
- port: 22
disks:
# add a second device disk
- name: emptydisk
disk:
bus: virtio
volumes:
# override default 'boot' volume with cdi data volume template source
- name: boot
dataVolume:
name: disk-dv
# add a second volume, must be same name as defined in device
- name: emptydisk
emptyDisk:
capacity: 2Gi
networks:
# add a second network for added device interface
- name: multus
multus:
# use a NetworkAttachement
networkName: macvlan-conf
# cloud-config format and mount additional disk
user_data:
# format additional disk
fs_setup:
- label: data_disk
filesystem: 'ext4'
device: /dev/vdb
overwrite: true
# mount additional disk
mounts:
- [ /dev/vdb, /var/lib/software, "auto", "defaults,nofail", "0", "0" ]
See `molecule/tests/molecule.yml` from source code for full example.

Run from inside Kubernetes cluster
==================================
Expand Down
4 changes: 4 additions & 0 deletions molecule/tests/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
- name: Converge
hosts: all
gather_facts: false
123 changes: 123 additions & 0 deletions molecule/tests/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
dependency:
name: galaxy
driver:
name: kubevirt
platforms:
- name: instance-full
namespace: kube-public
# image: localhost:5001/kubevirt/fedora-cloud-container-disk-demo
autoattachGraphicsDevice: false
hostname: "myhost"
livenessProbe: ""
nodeSelector: ""
readinessProbe: ""
subdomain: "my-domain"
terminationGracePeriodSeconds: 30
tolerations: []
dataVolumeTemplates:
- metadata:
name: disk-dv-instance-full
spec:
pvc:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
preallocation: true
source:
http:
url: https://download.fedoraproject.org/pub/fedora/linux/releases/35/Cloud/x86_64/images/Fedora-Cloud-Base-35-1.2.x86_64.raw.xz
annotations:
cni.projectcalico.org/ipAddrs: "[\"10.244.25.25\"]"
domain:
resources:
limits:
cpu: "1"
memory: 3Gi
requests:
cpu: 200m
memory: 1Gi
devices:
interfaces:
# override default interface
- name: default
bridge: {}
model: e1000
ports:
- port: 22
# add another interface
- name: multus
bridge: {}
model: virtio
ports:
- port: 22
disks:
# override default boot device disk
- name: boot
disk:
bus: virtio
# add a second disk
- name: emptydisk
disk:
bus: virtio
volumes:
# override default boot volume
- name: boot
dataVolume:
name: disk-dv-instance-full
# add a second volume
- name: emptydisk
emptyDisk:
capacity: 2Gi
networks:
# override default network
- name: default
pod: {}
# add a second network
- name: multus
multus:
networkName: macvlan-conf
# custom cloud-config - see cloud-config doc
user_data:
# add a second user
users:
- name: user2
sudo: false
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDJRj9o4jhKW0Q6KnWa2jkThu/I070SJ+NBMDkP4ZXNu/t9Oq55Siz2dw6miwAjRVDfbB5HScM6XNJFWfPg10tY9ZUEizTirM5HeT8D+R5IvugfyqFeYs5d5V7X5O/TVJkNFUmqpA9TZYvoBUKsjnH4lH2/sPhtT13qUCLZNheUeQ==
# format additional disk
fs_setup:
- label: data_disk
filesystem: 'ext4'
device: /dev/vdb
overwrite: true
# mount additional disk
mounts:
- [ /dev/vdb, /var/lib/software, "auto", "defaults,nofail", "0", "0" ]
ssh_service:
type: NodePort
# custom cloud-config of molecule user - see cloud-config doc
user_molecule:
name: notmolecule
gecos: "dummy user"
plain_text_passwd: notmolecule
lock_passwd: false
# more authorized keys can be provided but the one created by driver is always inserted in the list
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDJRj9o4jhKW0Q6KnWa2jkThu/I070SJ+NBMDkP4ZXNu/t9Oq55Siz2dw6miwAjRVDfbB5HScM6XNJFWfPg10tY9ZUEizTirM5HeT8D+R5IvugfyqFeYs5d5V7X5O/TVJkNFUmqpA9TZYvoBUKsjnH4lH2/sPhtT13qUCLZNheUeQ==XXX
sudo:
- ALL=(ALL) NOPASSWD:/bin/mysql
# Use for creation test only: non running VMs specs can be tested without waiting ssh to be ready.
# Requires ssh_service to be activated since VM won't get IP from non created Pod
running: false

- name: instance-almost-default
ssh_service:
type: NodePort
running: false
provisioner:
name: ansible
verifier:
name: ansible
Loading

0 comments on commit d76e426

Please sign in to comment.