diff --git a/.gitmodules b/.gitmodules index 2624f31c..967507bb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/.travis.yml b/.travis.yml index 5e53405d..23aa0efe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ sudo: required dist: xenial -language: go +language: python branches: only: - master @@ -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 @@ -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: @@ -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 diff --git a/README.md b/README.md index 566730c5..e592f995 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,62 @@ [![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 $ @@ -50,15 +64,17 @@ $ # 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) | diff --git a/generate-templates.yaml b/generate-templates.yaml new file mode 100644 index 00000000..b823d4a9 --- /dev/null +++ b/generate-templates.yaml @@ -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 + + diff --git a/lookup_plugins/osinfo.py b/lookup_plugins/osinfo.py new file mode 100644 index 00000000..6f286310 --- /dev/null +++ b/lookup_plugins/osinfo.py @@ -0,0 +1,105 @@ +# This is an Ansible / Jinja2 lookup plugin +# that allows querying the libosinfo database +# +# Example usage: +# {{ lookup('osinfo', 'fedora15')["minimum_resources.0.ram"] }} +# {% if "name=virtio-scsi2" in lookup('osinfo', 'fedora15').all_devices %} +# +# The code is distributed under the Apache 2 license + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import subprocess + +from ansible.errors import AnsibleError +from ansible.plugins.lookup import LookupBase + +import gi +gi.require_version('Libosinfo', '1.0') +from gi.repository import Libosinfo as osinfo + +loader = osinfo.Loader() +#loader.process_default_path() +loader.process_path("osinfo-db/data") +db = loader.get_db() + +class OsInfoGObjectProxy(object): + def __str__(self): + return "<%s @ %s obj=%s>" % (self.__class__.__name__, self._root_path, str(self._obj)) + + def __init__(self, obj, root_path=""): + self._obj = obj + self._root_path = root_path + + def __bool__(self): + return bool(self._obj) + + def __contains__(self, key): + if hasattr(self._obj, "get_" + str(key)): + return True + elif hasattr(self._obj, "get_length") and hasattr(self._obj, "get_nth"): + if type(key) == int or type(key) == long: + return self._obj.get_length() > int(key) + elif type(key) == str or type(key) == unicode: + conditions = [v.split("=", 1) for v in key.split(",")] + conditions = {v[0] : v[1] for v in conditions} + matches = 0 + for idx in range(self._obj.get_length()): + obj = self.__class__(self._obj.get_nth(idx), + self._root_path + "." + str(idx)) + if all([obj[k] == v for k,v in conditions.items()]): + matches += 1 + return matches > 0 + else: + return False + + def _resolve(self, val, path): + if (type(val) == int or type(val) == long or type(val) == float or + type(val) == str or type(val) == unicode or type(val) == bool): + return val + else: + return self.__class__(val, root_path = path) + + def _get(self, root, root_path, idx): + if hasattr(root, "get_" + str(idx)): + return getattr(root, "get_" + str(idx))() + elif hasattr(root, "get_length") and hasattr(root, "get_nth"): + if root.get_length() <= int(idx): + raise IndexError("%s[%s]" % (self._obj, root_path + "." + idx)) + else: + return root.get_nth(int(idx)) + else: + raise AttributeError("%s[%s]" % (self._obj, root_path + "." + idx)) + + def __getattr__(self, name): + root = self._obj + root = self._get(root, self._root_path + "." + name, name) + return self._resolve(root, self._root_path + "." + name) + + def __getitem__(self, idx): + if type(idx) == int or type(idx) == long: + idx = str(idx) + root = self._obj + root_path = [self._root_path] + for i in idx.split("."): + root_path.append(i) + root = self._get(root, ".".join(root_path), i) + return self._resolve(root, ".".join(root_path)) + +class LookupModule(LookupBase): + def run(self, terms, variables, **kwargs): + ret = [] + for term in terms: + filter = osinfo.Filter() + filter.add_constraint(osinfo.PRODUCT_PROP_SHORT_ID, term) + oses = db.get_os_list().new_filtered(filter) + if oses.get_length() > 0: + os = OsInfoGObjectProxy(oses.get_nth(0), root_path = "[" + term + "]") + ret.append(os) + else: + ret.append({"name": term}) + + return ret + +# vim: sw=4 sts=4 et diff --git a/makefile b/makefile index 70688b33..3c49e419 100644 --- a/makefile +++ b/makefile @@ -1,12 +1,13 @@ SHELL=/bin/bash # i.e. fedora28.yaml -ALL_TEMPLATES=$(wildcard templates/*.yaml) +ALL_META_TEMPLATES=$(wildcard templates/*.yaml) +ALL_TEMPLATES=$(wildcard dist/templates/*.yaml) ALL_PRESETS=$(wildcard presets/*.yaml) -SOURCES=$(ALL_TEMPLATES) $(ALL_PRESETS) +METASOURCES=$(ALL_META_TEMPLATES) $(ALL_PRESETS) # i.e. fedora28 -ALL_GUESTS=$(ALL_TEMPLATES:templates/%.yaml=%) +ALL_GUESTS=$(ALL_TEMPLATES:dist/templates/%.yaml=%) # Make sure the version is defined VERSION=unknown @@ -15,35 +16,37 @@ VERSION=unknown TEST_SYNTAX=$(ALL_GUESTS) TEST_UNIT=$(ALL_GUESTS) ifeq ($(TEST_FUNCTIONAL),ALL) -TEST_FUNCTIONAL=fedora28 ubuntu1804 opensuse15 rhel75 +TEST_FUNCTIONAL=fedora-generic-small ubuntu-generic-small rhel7-generic-small centos7-generic-small endif test: syntax-tests unit-tests functional-tests -syntax-tests: $(TEST_SYNTAX:%=%-syntax-check) +syntax-tests: generate $(TEST_SYNTAX:%=%-syntax-check) -unit-tests: is-deployed +unit-tests: generate is-deployed unit-tests: $(TEST_UNIT:%=%-apply-and-remove) unit-tests: $(TEST_UNIT:%=%-generated-name-apply-and-remove) -functional-tests: is-deployed +functional-tests: generate is-deployed functional-tests: $(TEST_FUNCTIONAL:%=%-start-wait-for-systemd-and-stop) -common-templates.yaml: $(SOURCES) +dist/templates/%.yaml: generate + +dist/common-templates.yaml: generate ( \ echo -n "# Version " ; \ git describe --always --tags HEAD ; \ - for F in $(SOURCES) ; \ + for F in $(ALL_PRESETS) dist/templates/*.yaml; \ do \ echo "---" ; \ echo "# Source: $$F" ; \ cat $$F ; \ done ; \ - ) | tee $@ + ) >$@ -release: common-templates.yaml - cp common-templates.yaml common-templates-$(VERSION).yaml +release: dist/common-templates.yaml + cp dist/common-templates.yaml dist/common-templates-$(VERSION).yaml TRAVIS_FOLD_START=echo -e "travis_fold:start:details\033[33;1mDetails\033[0m" TRAVIS_FOLD_END=echo -e "\ntravis_fold:end:details\r" @@ -57,32 +60,35 @@ gather-env-of-%: is-deployed: kubectl api-versions | grep kubevirt.io -%-syntax-check: templates/%.yaml - oc process --local -f "templates/$*.yaml" NAME=$@ PVCNAME=$@-pvc +generate: generate-templates.yaml $(METASOURCES) + ansible-playbook generate-templates.yaml + +%-syntax-check: dist/templates/%.yaml + oc process --local -f "dist/templates/$*.yaml" NAME=$@ PVCNAME=$*-pvc -%-apply-and-remove: templates/%.yaml - oc process --local -f "templates/$*.yaml" NAME=$@ PVCNAME=$@-pvc | \ +%-apply-and-remove: dist/templates/%.yaml + oc process --local -f "dist/templates/$*.yaml" NAME=$@ PVCNAME=$*-pvc | \ kubectl apply -f - - oc process --local -f "templates/$*.yaml" NAME=$@ PVCNAME=$@-pvc | \ + oc process --local -f "dist/templates/$*.yaml" NAME=$@ PVCNAME=$*-pvc | \ kubectl delete -f - %-generated-name-apply-and-remove: - oc process --local -f "templates/$*.yaml" PVCNAME=$@-pvc > $@.yaml + oc process --local -f "dist/templates/$*.yaml" PVCNAME=$*-pvc > $@.yaml kubectl apply -f $@.yaml kubectl delete -f $@.yaml rm -v $@.yaml %-start-wait-for-systemd-and-stop: %.pvc - oc process --local -f "templates/$*.yaml" NAME=$@ PVCNAME=$* | \ + oc process --local -f "dist/templates/$*.yaml" NAME=$* PVCNAME=$* | \ kubectl apply -f - - virtctl start $@ + virtctl start $* $(TRAVIS_FOLD_START) - while ! kubectl get vmi $@ -o yaml | grep "phase: Running" ; do make gather-env-of-$@ ; sleep 3; done - make gather-env-of-$@ + while ! kubectl get vmi $* -o yaml | grep "phase: Running" ; do make gather-env-of-$* ; sleep 3; done + make gather-env-of-$* $(TRAVIS_FOLD_END) # Wait for a pretty universal magic word - virtctl console --timeout=5 $@ | tee /dev/stderr | egrep -m 1 "Welcome|systemd" - oc process --local -f "templates/$*.yaml" NAME=$@ PVCNAME=$* | \ + virtctl console --timeout=5 $* | tee /dev/stderr | egrep -m 1 "Welcome|systemd" + oc process --local -f "dist/templates/$*.yaml" NAME=$* PVCNAME=$* | \ kubectl delete -f - pvs: $(TESTABLE_GUESTS:%=%.pv) @@ -91,7 +97,9 @@ raws: $(TESTABLE_GUESTS:%=%.raw) %.pvc: %.pv kubectl get pvc $* -%.pv: %.raw +# fedora-generic-small.pv will use fedora.raw +.SECONDEXPANSION: +%.pv: $$(firstword $$(subst -, ,$$@)).raw $(TRAVIS_FOLD_START) SIZEMB=$$(( $$(qemu-img info $< --output json | jq '.["virtual-size"]') / 1024 / 1024 + 128 )) && \ mkdir -p "$$PWD/pvs/$*" && \ @@ -106,23 +114,23 @@ raws: $(TESTABLE_GUESTS:%=%.raw) %.raw: %.qcow2 qemu-img convert -p -O raw $< $@ -fedora28.qcow2: +fedora.qcow2: curl -L -o $@ https://download.fedoraproject.org/pub/fedora/linux/releases/28/Cloud/x86_64/images/Fedora-Cloud-Base-28-1.1.x86_64.qcow2 -ubuntu1804.qcow2: +ubuntu.qcow2: curl -L -o $@ http://cloud-images.ubuntu.com/bionic/current/bionic-server-cloudimg-amd64.img -opensuse15.qcow2: +opensuse.qcow2: curl -L -o $@ https://download.opensuse.org/repositories/Cloud:/Images:/Leap_15.0/images/openSUSE-Leap-15.0-OpenStack.x86_64-0.0.4-Buildlp150.12.12.qcow2 centos7.qcow2: curl -L http://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2.xz | xz -d > $@ # For now we test the RHEL75 template with the CentOS image -rhel75.raw: centos7.raw +rhel7.raw: centos7.raw ln $< $@ clean: rm -v *.raw *.qcow2 -.PHONY: all test release common-templates.yaml +.PHONY: all test generate release diff --git a/osinfo-db b/osinfo-db new file mode 160000 index 00000000..6c147fc7 --- /dev/null +++ b/osinfo-db @@ -0,0 +1 @@ +Subproject commit 6c147fc74267725d6c98139f6e5a1208bf55154d diff --git a/templates/.gitignore b/templates/.gitignore new file mode 100644 index 00000000..f867a833 --- /dev/null +++ b/templates/.gitignore @@ -0,0 +1,3 @@ +*.retry +*.pyc +*.dist.yaml diff --git a/templates/opensuse15.yaml b/templates/_linux.yaml similarity index 63% rename from templates/opensuse15.yaml rename to templates/_linux.yaml index bc54188e..4ecac8dc 100644 --- a/templates/opensuse15.yaml +++ b/templates/_linux.yaml @@ -1,19 +1,4 @@ -apiVersion: v1 -kind: Template -metadata: - name: opensuse15 - annotations: - openshift.io/display-name: "OpenSUSE Leap 15.0 VM" - description: >- - This template can be used to create a VM suitable for - OpenSUSE Leap 15.0. - The template assumes that a PVC is available which is providing the - necessary OpenSUSE disk image. - - Recommended disk image (needs to be converted to raw) - https://download.opensuse.org/repositories/Cloud:/Images:/Leap_15.0/images/ - tags: "kubevirt,virtualmachine,linux,opensuse" - iconClass: "icon-fedora" + iconClass: "icon-{{ icon }}" openshift.io/provider-display-name: "KubeVirt" openshift.io/documentation-url: "https://github.com/kubevirt/common-templates" openshift.io/support-url: "https://github.com/kubevirt/common-templates/issues" @@ -29,10 +14,11 @@ metadata: /objects[0].spec.template.spec.networks labels: - os.template.cnv.io/opensuse15.0: "true" - workload.template.cnv.io/server: "true" - workload.template.cnv.io/desktop: "true" - flavor.template.cnv.io/small: "true" +{% for osl in oslabels %} + os.template.cnv.io/{{ osl }}: "true" +{% endfor %} + workload.template.cnv.io/{{ item.workload }}: "true" + flavor.template.cnv.io/{{ item.flavor }}: "true" template.cnv.io/type: "base" objects: @@ -40,16 +26,20 @@ objects: kind: VirtualMachine metadata: name: ${NAME} + osinfoname: {{ lookup('osinfo', osinfoname).name }} spec: running: false template: spec: domain: cpu: - cores: 2 + cores: {{ item.cores }} +{% if cpumodel |default("") %} + model: {{ cpumodel }} +{% endif %} resources: requests: - memory: 2G + memory: {{ item.memsize }} devices: rng: {} disks: @@ -65,15 +55,15 @@ objects: - cloudInitNoCloud: userData: |- #cloud-config - password: opensuse + password: {{ password }} chpasswd: { expire: False } name: cloudinitvolume parameters: -- name: NAME - description: VM name +- description: VM name + from: '{{ os }}-[A-Za-z0-9]{16}' generate: expression - from: "opensuse15-[a-z0-9]{6}" + name: NAME - name: PVCNAME description: Name of the PVC with the disk image required: true diff --git a/templates/centos7.tpl.yaml b/templates/centos7.tpl.yaml new file mode 100644 index 00000000..b6bf21e3 --- /dev/null +++ b/templates/centos7.tpl.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Template +metadata: + name: {{ os }}-{{ item.workload }}-{{ item.flavor }} + annotations: + openshift.io/display-name: "CentOS 7.0+ VM" + description: >- + This template can be used to create a VM suitable for + CentOS 7 and newer. + The template assumes that a PVC is available which is providing the + necessary CentOS disk image. + tags: "kubevirt,virtualmachine,linux,centos" + +{% include "_linux.yaml" %} + diff --git a/templates/fedora.tpl.yaml b/templates/fedora.tpl.yaml new file mode 100644 index 00000000..f30c74c6 --- /dev/null +++ b/templates/fedora.tpl.yaml @@ -0,0 +1,18 @@ +apiVersion: v1 +kind: Template +metadata: + name: {{ os }}-{{ item.workload }}-{{ item.flavor }} + annotations: + openshift.io/display-name: "Fedora 23+ VM" + description: >- + This template can be used to create a VM suitable for + Fedora 23 and newer. + The template assumes that a PVC is available which is providing the + necessary Fedora disk image. + + Recommended disk image (needs to be converted to raw) + https://download.fedoraproject.org/pub/fedora/linux/releases/28/Cloud/x86_64/images/Fedora-Cloud-Base-28-1.1.x86_64.qcow2 + tags: "kubevirt,virtualmachine,fedora,rhel" + +{% include "_linux.yaml" %} + diff --git a/templates/fedora28.yaml b/templates/fedora28.yaml deleted file mode 100644 index c8a79212..00000000 --- a/templates/fedora28.yaml +++ /dev/null @@ -1,86 +0,0 @@ -apiVersion: v1 -kind: Template -metadata: - name: fedora-generic - annotations: - openshift.io/display-name: "Fedora 23+ VM" - description: >- - This template can be used to create a VM suitable for - Fedora 23 and newer. - The template assumes that a PVC is available which is providing the - necessary Fedora disk image. - - Recommended disk image (needs to be converted to raw) - https://download.fedoraproject.org/pub/fedora/linux/releases/28/Cloud/x86_64/images/Fedora-Cloud-Base-28-1.1.x86_64.qcow2 - tags: "kubevirt,virtualmachine,fedora,rhel" - iconClass: "icon-fedora" - openshift.io/provider-display-name: "KubeVirt" - openshift.io/documentation-url: "https://github.com/kubevirt/common-templates" - openshift.io/support-url: "https://github.com/kubevirt/common-templates/issues" - template.openshift.io/bindable: "false" - - template.cnv.io/version: v1alpha1 - defaults.template.cnv.io/disk: rootdisk - template.cnv.io/editable: | - /objects[0].spec.template.spec.domain.cpu.cores - /objects[0].spec.template.spec.domain.resources.requests.memory - /objects[0].spec.template.spec.domain.devices.disks - /objects[0].spec.template.spec.volumes - /objects[0].spec.template.spec.networks - - labels: - os.template.cnv.io/fedora29: "true" - os.template.cnv.io/fedora28: "true" - os.template.cnv.io/fedora27: "true" - os.template.cnv.io/fedora26: "true" - os.template.cnv.io/fedora25: "true" - os.template.cnv.io/fedora24: "true" - os.template.cnv.io/fedora23: "true" - workload.template.cnv.io/server: "true" - workload.template.cnv.io/desktop: "true" - flavor.template.cnv.io/small: "true" - template.cnv.io/type: "base" - -objects: -- apiVersion: kubevirt.io/v1alpha2 - kind: VirtualMachine - metadata: - name: ${NAME} - spec: - running: false - template: - spec: - domain: - cpu: - cores: 2 - resources: - requests: - memory: 2G - devices: - rng: {} - disks: - - disk: - bus: virtio - name: rootdisk - volumeName: rootvolume - terminationGracePeriodSeconds: 0 - volumes: - - name: rootvolume - persistentVolumeClaim: - claimName: ${PVCNAME} - - cloudInitNoCloud: - userData: |- - #cloud-config - password: fedora - chpasswd: { expire: False } - name: cloudinitvolume - -parameters: -- description: VM name - from: '[A-Za-z0-9]{1,16}' - generate: expression - name: NAME -- name: PVCNAME - description: Name of the PVC with the disk image - required: true - diff --git a/templates/opensuse.tpl.yaml b/templates/opensuse.tpl.yaml new file mode 100644 index 00000000..dec1f43d --- /dev/null +++ b/templates/opensuse.tpl.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Template +metadata: + name: {{ os }}-{{ item.workload }}-{{ item.flavor }} + annotations: + openshift.io/display-name: "OpenSUSE Leap 15.0 VM" + description: >- + This template can be used to create a VM suitable for + OpenSUSE Leap 15.0. + The template assumes that a PVC is available which is providing the + necessary OpenSUSE disk image. + + Recommended disk image (needs to be converted to raw) + https://download.opensuse.org/repositories/Cloud:/Images:/Leap_15.0/images/ + tags: "kubevirt,virtualmachine,linux,opensuse" + +{% include "_linux.yaml" %} diff --git a/templates/rhel7.tpl.yaml b/templates/rhel7.tpl.yaml new file mode 100644 index 00000000..1a6e397d --- /dev/null +++ b/templates/rhel7.tpl.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Template +metadata: + name: {{ os }}-{{ item.workload }}-{{ item.flavor }} + annotations: + openshift.io/display-name: "Red Hat Enterprise Linux 7.0+ VM" + description: >- + This template can be used to create a VM suitable for + Red Hat Enterprise Linux 7 and newer. + The template assumes that a PVC is available which is providing the + necessary RHEL disk image. + tags: "kubevirt,virtualmachine,linux,rhel" + +{% include "_linux.yaml" %} + diff --git a/templates/rhel75-hp.yaml b/templates/rhel75-hp.yaml deleted file mode 100644 index 9d68fa62..00000000 --- a/templates/rhel75-hp.yaml +++ /dev/null @@ -1,87 +0,0 @@ -apiVersion: v1 -kind: Template -metadata: - name: rhel-high-performance - annotations: - openshift.io/display-name: "Red Hat Enterprise Linux 7.0+ VM High Performance" - description: >- - This template can be used to create a VM suitable for - Red Hat Enterprise Linux 7 and newer and sets configuration - for high performance. That means for example CPU passhtrough, - CPU pinning and disabled graphics device. - The template assumes that a PVC is available which is providing the - necessary RHEL disk image. - tags: "kubevirt,virtualmachine,linux,rhel,high-performance" - iconClass: "icon-rhel" - openshift.io/provider-display-name: "KubeVirt" - openshift.io/documentation-url: "https://github.com/kubevirt/common-templates" - openshift.io/support-url: "https://github.com/kubevirt/common-templates/issues" - template.openshift.io/bindable: "false" - - template.cnv.io/version: v1alpha1 - defaults.template.cnv.io/disk: rootdisk - template.cnv.io/editable: | - /objects[0].spec.template.spec.domain.cpu.cores - /objects[0].spec.template.spec.domain.resources.requests.memory - /objects[0].spec.template.spec.domain.devices.disks - /objects[0].spec.template.spec.volumes - /objects[0].spec.template.spec.networks - - labels: - os.template.cnv.io/rhel7.0: "true" - os.template.cnv.io/rhel7.1: "true" - os.template.cnv.io/rhel7.2: "true" - os.template.cnv.io/rhel7.3: "true" - os.template.cnv.io/rhel7.4: "true" - os.template.cnv.io/rhel7.5: "true" - workload.template.cnv.io/high-performance: "true" - flavor.template.cnv.io/medium: "true" - template.cnv.io/type: "base" - -objects: -- apiVersion: kubevirt.io/v1alpha2 - kind: VirtualMachine - metadata: - name: ${NAME} - spec: - running: false - template: - spec: - domain: - ioThreadsPolicy: shared - cpu: - cores: 2 - dedicatedCpuPlacement: "true" - model: host-model - resources: - requests: - memory: 4G - devices: - autoattachGraphicsDevice: false - rng: {} - disks: - - disk: - bus: virtio - name: rootdisk - volumeName: rootvolume - terminationGracePeriodSeconds: 0 - volumes: - - name: rootvolume - persistentVolumeClaim: - claimName: ${PVCNAME} - - cloudInitNoCloud: - userData: |- - #cloud-config - password: redhat - chpasswd: { expire: False } - name: cloudinitvolume - -parameters: -- description: Name of the new VM - from: '[A-Za-z0-9]{1,16}' - generate: expression - name: NAME -- name: PVCNAME - description: Name of the PVC with the disk image - required: true - diff --git a/templates/rhel75.yaml b/templates/rhel75.yaml deleted file mode 100644 index 35776d7d..00000000 --- a/templates/rhel75.yaml +++ /dev/null @@ -1,84 +0,0 @@ -apiVersion: v1 -kind: Template -metadata: - name: rhel-generic - annotations: - openshift.io/display-name: "Red Hat Enterprise Linux 7.0+ VM" - description: >- - This template can be used to create a VM suitable for - Red Hat Enterprise Linux 7 and newer. This template - can also be used for CentOS based VMs. - The template assumes that a PVC is available which is providing the - necessary RHEL disk image. - tags: "kubevirt,virtualmachine,linux,rhel" - iconClass: "icon-rhel" - openshift.io/provider-display-name: "KubeVirt" - openshift.io/documentation-url: "https://github.com/kubevirt/common-templates" - openshift.io/support-url: "https://github.com/kubevirt/common-templates/issues" - template.openshift.io/bindable: "false" - - template.cnv.io/version: v1alpha1 - defaults.template.cnv.io/disk: rootdisk - template.cnv.io/editable: | - /objects[0].spec.template.spec.domain.cpu.cores - /objects[0].spec.template.spec.domain.resources.requests.memory - /objects[0].spec.template.spec.domain.devices.disks - /objects[0].spec.template.spec.volumes - /objects[0].spec.template.spec.networks - - labels: - os.template.cnv.io/centos7.0: "true" - os.template.cnv.io/rhel7.0: "true" - os.template.cnv.io/rhel7.1: "true" - os.template.cnv.io/rhel7.2: "true" - os.template.cnv.io/rhel7.3: "true" - os.template.cnv.io/rhel7.4: "true" - os.template.cnv.io/rhel7.5: "true" - workload.template.cnv.io/server: "true" - workload.template.cnv.io/desktop: "true" - flavor.template.cnv.io/small: "true" - template.cnv.io/type: "base" - -objects: -- apiVersion: kubevirt.io/v1alpha2 - kind: VirtualMachine - metadata: - name: ${NAME} - spec: - running: false - template: - spec: - domain: - cpu: - cores: 2 - resources: - requests: - memory: 2G - devices: - rng: {} - disks: - - disk: - bus: virtio - name: rootdisk - volumeName: rootvolume - terminationGracePeriodSeconds: 0 - volumes: - - name: rootvolume - persistentVolumeClaim: - claimName: ${PVCNAME} - - cloudInitNoCloud: - userData: |- - #cloud-config - password: redhat - chpasswd: { expire: False } - name: cloudinitvolume - -parameters: -- name: NAME - description: VM name - generate: expression - from: "rhel75-[a-z0-9]{6}" -- name: PVCNAME - description: Name of the PVC with the disk image - required: true - diff --git a/templates/ubuntu.tpl.yaml b/templates/ubuntu.tpl.yaml new file mode 100644 index 00000000..4d8cda9e --- /dev/null +++ b/templates/ubuntu.tpl.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Template +metadata: + name: {{ os }}-{{ item.workload }}-{{ item.flavor }} + annotations: + openshift.io/display-name: "Ubuntu 18.04 (Xenial Xerus) VM" + description: >- + This template can be used to create a VM suitable for + Ubuntu 18.04 (Xenial Xerus). + The template assumes that a PVC is available which is providing the + necessary Ubuntu disk image. + + Recommended disk image (needs to be converted to raw) + http://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img + tags: "kubevirt,virtualmachine,ubuntu" + +{% include "_linux.yaml" %} diff --git a/templates/ubuntu1804.yaml b/templates/ubuntu1804.yaml deleted file mode 100644 index 360ddc0a..00000000 --- a/templates/ubuntu1804.yaml +++ /dev/null @@ -1,81 +0,0 @@ -apiVersion: v1 -kind: Template -metadata: - name: ubuntu1804 - annotations: - openshift.io/display-name: "Ubuntu 18.04 (Xenial Xerus) VM" - description: >- - This template can be used to create a VM suitable for - Ubuntu 18.04 (Xenial Xerus). - The template assumes that a PVC is available which is providing the - necessary Ubuntu disk image. - - Recommended disk image (needs to be converted to raw) - http://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-disk1.img - tags: "kubevirt,virtualmachine,ubuntu" - iconClass: "icon-ubuntu" - openshift.io/provider-display-name: "KubeVirt" - openshift.io/documentation-url: "https://github.com/kubevirt/common-templates" - openshift.io/support-url: "https://github.com/kubevirt/common-templates/issues" - template.openshift.io/bindable: "false" - - template.cnv.io/version: v1alpha1 - defaults.template.cnv.io/disk: rootdisk - template.cnv.io/editable: | - /objects[0].spec.template.spec.domain.cpu.cores - /objects[0].spec.template.spec.domain.resources.requests.memory - /objects[0].spec.template.spec.domain.devices.disks - /objects[0].spec.template.spec.volumes - /objects[0].spec.template.spec.networks - - labels: - os.template.cnv.io/ubuntu18.04: "true" - workload.template.cnv.io/server: "true" - workload.template.cnv.io/desktop: "true" - flavor.template.cnv.io/small: "true" - template.cnv.io/type: "base" - -objects: -- apiVersion: kubevirt.io/v1alpha2 - kind: VirtualMachine - metadata: - name: ${NAME} - spec: - running: false - template: - spec: - domain: - cpu: - cores: 2 - model: Conroe - devices: - rng: {} - resources: - requests: - memory: 2G - devices: - disks: - - disk: - bus: virtio - name: rootdisk - volumeName: rootvolume - terminationGracePeriodSeconds: 0 - volumes: - - name: rootvolume - persistentVolumeClaim: - claimName: ${PVCNAME} - - cloudInitNoCloud: - userData: |- - #cloud-config - password: ubuntu - chpasswd: { expire: False } - name: cloudinitvolume -parameters: -- name: NAME - description: Name of the new VM - generate: expression - from: "ubuntu1804-[a-z0-9]{6}" - required: true -- name: PVCNAME - description: Name of the PVC with the disk image - required: true diff --git a/templates/win2k12r2.yaml b/templates/win2k12r2.tpl.yaml similarity index 91% rename from templates/win2k12r2.yaml rename to templates/win2k12r2.tpl.yaml index 05b96f66..e0fd6add 100644 --- a/templates/win2k12r2.yaml +++ b/templates/win2k12r2.tpl.yaml @@ -1,7 +1,7 @@ apiVersion: v1 kind: Template metadata: - name: win2k12r2 + name: win2k12r2-{{ item.workload }}-{{ item.flavor }} annotations: openshift.io/display-name: "Microsoft Windows Server 2012 R2 VM" description: >- @@ -31,17 +31,14 @@ metadata: os.template.cnv.io/win2k8r2: "true" os.template.cnv.io/win2k8: "true" os.template.cnv.io/win10: "true" - workload.template.cnv.io/server: "true" - workload.template.cnv.io/desktop: "true" - flavor.template.cnv.io/medium: "true" + workload.template.cnv.io/{{ item.workload }}: "true" + flavor.template.cnv.io/{{ item.flavor }}: "true" template.cnv.io/type: "base" objects: - apiVersion: kubevirt.io/v1alpha2 kind: VirtualMachine metadata: - labels: - kubevirt.io/os: win2k12r2 name: ${NAME} spec: running: false @@ -59,10 +56,10 @@ objects: tickPolicy: catchup hyperv: {} cpu: - cores: 2 + cores: {{ item.cores }} resources: requests: - memory: 4G + memory: {{ item.memsize }} features: acpi: {} apic: {}