From 183f26c0484920b3d2cd451b9528fc80f61ec5ef Mon Sep 17 00:00:00 2001 From: "Crank, Daniel (dc6350)" Date: Tue, 2 Mar 2021 10:33:25 -0600 Subject: [PATCH] Integrate vino-builder This patchset integrates vino-builder into the vino manager daemonset. See corresponding vino changes in [0]. [0] https://review.opendev.org/c/airship/vino/+/778209 Change-Id: I860ffef6275aca9d10a20abf79c1a25455ff3717 --- vino-builder/Makefile | 113 ++++++++++++++++++ vino-builder/assets/entrypoint.sh | 8 +- .../roles/libvirt/library/core_allocation.py | 9 +- .../roles/libvirt/tasks/create-domain.yaml | 20 ++-- .../roles/libvirt/tasks/create-network.yaml | 4 +- .../playbooks/roles/libvirt/tasks/main.yml | 1 + 6 files changed, 140 insertions(+), 15 deletions(-) create mode 100644 vino-builder/Makefile diff --git a/vino-builder/Makefile b/vino-builder/Makefile new file mode 100644 index 0000000..5cce445 --- /dev/null +++ b/vino-builder/Makefile @@ -0,0 +1,113 @@ +# Copyright 2021 AT&T Intellectual Property. All other rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SHELL := /bin/bash +BUILD_DIR ?= build +PUSH_IMAGE ?= false +IMAGE_ID ?= none +COMMIT ?= $(shell git rev-parse HEAD) +LABEL ?= org.airshipit.build=community +IMAGE_NAME ?= vino-builder +DOCKER_REGISTRY ?= quay.io +IMAGE_PREFIX ?= airshipit +IMAGE_TAG ?= latest +DISTRO ?= ubuntu_bionic +IMAGE := ${DOCKER_REGISTRY}/${IMAGE_PREFIX}/${IMAGE_NAME}:${IMAGE_TAG}-${DISTRO} +SH_TO_CHECK := $(wildcard files/*.sh ) +PROXY ?= http://proxy.foo.com:8000 +NO_PROXY ?= localhost,127.0.0.1,.svc.cluster.local +USE_PROXY ?= false + +all: lint images + +check-docker: + @if [ -z $$(which docker) ]; then \ + echo "Missing \`docker\` client which is required for development"; \ + exit 2; \ + fi + +images: check-docker build_vino-builder + +docs: clean build_docs + +build_docs: + echo TODO + +run_images: run_vino-builder + +run_vino-builder: + echo TODO + +build_vino-builder: + mkdir -p $(BUILD_DIR) +ifeq ($(IMAGE_ID), none) +ifeq ($(USE_PROXY), true) + docker build . \ + --iidfile $(BUILD_DIR)/image_id \ + --tag $(IMAGE) \ + --label $(LABEL) \ + --label "org.opencontainers.image.revision=$(COMMIT)" \ + --label "org.opencontainers.image.created=\ + $(shell date --rfc-3339=seconds --utc)" \ + --label "org.opencontainers.image.title=$(IMAGE_NAME)" \ + --build-arg http_proxy=$(PROXY) \ + --build-arg https_proxy=$(PROXY) \ + --build-arg HTTP_PROXY=$(PROXY) \ + --build-arg HTTPS_PROXY=$(PROXY) \ + --build-arg no_proxy=$(NO_PROXY) \ + --build-arg NO_PROXY=$(NO_PROXY) \ + --build-arg GIT_COMMIT=$(COMMIT) +else + docker build . \ + --iidfile $(BUILD_DIR)/image_id \ + --tag $(IMAGE) \ + --label $(LABEL) \ + --label "org.opencontainers.image.revision=$(COMMIT)" \ + --label "org.opencontainers.image.created=\ + $(shell date --rfc-3339=seconds --utc)" \ + --label "org.opencontainers.image.title=$(IMAGE_NAME)" \ + --build-arg GIT_COMMIT=$(COMMIT) +endif +else + echo $(IMAGE_ID) > $(BUILD_DIR)/image_id +endif +ifeq ($(PUSH_IMAGE), true) + docker push $(IMAGE) +endif + +clean: +ifeq ($(IMAGE_ID), none) + if [[ -s $(BUILD_DIR)/image_id ]]; \ + then \ + docker rmi $$(cat $(BUILD_DIR)/image_id); \ + fi +endif + rm -rf $(BUILD_DIR) + +# style checks +lint: test-shellcheck + +tests: lint unit_tests run_vino-builder + +test-shellcheck: $(SH_TO_CHECK) + +unit_tests: + echo TODO + +$(SH_TO_CHECK): + docker run --rm -v $(shell pwd):/mnt \ + nlknguyen/alpine-shellcheck -x /mnt/$(@) + +.PHONY: test clean $(SH_TO_CHECK) test-shellcheck tests lint build_vino-builder \ + run_vino-builder run_images all build_docs docs check-docker images diff --git a/vino-builder/assets/entrypoint.sh b/vino-builder/assets/entrypoint.sh index f9f69af..7707c97 100644 --- a/vino-builder/assets/entrypoint.sh +++ b/vino-builder/assets/entrypoint.sh @@ -26,4 +26,10 @@ while [[ ! -e /var/run/libvirt/libvirt-sock ]]; do fi done -ansible-playbook -v -e @/var/lib/vino-builder/vino-builder-config.yaml /playbooks/vino-builder.yaml \ No newline at end of file +ansible-playbook -v \ + -e @/vino/spec \ + -e @/var/lib/vino-builder/flavors/flavors.yaml \ + -e @/var/lib/vino-builder/flavor-templates/flavor-templates.yaml \ + -e @/var/lib/vino-builder/network-templates/network-templates.yaml \ + -e @/var/lib/vino-builder/storage-templates/storage-templates.yaml \ + /playbooks/vino-builder.yaml \ No newline at end of file diff --git a/vino-builder/assets/playbooks/roles/libvirt/library/core_allocation.py b/vino-builder/assets/playbooks/roles/libvirt/library/core_allocation.py index 6f6566b..8a5d70a 100644 --- a/vino-builder/assets/playbooks/roles/libvirt/library/core_allocation.py +++ b/vino-builder/assets/playbooks/roles/libvirt/library/core_allocation.py @@ -60,7 +60,7 @@ def get_numa_cores(): numa_core_dict[numa] = parsed_range_list return numa_core_dict -def allocate_cores(nodes, exclude_cpu): +def allocate_cores(nodes, flavors, exclude_cpu): """Return""" core_state = {} @@ -96,13 +96,16 @@ def allocate_cores(nodes, exclude_cpu): # address the case where previous != desired - delete previous, re-run for node in nodes: + flavor = node['labels']['vmFlavor'] + vcpus = flavors[flavor]['vcpus'] + for num_node in range(0, node['count']): # generate a unique name such as master-0, master-1 node_name = node['name'] + '-' + str(num_node) # extract the core count - core_count = int(node['instance']['vcpu']) + core_count = int(vcpus) # discover any previous allocation if 'assignments' in core_state: @@ -140,10 +143,12 @@ def main(): module = AnsibleModule( argument_spec=dict( nodes=dict(required=True, type='list'), + flavors=dict(required=True, type='dict'), exclude_cpu=dict(required=True, type='str') ) ) result = allocate_cores(module.params["nodes"], + module.params["flavors"], module.params["exclude_cpu"]) module.exit_json(**result) diff --git a/vino-builder/assets/playbooks/roles/libvirt/tasks/create-domain.yaml b/vino-builder/assets/playbooks/roles/libvirt/tasks/create-domain.yaml index 9df7192..08a365c 100644 --- a/vino-builder/assets/playbooks/roles/libvirt/tasks/create-domain.yaml +++ b/vino-builder/assets/playbooks/roles/libvirt/tasks/create-domain.yaml @@ -5,7 +5,7 @@ - name: debug print virsh xml domain debug: - msg: "{{ libvirtDomains[node.name]['domainTemplate'] }}" + msg: "{{ flavorTemplates[node.labels.vmFlavor]['domainTemplate'] }}" loop: "{{ range(0,node.count)|list }}" - name: get state of existing volumes @@ -14,7 +14,7 @@ register: vol_list - name: write out domain volume request xml - copy: content="{{libvirtDomains[node.name]['volumeTemplate']}}" dest=/tmp/vol-{{item}}.xml + copy: content="{{ flavorTemplates[node.labels.vmFlavor]['volumeTemplate'] }}" dest=/tmp/vol-{{item}}.xml loop: "{{ range(0,node.count)|list }}" - name: create domain volume if it doesn't exist @@ -35,7 +35,7 @@ # to domains, so we must shell out here instead - name: write out domain volume request xml - copy: content="{{libvirtDomains[node.name]['domainTemplate']}}" dest=/tmp/domain-{{item}}.xml + copy: content="{{ flavorTemplates[node.labels.vmFlavor]['domainTemplate'] }}" dest=/tmp/domain-{{item}}.xml loop: "{{ range(0,node.count)|list }}" - name: virsh define domain @@ -43,10 +43,10 @@ virsh define /tmp/domain-{{item}}.xml loop: "{{ range(0,node.count)|list }}" -# - name: set vm to running -# virt: -# name: "{{ node.name + '-' + item|string}}" -# state: running -# # autostart: yes -# loop: "{{ range(0,node.count)|list }}" -# ignore_errors: true +- name: set vm to running + virt: + name: "{{ node.name + '-' + item|string}}" + state: running + autostart: yes + loop: "{{ range(0,node.count)|list }}" + ignore_errors: true diff --git a/vino-builder/assets/playbooks/roles/libvirt/tasks/create-network.yaml b/vino-builder/assets/playbooks/roles/libvirt/tasks/create-network.yaml index 8614592..6fdfe5e 100644 --- a/vino-builder/assets/playbooks/roles/libvirt/tasks/create-network.yaml +++ b/vino-builder/assets/playbooks/roles/libvirt/tasks/create-network.yaml @@ -2,7 +2,7 @@ - name: initially gather facts on existing virsh networks virt_net: command: facts - name: management # this attribute is not needed but required + name: "" # this attribute is not needed but required uri: "{{ libvirt_uri }}" ignore_errors: true @@ -27,7 +27,7 @@ - name: re-gather facts on existing virsh networks virt_net: command: facts - name: management + name: "" uri: "{{ libvirt_uri }}" ignore_errors: true diff --git a/vino-builder/assets/playbooks/roles/libvirt/tasks/main.yml b/vino-builder/assets/playbooks/roles/libvirt/tasks/main.yml index 1f47451..a89f6e6 100644 --- a/vino-builder/assets/playbooks/roles/libvirt/tasks/main.yml +++ b/vino-builder/assets/playbooks/roles/libvirt/tasks/main.yml @@ -21,6 +21,7 @@ - name: allocate domain cores core_allocation: nodes: "{{ nodes }}" + flavors: "{{ flavors }}" exclude_cpu: "{{ configuration.cpuExclude }}" register: node_core_map when: nodes