Skip to content
This repository has been archived by the owner on Jun 13, 2023. It is now read-only.

Commit

Permalink
Add kubevirt-cpu-node-labeller deployment to kubevirt ansible (#574)
Browse files Browse the repository at this point in the history
(cherry picked from commit 207f583)
  • Loading branch information
Ryan Hallisey authored Jan 18, 2019
1 parent f8caa57 commit f5aa033
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 1 deletion.
11 changes: 11 additions & 0 deletions playbooks/kubevirt-cpu-node-labeller.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
- import_playbook: initial_configuration.yml

- name: Deploy kubevirt-cpu-node-labeller role
hosts: localhost
connection: local
gather_facts: False
environment:
http_proxy: ""
roles:
- role: "kubevirt-cpu-node-labeller"
6 changes: 5 additions & 1 deletion playbooks/kubevirt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@

# Deploy kubevirt ssp
- import_playbook: kubevirt-ssp.yml
when: platform == "openshift"
when: platform == "openshift"

# Deploy kubevirt cpu-node-labeller
- import_playbook: kubevirt-cpu-node-labeller.yml
when: platform == "openshift"
2 changes: 2 additions & 0 deletions roles/kubevirt-cpu-node-labeller/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# kubevirt-cpu-node-labeller
Labells nodes with all supported cpu models on host.
9 changes: 9 additions & 0 deletions roles/kubevirt-cpu-node-labeller/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
kubevirt_node_labeller_namespace: "kubevirt"
kubevirt_cpu_node_labeller_files_dir: "{{ role_path }}/templates"
cluster_command: "oc" # in case the roles/playbook is not executed from kubevirt.yml
registry_url: "quay.io"
repo_tag: "ksimon"
docker_tag: "0.0.1"
docker_prefix: "{{ registry_url }}/{{ repo_tag }}"
libvirt_image: "kubevirt/libvirt:4.9.0"
21 changes: 21 additions & 0 deletions roles/kubevirt-cpu-node-labeller/tasks/deprovision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Check that kubevirt-cpu-node-labeller.yaml still exists in /tmp
stat:
path: "/tmp/kubevirt-cpu-node-labeller.yaml"
register: kubevirt_cpu_node_labeller

- name: Copy kubevirt-cpu-node-labeller yaml to temp directory
template:
src: "{{ kubevirt_cpu_node_labeller_files_dir }}/kubevirt-cpu-node-labeller-0.0.1.yaml"
dest: "/tmp/kubevirt-cpu-node-labeller.yaml"
when: kubevirt_cpu_node_labeller.stat.exists == false

- name: Delete Kubevirt cpu-node-labeller
shell: "{{ cluster_command }} delete --ignore-not-found -f /tmp/kubevirt-cpu-node-labeller.yaml -n {{ kubevirt_node_labeller_namespace }}"

- name: Wait until kubevirt-cpu-node-labeller deamonset is deleted
shell: "{{ cluster_command }} -n {{ kubevirt_node_labeller_namespace }} get ds | grep -o -E kubevirt-cpu-node-labeller | wc -l"
register: result
until: result.stdout == "0"
retries: 24
delay: 10
1 change: 1 addition & 0 deletions roles/kubevirt-cpu-node-labeller/tasks/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- include_tasks: "{{ apb_action }}.yml"
21 changes: 21 additions & 0 deletions roles/kubevirt-cpu-node-labeller/tasks/provision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
- name: Check that kubevirt-cpu-node-labeller.yaml still exists in /tmp
stat:
path: "/tmp/kubevirt-cpu-node-labeller.yaml"
register: kubevirt_cpu_node_labeller

- name: Copy kubevirt-cpu-node-labeller.yaml to temp directory
template:
src: "{{ kubevirt_cpu_node_labeller_files_dir }}/kubevirt-cpu-node-labeller-0.0.1.yaml"
dest: "/tmp/kubevirt-cpu-node-labeller.yaml"
when: kubevirt_cpu_node_labeller.stat.exists == false

- name: Create kubevirt-cpu-node-labeller
shell: "{{ cluster_command }} create -f /tmp/kubevirt-cpu-node-labeller.yaml -n {{ kubevirt_node_labeller_namespace }}"

- name: Wait until kubevirt-cpu-node-labeller deamonset is created
shell: "{{ cluster_command }} -n {{ kubevirt_node_labeller_namespace }} get ds | grep -o -E kubevirt-cpu-node-labeller | wc -l"
register: result
until: result.stdout == "1"
retries: 24
delay: 10
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: kubevirt-cpu-node-labeller
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: kubevirt-cpu-node-labeller
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
verbs:
- get
- patch
- update
- apiGroups:
- security.openshift.io
resources:
- securitycontextconstraints
verbs:
- use
resourceName:
- privileged
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: kubevirt-cpu-node-labeller
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: kubevirt-cpu-node-labeller
subjects:
- kind: ServiceAccount
name: kubevirt-cpu-node-labeller
namespace: {{kubevirt_node_labeller_namespace}}
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
labels:
app: kubevirt-cpu-node-labeller
name: kubevirt-cpu-node-labeller
spec:
selector:
matchLabels:
app: kubevirt-cpu-node-labeller
template:
metadata:
labels:
app: kubevirt-cpu-node-labeller
spec:
serviceAccount: kubevirt-cpu-node-labeller
containers:
- env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: {{ docker_prefix }}/kubevirt-cpu-node-labeller:{{ docker_tag }}
name: kubevirt-cpu-node-labeller
volumeMounts:
- name: nfd-source
mountPath: "/etc/kubernetes/node-feature-discovery/source.d/"
initContainers:
- image: {{ docker_prefix }}/kubevirt-cpu-model-nfd-plugin:{{ docker_tag }}
command: ["/bin/sh","-c"]
args: ["cp /plugin/dest/cpu-model-nfd-plugin /etc/kubernetes/node-feature-discovery/source.d/;"]
imagePullPolicy: Always
name: cpu-model-nfd-plugin
volumeMounts:
- name: nfd-source
mountPath: "/etc/kubernetes/node-feature-discovery/source.d/"

- image: {{ libvirt_image }}
command: ["/bin/sh","-c"]
args: ["libvirtd -d; chmod o+rw /dev/kvm; virsh domcapabilities --machine q35 --arch x86_64 --virttype kvm > /etc/kubernetes/node-feature-discovery/source.d/virsh_domcapabilities.xml;"]
imagePullPolicy: Always
name: libvirt
securityContext:
privileged: true
resources:
requests:
devices.kubevirt.io/kvm: "1"
limits:
devices.kubevirt.io/kvm: "1"
volumeMounts:
- name: nfd-source
mountPath: "/etc/kubernetes/node-feature-discovery/source.d/"

volumes:
- name: nfd-source
emptyDir: {}

0 comments on commit f5aa033

Please sign in to comment.