From 9161825af1392039164623d95da4cef88d5b9670 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Wed, 3 Oct 2018 15:23:58 +0200 Subject: [PATCH 01/14] Use ansible to generate the supported template matrix --- templates/generate.yaml | 18 ++++++ templates/templates/rhel75.tpl.yaml | 86 +++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 templates/generate.yaml create mode 100644 templates/templates/rhel75.tpl.yaml diff --git a/templates/generate.yaml b/templates/generate.yaml new file mode 100644 index 00000000..b3552ae5 --- /dev/null +++ b/templates/generate.yaml @@ -0,0 +1,18 @@ +--- +- connection: local + hosts: 127.0.0.1 + tasks: + - name: Generate RHEL templates + template: + src: rhel75.tpl.yaml + dest: "{{ playbook_dir }}/rhel75-{{ item.workload }}-{{ item.flavor }}.yaml" + with_items: + - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} + - {flavor: tiny, workload: highperformance, memsize: 1, cores: 1, iothreads: True} + - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} + - {flavor: small, workload: highperformance, memsize: 2, cores: 1, iothreads: True} + - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} + - {flavor: medium, workload: highperformance, memsize: 4, cores: 1, iothreads: True} + - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} + - {flavor: large, workload: highperformance, memsize: 8, cores: 2, iothreads: True} + diff --git a/templates/templates/rhel75.tpl.yaml b/templates/templates/rhel75.tpl.yaml new file mode 100644 index 00000000..9c9cf38e --- /dev/null +++ b/templates/templates/rhel75.tpl.yaml @@ -0,0 +1,86 @@ +apiVersion: v1 +kind: Template +metadata: + name: rhel-{{ item.flavor }}-{{ item.workload }} + 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/{{ item.workload }}: "true" + flavor.template.cnv.io/{{ item.flavor }}: "true" + template.cnv.io/type: "base" + +objects: +- apiVersion: kubevirt.io/v1alpha2 + kind: VirtualMachine + metadata: + name: ${NAME} + spec: + running: false + template: + spec: + domain: +{% if item.iothreads %} + ioThreadsPolicy: shared +{% endif %} + cpu: + cores: {{ item.cores }} + resources: + requests: + memory: {{ item.memsize }}G + 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-{{ item.flavor }}-[a-z0-9]{6}" +- name: PVCNAME + description: Name of the PVC with the disk image + required: true + From ca505c26136d684b0828448c3d106c412b92af18 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Thu, 4 Oct 2018 11:30:07 +0200 Subject: [PATCH 02/14] Prepare meta-templates for the major OSes --- templates/.gitignore | 1 + templates/fedora28.yaml | 86 ------------------ templates/generate.yaml | 78 ++++++++++++++++- templates/rhel75-hp.yaml | 87 ------------------- templates/rhel75.yaml | 84 ------------------ .../_linux.yaml} | 41 ++++----- templates/templates/fedora.tpl.yaml | 18 ++++ templates/templates/opensuse.tpl.yaml | 17 ++++ templates/templates/rhel7.tpl.yaml | 16 ++++ templates/templates/rhel75.tpl.yaml | 86 ------------------ templates/templates/ubuntu.tpl.yaml | 17 ++++ .../win2k12r2.tpl.yaml} | 13 ++- templates/ubuntu1804.yaml | 81 ----------------- 13 files changed, 165 insertions(+), 460 deletions(-) create mode 100644 templates/.gitignore delete mode 100644 templates/fedora28.yaml delete mode 100644 templates/rhel75-hp.yaml delete mode 100644 templates/rhel75.yaml rename templates/{opensuse15.yaml => templates/_linux.yaml} (63%) create mode 100644 templates/templates/fedora.tpl.yaml create mode 100644 templates/templates/opensuse.tpl.yaml create mode 100644 templates/templates/rhel7.tpl.yaml delete mode 100644 templates/templates/rhel75.tpl.yaml create mode 100644 templates/templates/ubuntu.tpl.yaml rename templates/{win2k12r2.yaml => templates/win2k12r2.tpl.yaml} (91%) delete mode 100644 templates/ubuntu1804.yaml diff --git a/templates/.gitignore b/templates/.gitignore new file mode 100644 index 00000000..a8b42eb6 --- /dev/null +++ b/templates/.gitignore @@ -0,0 +1 @@ +*.retry 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/generate.yaml b/templates/generate.yaml index b3552ae5..f6930018 100644 --- a/templates/generate.yaml +++ b/templates/generate.yaml @@ -4,8 +4,8 @@ tasks: - name: Generate RHEL templates template: - src: rhel75.tpl.yaml - dest: "{{ playbook_dir }}/rhel75-{{ item.workload }}-{{ item.flavor }}.yaml" + src: rhel7.tpl.yaml + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" with_items: - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - {flavor: tiny, workload: highperformance, memsize: 1, cores: 1, iothreads: True} @@ -15,4 +15,78 @@ - {flavor: medium, workload: highperformance, memsize: 4, cores: 1, iothreads: True} - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} - {flavor: large, workload: highperformance, memsize: 8, cores: 2, iothreads: True} + vars: + os: rhel7 + icon: rhel + password: redhat + oslabels: + - rhel7.0 + - rhel7.1 + - rhel7.2 + - rhel7.3 + - rhel7.4 + - rhel7.5 + + - name: Generate Fedora templates + template: + src: fedora.tpl.yaml + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" + with_items: + - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} + - {flavor: tiny, workload: highperformance, memsize: 1, cores: 1, iothreads: True} + - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} + - {flavor: small, workload: highperformance, memsize: 2, cores: 1, iothreads: True} + - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} + - {flavor: medium, workload: highperformance, memsize: 4, cores: 1, iothreads: True} + - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} + - {flavor: large, workload: highperformance, memsize: 8, cores: 2, iothreads: True} + vars: + os: fedora + icon: fedora + password: fedora + oslabels: + - fedora26 + - fedora27 + - fedora28 + + - name: Generate OpenSUSE templates + template: + src: opensuse.tpl.yaml + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" + with_items: + - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} + - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} + - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} + - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} + vars: + os: opensuse + icon: opensuse + password: opensuse + oslabels: + - opensuse15 + + - name: Generate Ubuntu templates + template: + src: ubuntu.tpl.yaml + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" + with_items: + - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} + - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} + - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} + - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} + vars: + cpumodel: Conroe + os: ubuntu + icon: ubuntu + password: ubuntu + oslabels: + - ubuntu1804 + + - name: Generate Windows templates + template: + src: win2k12r2.tpl.yaml + dest: "{{ playbook_dir }}/win2k12r2-{{ item.workload }}-{{ item.flavor }}.yaml" + with_items: + - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} + - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} 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/opensuse15.yaml b/templates/templates/_linux.yaml similarity index 63% rename from templates/opensuse15.yaml rename to templates/templates/_linux.yaml index bc54188e..1ca8a506 100644 --- a/templates/opensuse15.yaml +++ b/templates/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: @@ -46,10 +32,13 @@ objects: 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 +54,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/templates/fedora.tpl.yaml b/templates/templates/fedora.tpl.yaml new file mode 100644 index 00000000..f30c74c6 --- /dev/null +++ b/templates/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/templates/opensuse.tpl.yaml b/templates/templates/opensuse.tpl.yaml new file mode 100644 index 00000000..dec1f43d --- /dev/null +++ b/templates/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/templates/rhel7.tpl.yaml b/templates/templates/rhel7.tpl.yaml new file mode 100644 index 00000000..ccc58e58 --- /dev/null +++ b/templates/templates/rhel7.tpl.yaml @@ -0,0 +1,16 @@ +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. 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" + +{% include "_linux.yaml" %} + diff --git a/templates/templates/rhel75.tpl.yaml b/templates/templates/rhel75.tpl.yaml deleted file mode 100644 index 9c9cf38e..00000000 --- a/templates/templates/rhel75.tpl.yaml +++ /dev/null @@ -1,86 +0,0 @@ -apiVersion: v1 -kind: Template -metadata: - name: rhel-{{ item.flavor }}-{{ item.workload }} - 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/{{ item.workload }}: "true" - flavor.template.cnv.io/{{ item.flavor }}: "true" - template.cnv.io/type: "base" - -objects: -- apiVersion: kubevirt.io/v1alpha2 - kind: VirtualMachine - metadata: - name: ${NAME} - spec: - running: false - template: - spec: - domain: -{% if item.iothreads %} - ioThreadsPolicy: shared -{% endif %} - cpu: - cores: {{ item.cores }} - resources: - requests: - memory: {{ item.memsize }}G - 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-{{ item.flavor }}-[a-z0-9]{6}" -- name: PVCNAME - description: Name of the PVC with the disk image - required: true - diff --git a/templates/templates/ubuntu.tpl.yaml b/templates/templates/ubuntu.tpl.yaml new file mode 100644 index 00000000..4d8cda9e --- /dev/null +++ b/templates/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/win2k12r2.yaml b/templates/templates/win2k12r2.tpl.yaml similarity index 91% rename from templates/win2k12r2.yaml rename to templates/templates/win2k12r2.tpl.yaml index 05b96f66..1daf31cd 100644 --- a/templates/win2k12r2.yaml +++ b/templates/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 }}G features: acpi: {} apic: {} 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 From 8d75ad45e44dd9881fb515aadad0ef0f340bfa49 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Fri, 5 Oct 2018 12:33:42 +0200 Subject: [PATCH 03/14] Add dummy osinfo lookup plugin --- templates/generate.yaml | 1 + templates/lookup_plugins/osinfo.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 templates/lookup_plugins/osinfo.py diff --git a/templates/generate.yaml b/templates/generate.yaml index f6930018..b79ab7cc 100644 --- a/templates/generate.yaml +++ b/templates/generate.yaml @@ -26,6 +26,7 @@ - rhel7.3 - rhel7.4 - rhel7.5 + osinfo: "{{ lookup('osinfo', os) }}" - name: Generate Fedora templates template: diff --git a/templates/lookup_plugins/osinfo.py b/templates/lookup_plugins/osinfo.py new file mode 100644 index 00000000..a15db3df --- /dev/null +++ b/templates/lookup_plugins/osinfo.py @@ -0,0 +1,17 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import subprocess + +from ansible.errors import AnsibleError +from ansible.plugins.lookup import LookupBase + +class LookupModule(LookupBase): + def run(self, terms, variables, **kwargs): + ret = [] + for term in terms: + ret.append({ + "shortid": term, + }) + return ret + From a371e9c8039f660d18722958cc310d4256f780a6 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Fri, 5 Oct 2018 17:06:48 +0200 Subject: [PATCH 04/14] Implement osinfo lookup This adds osinfo lookup source that makes it possible to use libosinfo information in templates. There are two ways to reference an attribute: - object style - lookup().name - dict style - lookup()["name"] Arrays can be accessed using numerical indices like this: lookup('osinfo', 'fedora15')["minimum_resources.0.ram"] Beware though: Ansible has a bug [1] that makes it impossible to use this lookup source from Ansible files like this: "{{ lookup(..) }}". Ansible / Jinja2 always converts the result to AnsibleUnsafeText intead of keeping it in the original native type and that breaks the proxy used to access all the result attributes. [1] https://github.com/ansible/ansible/issues/34595#issuecomment-356091161 --- .gitmodules | 3 ++ osinfo-db | 1 + templates/generate.yaml | 12 +++-- templates/lookup_plugins/osinfo.py | 72 ++++++++++++++++++++++++++++-- templates/templates/_linux.yaml | 1 + 5 files changed, 83 insertions(+), 6 deletions(-) create mode 160000 osinfo-db 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/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/generate.yaml b/templates/generate.yaml index b79ab7cc..aa4279d8 100644 --- a/templates/generate.yaml +++ b/templates/generate.yaml @@ -26,7 +26,7 @@ - rhel7.3 - rhel7.4 - rhel7.5 - osinfo: "{{ lookup('osinfo', os) }}" + osinfoname: "{{ oslabels[0] }}" - name: Generate Fedora templates template: @@ -49,6 +49,7 @@ - fedora26 - fedora27 - fedora28 + osinfoname: "{{ oslabels[0] }}" - name: Generate OpenSUSE templates template: @@ -64,7 +65,8 @@ icon: opensuse password: opensuse oslabels: - - opensuse15 + - opensuse15.0 + osinfoname: "{{ oslabels[0] }}" - name: Generate Ubuntu templates template: @@ -81,7 +83,8 @@ icon: ubuntu password: ubuntu oslabels: - - ubuntu1804 + - ubuntu18.04 + osinfoname: "{{ oslabels[0] }}" - name: Generate Windows templates template: @@ -90,4 +93,7 @@ with_items: - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} + vars: + osinfoname: win2k12r2 + diff --git a/templates/lookup_plugins/osinfo.py b/templates/lookup_plugins/osinfo.py index a15db3df..40397f87 100644 --- a/templates/lookup_plugins/osinfo.py +++ b/templates/lookup_plugins/osinfo.py @@ -6,12 +6,78 @@ 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"): + return self._obj.get_length() > int(key) + 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) == 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): + 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: - ret.append({ - "shortid": term, - }) + 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/templates/templates/_linux.yaml b/templates/templates/_linux.yaml index 1ca8a506..4ecac8dc 100644 --- a/templates/templates/_linux.yaml +++ b/templates/templates/_linux.yaml @@ -26,6 +26,7 @@ objects: kind: VirtualMachine metadata: name: ${NAME} + osinfoname: {{ lookup('osinfo', osinfoname).name }} spec: running: false template: From 7752f5452ae28c31216c3f010c6d40fa98904f7b Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Tue, 9 Oct 2018 10:17:02 +0200 Subject: [PATCH 05/14] Add membership test to the osinfo proxy This code allows the following test: "name=virtio-scsi2" in os.all_devices The "name" string is the attribute that is being tested and the part after first equals sign (=) is the value we are looking for. --- templates/lookup_plugins/osinfo.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/templates/lookup_plugins/osinfo.py b/templates/lookup_plugins/osinfo.py index 40397f87..e47eaba6 100644 --- a/templates/lookup_plugins/osinfo.py +++ b/templates/lookup_plugins/osinfo.py @@ -30,13 +30,24 @@ 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"): - return self._obj.get_length() > int(key) + 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) == bool): + type(val) == str or type(val) == unicode or type(val) == bool): return val else: return self.__class__(val, root_path = path) @@ -58,6 +69,8 @@ def __getattr__(self, 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("."): From e25f94a94f1e6e7fcca2310764f962dad8a152c3 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Thu, 11 Oct 2018 14:00:19 +0200 Subject: [PATCH 06/14] Add CentOS 7 --- templates/generate.yaml | 19 ++++++++++++++++++- templates/templates/centos7.tpl.yaml | 15 +++++++++++++++ templates/templates/rhel7.tpl.yaml | 3 +-- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 templates/templates/centos7.tpl.yaml diff --git a/templates/generate.yaml b/templates/generate.yaml index aa4279d8..c20cd72e 100644 --- a/templates/generate.yaml +++ b/templates/generate.yaml @@ -2,7 +2,7 @@ - connection: local hosts: 127.0.0.1 tasks: - - name: Generate RHEL templates + - name: Generate RHEL 7 templates template: src: rhel7.tpl.yaml dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" @@ -28,6 +28,23 @@ - rhel7.5 osinfoname: "{{ oslabels[0] }}" + - name: Generate CentOS 7 templates + template: + src: centos7.tpl.yaml + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" + with_items: + - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} + - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} + - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} + - {flavor: large, workload: generic, memsize: 8, 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 diff --git a/templates/templates/centos7.tpl.yaml b/templates/templates/centos7.tpl.yaml new file mode 100644 index 00000000..b6bf21e3 --- /dev/null +++ b/templates/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/templates/rhel7.tpl.yaml b/templates/templates/rhel7.tpl.yaml index ccc58e58..1a6e397d 100644 --- a/templates/templates/rhel7.tpl.yaml +++ b/templates/templates/rhel7.tpl.yaml @@ -6,8 +6,7 @@ metadata: 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. + 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" From 6ad334b5f89be290cfba3765c80c1f6cbf20370a Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Thu, 11 Oct 2018 14:02:26 +0200 Subject: [PATCH 07/14] Ignore the generated files in git --- templates/.gitignore | 1 + templates/generate.yaml | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/templates/.gitignore b/templates/.gitignore index a8b42eb6..226b2ce3 100644 --- a/templates/.gitignore +++ b/templates/.gitignore @@ -1 +1,2 @@ *.retry +*.dist.yaml diff --git a/templates/generate.yaml b/templates/generate.yaml index c20cd72e..dc2b31f0 100644 --- a/templates/generate.yaml +++ b/templates/generate.yaml @@ -5,7 +5,7 @@ - name: Generate RHEL 7 templates template: src: rhel7.tpl.yaml - dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - {flavor: tiny, workload: highperformance, memsize: 1, cores: 1, iothreads: True} @@ -31,7 +31,7 @@ - name: Generate CentOS 7 templates template: src: centos7.tpl.yaml - dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} @@ -48,7 +48,7 @@ - name: Generate Fedora templates template: src: fedora.tpl.yaml - dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - {flavor: tiny, workload: highperformance, memsize: 1, cores: 1, iothreads: True} @@ -71,7 +71,7 @@ - name: Generate OpenSUSE templates template: src: opensuse.tpl.yaml - dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} @@ -88,7 +88,7 @@ - name: Generate Ubuntu templates template: src: ubuntu.tpl.yaml - dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.yaml" + dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} @@ -106,7 +106,7 @@ - name: Generate Windows templates template: src: win2k12r2.tpl.yaml - dest: "{{ playbook_dir }}/win2k12r2-{{ item.workload }}-{{ item.flavor }}.yaml" + dest: "{{ playbook_dir }}/win2k12r2-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} From 5ef90ac0777684f4d085fb26123ba34da8f91257 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Thu, 11 Oct 2018 14:02:47 +0200 Subject: [PATCH 08/14] Ignore python bytecode --- templates/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/.gitignore b/templates/.gitignore index 226b2ce3..f867a833 100644 --- a/templates/.gitignore +++ b/templates/.gitignore @@ -1,2 +1,3 @@ *.retry +*.pyc *.dist.yaml From 45e5b0c25684690657d9b0bf28c4f28fda9d10b4 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Thu, 11 Oct 2018 14:40:29 +0200 Subject: [PATCH 09/14] Update README to match the current template build and usage patterns --- README.md | 75 +++++++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 566730c5..e75274fa 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,61 @@ [![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/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. -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) [templates/generate.yaml](templates/generate.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: + +- 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.yaml + +# Pick a template by selecting +# - the guest OS - win2k12r2 +# - the workload type - generic +# - the size - medium + +# Use the template +$ oc process --local -f 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 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 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 win2k1r2-generic-medium.dist.yaml PVCNAME=mydisk | kubectl apply -f - virtualmachine.kubevirt.io/windows2012r2-rt1ap2 created $ @@ -50,15 +63,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](templates/generate.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/templates/win2k12r2.tpl.yaml) | +| Fedora 28 | [fedora](templates/templates/fedora.tpl.yaml) | +| Red Hat Enterprise Linux 7.5 | [rhel7](templates/templates/rhel7.tpl.yaml) | +| Ubuntu 18.04 LTS | [ubuntu](templates/templates/ubuntu.tpl.yaml) | +| OpenSUSE Leap 15.0 (no CI) | [opensuse](templates/templates/opensuse.tpl.yaml) | +| Cent OS 7 | [centos7](templates/templates/centos7.tpl.yaml) | From 0c7a929416573777beb8d81dc9499c3985720ab1 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Thu, 11 Oct 2018 17:42:02 +0200 Subject: [PATCH 10/14] Configure CI to test generated templates --- .travis.yml | 20 ++++++++++++++----- README.md | 3 ++- makefile | 57 ++++++++++++++++++++++++++++++----------------------- 3 files changed, 49 insertions(+), 31 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5e53405d..8828bcb6 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 @@ -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 e75274fa..f7539c6c 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,9 @@ Every template consists of a VirtualMachine definition which can be used to laun # Requirements -Is it necessary to install the following components to be able to run the Ansible generator: +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 diff --git a/makefile b/makefile index 70688b33..dce35940 100644 --- a/makefile +++ b/makefile @@ -1,12 +1,14 @@ SHELL=/bin/bash # i.e. fedora28.yaml -ALL_TEMPLATES=$(wildcard templates/*.yaml) +ALL_META_TEMPLATES=$(wildcard templates/templates/*.yaml) +ALL_TEMPLATES=$(wildcard templates/*.dist.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:templates/%.dist.yaml=%) # Make sure the version is defined VERSION=unknown @@ -15,22 +17,22 @@ 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 opensuse-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) +common-templates.yaml: generate $(SOURCES) ( \ echo -n "# Version " ; \ git describe --always --tags HEAD ; \ @@ -57,32 +59,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: templates/generate.yaml $(METASOURCES) + pushd templates && ansible-playbook generate.yaml && popd -%-apply-and-remove: templates/%.yaml - oc process --local -f "templates/$*.yaml" NAME=$@ PVCNAME=$@-pvc | \ +%-syntax-check: templates/%.dist.yaml + oc process --local -f "templates/$*.dist.yaml" NAME=$@ PVCNAME=$*-pvc + +%-apply-and-remove: templates/%.dist.yaml + oc process --local -f "templates/$*.dist.yaml" NAME=$@ PVCNAME=$*-pvc | \ kubectl apply -f - - oc process --local -f "templates/$*.yaml" NAME=$@ PVCNAME=$@-pvc | \ + oc process --local -f "templates/$*.dist.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 "templates/$*.dist.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 "templates/$*.dist.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 "templates/$*.dist.yaml" NAME=$* PVCNAME=$* | \ kubectl delete -f - pvs: $(TESTABLE_GUESTS:%=%.pv) @@ -91,7 +96,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 +113,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 From f5bfe6e38e79ee5cda7ef6a1320da455d403c0cb Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Fri, 12 Oct 2018 11:21:16 +0200 Subject: [PATCH 11/14] Fix memory sizes --- templates/generate.yaml | 60 +++++++++++++------------- templates/templates/win2k12r2.tpl.yaml | 2 +- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/templates/generate.yaml b/templates/generate.yaml index dc2b31f0..d40e4ed2 100644 --- a/templates/generate.yaml +++ b/templates/generate.yaml @@ -7,14 +7,14 @@ src: rhel7.tpl.yaml dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - - {flavor: tiny, workload: highperformance, memsize: 1, cores: 1, iothreads: True} - - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} - - {flavor: small, workload: highperformance, memsize: 2, cores: 1, iothreads: True} - - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} - - {flavor: medium, workload: highperformance, memsize: 4, cores: 1, iothreads: True} - - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} - - {flavor: large, workload: highperformance, memsize: 8, cores: 2, iothreads: True} + - {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 @@ -33,10 +33,10 @@ src: centos7.tpl.yaml dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} - - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} - - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} + - {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 @@ -50,14 +50,14 @@ src: fedora.tpl.yaml dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - - {flavor: tiny, workload: highperformance, memsize: 1, cores: 1, iothreads: True} - - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} - - {flavor: small, workload: highperformance, memsize: 2, cores: 1, iothreads: True} - - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} - - {flavor: medium, workload: highperformance, memsize: 4, cores: 1, iothreads: True} - - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} - - {flavor: large, workload: highperformance, memsize: 8, cores: 2, iothreads: True} + - {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 @@ -73,10 +73,10 @@ src: opensuse.tpl.yaml dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} - - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} - - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} + - {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 @@ -90,10 +90,10 @@ src: ubuntu.tpl.yaml dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - - {flavor: tiny, workload: generic, memsize: 1, cores: 1, iothreads: False} - - {flavor: small, workload: generic, memsize: 2, cores: 1, iothreads: False} - - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} - - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} + - {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 @@ -108,8 +108,8 @@ src: win2k12r2.tpl.yaml dest: "{{ playbook_dir }}/win2k12r2-{{ item.workload }}-{{ item.flavor }}.dist.yaml" with_items: - - {flavor: medium, workload: generic, memsize: 4, cores: 1, iothreads: False} - - {flavor: large, workload: generic, memsize: 8, cores: 2, iothreads: False} + - {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/templates/templates/win2k12r2.tpl.yaml b/templates/templates/win2k12r2.tpl.yaml index 1daf31cd..e0fd6add 100644 --- a/templates/templates/win2k12r2.tpl.yaml +++ b/templates/templates/win2k12r2.tpl.yaml @@ -59,7 +59,7 @@ objects: cores: {{ item.cores }} resources: requests: - memory: {{ item.memsize }}G + memory: {{ item.memsize }} features: acpi: {} apic: {} From 7732515f473e09818ee9e7b7651f2c8a585e34ae Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Tue, 16 Oct 2018 10:13:41 +0200 Subject: [PATCH 12/14] Directory structure rethinked --- .travis.yml | 2 +- README.md | 28 ++++++------- .../generate.yaml => generate-templates.yaml | 17 +++++--- .../osinfo.py | 2 +- makefile | 39 ++++++++++--------- templates/{templates => }/_linux.yaml | 0 templates/{templates => }/centos7.tpl.yaml | 0 templates/{templates => }/fedora.tpl.yaml | 0 templates/{templates => }/opensuse.tpl.yaml | 0 templates/{templates => }/rhel7.tpl.yaml | 0 templates/{templates => }/ubuntu.tpl.yaml | 0 templates/{templates => }/win2k12r2.tpl.yaml | 0 12 files changed, 47 insertions(+), 41 deletions(-) rename templates/generate.yaml => generate-templates.yaml (85%) rename {templates/lookup_plugins => lookup_plugins}/osinfo.py (98%) rename templates/{templates => }/_linux.yaml (100%) rename templates/{templates => }/centos7.tpl.yaml (100%) rename templates/{templates => }/fedora.tpl.yaml (100%) rename templates/{templates => }/opensuse.tpl.yaml (100%) rename templates/{templates => }/rhel7.tpl.yaml (100%) rename templates/{templates => }/ubuntu.tpl.yaml (100%) rename templates/{templates => }/win2k12r2.tpl.yaml (100%) diff --git a/.travis.yml b/.travis.yml index 8828bcb6..23aa0efe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,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: diff --git a/README.md b/README.md index f7539c6c..e592f995 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ A set of (meta-)Templates to create KubeVirt VMs. 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. -The VM templates are generated from [meta-templates](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 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/). -The [Ansible playbook](https://docs.ansible.com/ansible/latest/user_guide/playbooks.html) [templates/generate.yaml](templates/generate.yaml) describes all combinations that should be generated. +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. Every template consists of a VirtualMachine definition which can be used to launch the guest, if a disk image is available (see below). @@ -36,7 +36,7 @@ $ git submodule init update # Generate the template matrix $ pushd common-templates/templates -$ ansible-playbook generate.yaml +$ ansible-playbook generate-templates.yaml # Pick a template by selecting # - the guest OS - win2k12r2 @@ -44,19 +44,19 @@ $ ansible-playbook generate.yaml # - the size - medium # Use the template -$ oc process --local -f win2k1r2-generic-medium.dist.yaml +$ 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 win2k1r2-generic-medium.dist.yaml --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 win2k1r2-generic-medium.dist.yaml PVCNAME=mydisk +$ oc process --local -f dist/templates/win2k1r2-generic-medium.dist.yaml PVCNAME=mydisk … -$ oc process --local -f win2k1r2-generic-medium.dist.yaml PVCNAME=mydisk | kubectl apply -f - +$ oc process --local -f dist/templates/win2k1r2-generic-medium.dist.yaml PVCNAME=mydisk | kubectl apply -f - virtualmachine.kubevirt.io/windows2012r2-rt1ap2 created $ @@ -64,7 +64,7 @@ $ # 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](templates/generate.yaml) to prepare the properly parametrized templates first. +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 @@ -72,9 +72,9 @@ The table below lists the guest operating systems that are covered by the templa | Guest OS | Meta-template | |---|---| -| Microsoft Windows Server 2012 R2 (no CI) | [win2k12r2](templates/templates/win2k12r2.tpl.yaml) | -| Fedora 28 | [fedora](templates/templates/fedora.tpl.yaml) | -| Red Hat Enterprise Linux 7.5 | [rhel7](templates/templates/rhel7.tpl.yaml) | -| Ubuntu 18.04 LTS | [ubuntu](templates/templates/ubuntu.tpl.yaml) | -| OpenSUSE Leap 15.0 (no CI) | [opensuse](templates/templates/opensuse.tpl.yaml) | -| Cent OS 7 | [centos7](templates/templates/centos7.tpl.yaml) | +| 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/templates/generate.yaml b/generate-templates.yaml similarity index 85% rename from templates/generate.yaml rename to generate-templates.yaml index d40e4ed2..b823d4a9 100644 --- a/templates/generate.yaml +++ b/generate-templates.yaml @@ -2,10 +2,15 @@ - 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 }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.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} @@ -31,7 +36,7 @@ - name: Generate CentOS 7 templates template: src: centos7.tpl.yaml - dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.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} @@ -48,7 +53,7 @@ - name: Generate Fedora templates template: src: fedora.tpl.yaml - dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.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} @@ -71,7 +76,7 @@ - name: Generate OpenSUSE templates template: src: opensuse.tpl.yaml - dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.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} @@ -88,7 +93,7 @@ - name: Generate Ubuntu templates template: src: ubuntu.tpl.yaml - dest: "{{ playbook_dir }}/{{ os }}-{{ item.workload }}-{{ item.flavor }}.dist.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} @@ -106,7 +111,7 @@ - name: Generate Windows templates template: src: win2k12r2.tpl.yaml - dest: "{{ playbook_dir }}/win2k12r2-{{ item.workload }}-{{ item.flavor }}.dist.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} diff --git a/templates/lookup_plugins/osinfo.py b/lookup_plugins/osinfo.py similarity index 98% rename from templates/lookup_plugins/osinfo.py rename to lookup_plugins/osinfo.py index e47eaba6..e8fea863 100644 --- a/templates/lookup_plugins/osinfo.py +++ b/lookup_plugins/osinfo.py @@ -12,7 +12,7 @@ loader = osinfo.Loader() #loader.process_default_path() -loader.process_path("../osinfo-db/data") +loader.process_path("osinfo-db/data") db = loader.get_db() class OsInfoGObjectProxy(object): diff --git a/makefile b/makefile index dce35940..b75fb604 100644 --- a/makefile +++ b/makefile @@ -1,14 +1,13 @@ SHELL=/bin/bash # i.e. fedora28.yaml -ALL_META_TEMPLATES=$(wildcard templates/templates/*.yaml) -ALL_TEMPLATES=$(wildcard templates/*.dist.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/%.dist.yaml=%) +ALL_GUESTS=$(ALL_TEMPLATES:dist/templates/%.yaml=%) # Make sure the version is defined VERSION=unknown @@ -32,20 +31,22 @@ unit-tests: $(TEST_UNIT:%=%-generated-name-apply-and-remove) functional-tests: generate is-deployed functional-tests: $(TEST_FUNCTIONAL:%=%-start-wait-for-systemd-and-stop) -common-templates.yaml: generate $(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" @@ -59,26 +60,26 @@ gather-env-of-%: is-deployed: kubectl api-versions | grep kubevirt.io -generate: templates/generate.yaml $(METASOURCES) - pushd templates && ansible-playbook generate.yaml && popd +generate: generate-templates.yaml $(METASOURCES) + ansible-playbook generate-templates.yaml -%-syntax-check: templates/%.dist.yaml - oc process --local -f "templates/$*.dist.yaml" NAME=$@ PVCNAME=$*-pvc +%-syntax-check: dist/templates/%.yaml + oc process --local -f "dist/templates/$*.yaml" NAME=$@ PVCNAME=$*-pvc -%-apply-and-remove: templates/%.dist.yaml - oc process --local -f "templates/$*.dist.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/$*.dist.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/$*.dist.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/$*.dist.yaml" NAME=$* PVCNAME=$* | \ + oc process --local -f "dist/templates/$*.yaml" NAME=$* PVCNAME=$* | \ kubectl apply -f - virtctl start $* $(TRAVIS_FOLD_START) @@ -87,7 +88,7 @@ generate: templates/generate.yaml $(METASOURCES) $(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/$*.dist.yaml" NAME=$* PVCNAME=$* | \ + oc process --local -f "dist/templates/$*.yaml" NAME=$* PVCNAME=$* | \ kubectl delete -f - pvs: $(TESTABLE_GUESTS:%=%.pv) diff --git a/templates/templates/_linux.yaml b/templates/_linux.yaml similarity index 100% rename from templates/templates/_linux.yaml rename to templates/_linux.yaml diff --git a/templates/templates/centos7.tpl.yaml b/templates/centos7.tpl.yaml similarity index 100% rename from templates/templates/centos7.tpl.yaml rename to templates/centos7.tpl.yaml diff --git a/templates/templates/fedora.tpl.yaml b/templates/fedora.tpl.yaml similarity index 100% rename from templates/templates/fedora.tpl.yaml rename to templates/fedora.tpl.yaml diff --git a/templates/templates/opensuse.tpl.yaml b/templates/opensuse.tpl.yaml similarity index 100% rename from templates/templates/opensuse.tpl.yaml rename to templates/opensuse.tpl.yaml diff --git a/templates/templates/rhel7.tpl.yaml b/templates/rhel7.tpl.yaml similarity index 100% rename from templates/templates/rhel7.tpl.yaml rename to templates/rhel7.tpl.yaml diff --git a/templates/templates/ubuntu.tpl.yaml b/templates/ubuntu.tpl.yaml similarity index 100% rename from templates/templates/ubuntu.tpl.yaml rename to templates/ubuntu.tpl.yaml diff --git a/templates/templates/win2k12r2.tpl.yaml b/templates/win2k12r2.tpl.yaml similarity index 100% rename from templates/templates/win2k12r2.tpl.yaml rename to templates/win2k12r2.tpl.yaml From 97652aaf964f93a185077593a02fd5c6bbc43c0b Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Tue, 16 Oct 2018 16:03:57 +0200 Subject: [PATCH 13/14] Add description header to the osinfo lookup plugin file --- lookup_plugins/osinfo.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lookup_plugins/osinfo.py b/lookup_plugins/osinfo.py index e8fea863..6f286310 100644 --- a/lookup_plugins/osinfo.py +++ b/lookup_plugins/osinfo.py @@ -1,3 +1,12 @@ +# 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 From 9b79948086de3147077c45d527253a1ecd153833 Mon Sep 17 00:00:00 2001 From: Martin Sivak Date: Tue, 16 Oct 2018 17:51:16 +0200 Subject: [PATCH 14/14] Do not test OpenSUSE --- makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile b/makefile index b75fb604..3c49e419 100644 --- a/makefile +++ b/makefile @@ -16,7 +16,7 @@ VERSION=unknown TEST_SYNTAX=$(ALL_GUESTS) TEST_UNIT=$(ALL_GUESTS) ifeq ($(TEST_FUNCTIONAL),ALL) -TEST_FUNCTIONAL=fedora-generic-small ubuntu-generic-small opensuse-generic-small rhel7-generic-small centos7-generic-small +TEST_FUNCTIONAL=fedora-generic-small ubuntu-generic-small rhel7-generic-small centos7-generic-small endif