Skip to content

Commit

Permalink
Merge pull request #26 from MarSik/meta-templating
Browse files Browse the repository at this point in the history
Meta templating
  • Loading branch information
MarSik authored Oct 18, 2018
2 parents b0a3457 + 9b79948 commit e04bd6f
Show file tree
Hide file tree
Showing 19 changed files with 436 additions and 438 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "ci"]
path = ci
url = https://github.com/fabiand/traviskube/
[submodule "osinfo-db"]
path = osinfo-db
url = https://gitlab.com/libosinfo/osinfo-db.git
22 changes: 16 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sudo: required
dist: xenial
language: go
language: python
branches:
only:
- master
Expand All @@ -18,15 +18,19 @@ jobs:
script: bash -x test.sh

- name: Functional test of the Fedora template
env: TARGET=functional-tests TEST_FUNCTIONAL=fedora28
env: TARGET=functional-tests TEST_FUNCTIONAL=fedora-generic-small
script: bash -x test.sh

- name: Functional test of the Ubuntu template
env: TARGET=functional-tests TEST_FUNCTIONAL=ubuntu1804
env: TARGET=functional-tests TEST_FUNCTIONAL=ubuntu-generic-small
script: bash -x test.sh

- name: Functional test of the CentOS/RHEL template
env: TARGET=functional-tests TEST_FUNCTIONAL=rhel75
- name: Functional test of the RHEL template
env: TARGET=functional-tests TEST_FUNCTIONAL=rhel7-generic-small
script: bash -x test.sh

- name: Functional test of the CentOS template
env: TARGET=functional-tests TEST_FUNCTIONAL=centos7-generic-small
script: bash -x test.sh

- stage: Build and Deploy
Expand All @@ -37,7 +41,7 @@ jobs:
provider: releases
api_key:
secure: "TKxavkyq4h4xmH5hLCMbl2w9gceWh9InTY9xomxrZM8DkhLozjeUCRXn6YubnPnI9V23iemLHucUMV/mIwxT3m3iU+L6IwIdl1E1SdYKGwWUvW5ZfMjYI2A1NEVCiR7yyRoo0rhMd7v00gavgAY9UhUhIerR/CduFqbyfik/Qvy80m6+XZ1D099Em+4uWlzZ9qBVHSj7kdEbhDlV2rvqd9A6sA/qO+eg+jdzirB2T5sRvNs0eSpoKl2M1qPRBilbeA7DWXvkHsA5LJlOuNO0p6DW/+vqMxXpKBE1BsfQQzHReCCrSi0CkM+1uPzbKDPYKHXkWFfwQP8s6mZf4pPx2EVmiuZ7nKtB+y1hUoTnaIQs0IdsOMzPJvTNC+5DMnldMn1+8uDzIXrPkxfPCC6z9vc4eenuBWuNR/3SVzWkmoB+JpsvMNC2+rCX7SB8yy93T9PlfyOBRnckKzr2YZmxcArGvLzb+wVHwukzmIyQYLq4pxjgMhh1BWMdobLPYhTgj1s1pWqgNnam54bdK+OLVt72Xh0VHVtPSZHrmtyE5m+Ifzz+DUu9NKeCdgzxNq+KrOmf9q3xn8iUYPOIbbI67tmWYaQ/UB6nGd2Np2dOGlhfAFau11Q9d8X2U/IKBn0u725cj/a/yaRYzATSzd2xJo29BYE8I0KTJq5pVaTAMzg="
file: "common-templates-$TRAVIS_TAG.yaml"
file: "dist/common-templates-$TRAVIS_TAG.yaml"
skip_cleanup: true
name: $TRAVIS_TAG
on:
Expand All @@ -51,9 +55,15 @@ cache:
- "~/.minikube/cache"
addons:
apt:
sources:
- sourceline: 'ppa:ansible/ansible'
packages:
- qemu-utils
- jq
- ansible
- python-gobject
- libosinfo-1.0
- gir1.2-libosinfo-1.0
before_script:
- sudo mount --make-rshared /
- bash -x ci/prepare-host $CPLATFORM $CVER
Expand Down
76 changes: 46 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,80 @@
[![Build Status](https://travis-ci.com/kubevirt/common-templates.svg?branch=master)](https://travis-ci.com/kubevirt/common-templates)

A set of Templates to create KubeVirt VMs.
A set of (meta-)Templates to create KubeVirt VMs.

# Overview

All VMs are provided as [OpenShift templates](https://docs.okd.io/latest/dev_guide/templates.html).
These templates can be used straight forward with OpenShift itself, or they
can be transformed into regular objects for use with Kubernetes.
This repository provides VM templates in the form compatible with [OpenShift templates](https://docs.okd.io/latest/dev_guide/templates.html) and kubevirt UI and those can further be transformed into regular objects for use with plain Kubernetes.

Every template consists of two objects:
The VM templates are generated from [meta-templates](templates/) via [Ansible](https://www.ansible.com/) and [libosinfo](https://libosinfo.org/). The generated templates are parametrized according to three aspects: the guest OS, the workload type and the size. The generated content is stored in [dist/](dist/).

1. A VirtualMachineInstancePreset definition for the specific guest, this is
comparable to a "flavor"
2. A VirtualMachine definition which can be used to launch the guest, if a disk
image is available (see below)
The [Ansible playbook](https://docs.ansible.com/ansible/latest/user_guide/playbooks.html) [generate-templates.yaml](generate-templates.yaml) describes all combinations that should be generated.

The presets allow to keep all the guest specific machine configuration in a
single place. This configuration is applied to the VMs once they are started.
Every template consists of a VirtualMachine definition which can be used to launch the guest, if a disk image is available (see below).

# Requirements

Is it necessary to install the following components to be able to run the Ansible generator and the CI suite:

- jq
- ansible >= 2.4
- libosinfo
- python-gobject

# Usage

By default the snippets below from the table will fetch the template and
process it. It fails if a parameter (like the PVC name) is required, but not
provided. In such a case the parameter is appended to the snippet, i.e.
`PVCNAME`.
By default the process below takes a generated template and converts it to an VM object that can be used to start a virtual machine.
The conversion fails if a parameter (like the PVC name) is required, but not
provided (i.e.`PVCNAME`).

```bash
# Define the generic instance types:
$ kubectl apply -f https://raw.githubusercontent.com/fabiand/common-templates/master/presets/instancetypes.yaml
# Clone the repository
$ git clone https://github.com/kubevirt/common-templates

# Pull all submodules
$ git submodule init update

$ oc process --local -f https://git.io/fNp4Z
The Template "win2k12r2" is invalid: template.parameters[1]: Required value:
# Generate the template matrix
$ pushd common-templates/templates
$ ansible-playbook generate-templates.yaml

# Pick a template by selecting
# - the guest OS - win2k12r2
# - the workload type - generic
# - the size - medium

# Use the template
$ oc process --local -f dist/templates/win2k1r2-generic-medium.dist.yaml
The Template "win2k1r2-generic-medium" is invalid: template.parameters[1]: Required value:
template.parameters[1]: parameter PVCNAME is required and must be specified

$ oc process --local -f https://git.io/fNp4Z --parameters
$ oc process --local -f dist/templates/win2k1r2-generic-medium.dist.yaml --parameters
NAME DESCRIPTION GENERATOR VALUE
NAME Name of the new VM expression windows2012r2-[a-z0-9]{6}
PVCNAME Name of the PVC with the disk image

$ oc process --local -f https://git.io/fNp4Z PVCNAME=mydisk
$ oc process --local -f dist/templates/win2k1r2-generic-medium.dist.yaml PVCNAME=mydisk

$ oc process --local -f https://git.io/fNp4Z PVCNAME=mydisk | kubectl apply -f -
virtualmachineinstancepreset.kubevirt.io/win2k12r2 created
$ oc process --local -f dist/templates/win2k1r2-generic-medium.dist.yaml PVCNAME=mydisk | kubectl apply -f -
virtualmachine.kubevirt.io/windows2012r2-rt1ap2 created

$
```

# Templates

The table below lists the guest operating systems that are covered by the templates. The meta-templates are not directly consumable, please use the [generator](generate-templates.yaml) to prepare the properly parametrized templates first.

> **Note:** The templates are tuned for a specific guest version, but is often
> usable with different versions as well, i.e. the Fedora 28 template is also
> usable with Fedora 27 or 26.
| Template | Snippet |
| Guest OS | Meta-template |
|---|---|
| Microsoft Windows Server 2012 R2 (no CI) | [`oc process --local -f https://git.io/fNp4Z`](templates/win2k12r2.yaml) |
| Fedora 28 | [`oc process --local -f https://git.io/fNpBU`](templates/fedora28.yaml) |
| Red Hat Enterprise Linux 7.5 | [`oc process --local -f https://git.io/fNpuq`](templates/rhel75.yaml) |
| Ubuntu 18.04 LTS | [`oc process --local -f https://git.io/fA4q5`](templates/ubuntu1804.yaml) |
| OpenSUSE Leap 15.0 (no CI) | [`oc process --local -f https://git.io/fNpz2`](templates/opensuse15.yaml) |
| CoreOS Container Linux | TBD |
| Microsoft Windows Server 2012 R2 (no CI) | [win2k12r2](templates/win2k12r2.tpl.yaml) |
| Fedora 28 | [fedora](templates/fedora.tpl.yaml) |
| Red Hat Enterprise Linux 7.5 | [rhel7](templates/rhel7.tpl.yaml) |
| Ubuntu 18.04 LTS | [ubuntu](templates/ubuntu.tpl.yaml) |
| OpenSUSE Leap 15.0 (no CI) | [opensuse](templates/opensuse.tpl.yaml) |
| Cent OS 7 | [centos7](templates/centos7.tpl.yaml) |
121 changes: 121 additions & 0 deletions generate-templates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
- connection: local
hosts: 127.0.0.1
tasks:
- name: Prepare dist directory
file:
path: "{{ playbook_dir }}/dist/templates"
state: directory

- name: Generate RHEL 7 templates
template:
src: rhel7.tpl.yaml
dest: "{{ playbook_dir }}/dist/templates/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml"
with_items:
- {flavor: tiny, workload: generic, memsize: "1G", cores: 1, iothreads: False}
- {flavor: tiny, workload: highperformance, memsize: "1G", cores: 1, iothreads: True}
- {flavor: small, workload: generic, memsize: "2G", cores: 1, iothreads: False}
- {flavor: small, workload: highperformance, memsize: "2G", cores: 1, iothreads: True}
- {flavor: medium, workload: generic, memsize: "4G", cores: 1, iothreads: False}
- {flavor: medium, workload: highperformance, memsize: "4G", cores: 1, iothreads: True}
- {flavor: large, workload: generic, memsize: "8G", cores: 2, iothreads: False}
- {flavor: large, workload: highperformance, memsize: "8G", cores: 2, iothreads: True}
vars:
os: rhel7
icon: rhel
password: redhat
oslabels:
- rhel7.0
- rhel7.1
- rhel7.2
- rhel7.3
- rhel7.4
- rhel7.5
osinfoname: "{{ oslabels[0] }}"

- name: Generate CentOS 7 templates
template:
src: centos7.tpl.yaml
dest: "{{ playbook_dir }}/dist/templates/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml"
with_items:
- {flavor: tiny, workload: generic, memsize: "1G", cores: 1, iothreads: False}
- {flavor: small, workload: generic, memsize: "2G", cores: 1, iothreads: False}
- {flavor: medium, workload: generic, memsize: "4G", cores: 1, iothreads: False}
- {flavor: large, workload: generic, memsize: "8G", cores: 2, iothreads: False}
vars:
os: centos7
icon: centos
password: centos
oslabels:
- centos7.0
osinfoname: "{{ oslabels[0] }}"

- name: Generate Fedora templates
template:
src: fedora.tpl.yaml
dest: "{{ playbook_dir }}/dist/templates/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml"
with_items:
- {flavor: tiny, workload: generic, memsize: "1G", cores: 1, iothreads: False}
- {flavor: tiny, workload: highperformance, memsize: "1G", cores: 1, iothreads: True}
- {flavor: small, workload: generic, memsize: "2G", cores: 1, iothreads: False}
- {flavor: small, workload: highperformance, memsize: "2G", cores: 1, iothreads: True}
- {flavor: medium, workload: generic, memsize: "4G", cores: 1, iothreads: False}
- {flavor: medium, workload: highperformance, memsize: "4G", cores: 1, iothreads: True}
- {flavor: large, workload: generic, memsize: "8G", cores: 2, iothreads: False}
- {flavor: large, workload: highperformance, memsize: "8G", cores: 2, iothreads: True}
vars:
os: fedora
icon: fedora
password: fedora
oslabels:
- fedora26
- fedora27
- fedora28
osinfoname: "{{ oslabels[0] }}"

- name: Generate OpenSUSE templates
template:
src: opensuse.tpl.yaml
dest: "{{ playbook_dir }}/dist/templates/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml"
with_items:
- {flavor: tiny, workload: generic, memsize: "1G", cores: 1, iothreads: False}
- {flavor: small, workload: generic, memsize: "2G", cores: 1, iothreads: False}
- {flavor: medium, workload: generic, memsize: "4G", cores: 1, iothreads: False}
- {flavor: large, workload: generic, memsize: "8G", cores: 2, iothreads: False}
vars:
os: opensuse
icon: opensuse
password: opensuse
oslabels:
- opensuse15.0
osinfoname: "{{ oslabels[0] }}"

- name: Generate Ubuntu templates
template:
src: ubuntu.tpl.yaml
dest: "{{ playbook_dir }}/dist/templates/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml"
with_items:
- {flavor: tiny, workload: generic, memsize: "1G", cores: 1, iothreads: False}
- {flavor: small, workload: generic, memsize: "2G", cores: 1, iothreads: False}
- {flavor: medium, workload: generic, memsize: "4G", cores: 1, iothreads: False}
- {flavor: large, workload: generic, memsize: "8G", cores: 2, iothreads: False}
vars:
cpumodel: Conroe
os: ubuntu
icon: ubuntu
password: ubuntu
oslabels:
- ubuntu18.04
osinfoname: "{{ oslabels[0] }}"

- name: Generate Windows templates
template:
src: win2k12r2.tpl.yaml
dest: "{{ playbook_dir }}/dist/templates/win2k12r2-{{ item.workload }}-{{ item.flavor }}.yaml"
with_items:
- {flavor: medium, workload: generic, memsize: "4G", cores: 1, iothreads: False}
- {flavor: large, workload: generic, memsize: "8G", cores: 2, iothreads: False}
vars:
osinfoname: win2k12r2


Loading

0 comments on commit e04bd6f

Please sign in to comment.