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

Commit

Permalink
Merge pull request #543 from SchSeba/fix_cdi
Browse files Browse the repository at this point in the history
Fix cdi to provision and deprovision
  • Loading branch information
nellyc authored Jan 13, 2019
2 parents 9cd6076 + 81b6c8a commit 04c2c27
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 148 deletions.
46 changes: 29 additions & 17 deletions roles/cdi/tasks/deprovision.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,40 @@
- name: Delete {{ cdi_namespace }} ResourceQuota
command: kubectl delete -f /tmp/cdi-deprovision-resourcequota.yml -n {{ cdi_namespace }} --ignore-not-found

- name: Check that cdi-provision.yml still exists in /tmp
- name: Check that cdi-controller.yaml still exists in /tmp
stat:
path: "/tmp/cdi-provision.yml"
path: "/tmp/cdi-controller.yaml"
register: cdi_template

- name: Check for cdi-controller.yml.j2 template in {{ cdi_template_dir }}
stat:
path: "{{ cdi_template_dir }}/cdi-controller.yaml.j2"
register: byo_template
when: cdi_template.stat.exists == False
- name: Get cdi-controller.yaml
block:
- name: Check for cdi-controller.yaml.j2 template in {{ cdi_template_dir }}
stat:
path: "{{ cdi_template_dir }}/cdi-controller.yaml.j2"
register: byo_template

- name: Download CDI Template
get_url:
url: "{{ cdi_release_manifest_url }}/{{ release_tag }}/cdi-controller.yaml.j2"
dest: "{{ cdi_template_dir }}/cdi-controller.yaml.j2"
when: (cdi_template.stat.exists == False) and (byo_template.stat.exists == False)
- name: Render CDI deprovision yaml
template:
src: "cdi-controller.yaml.j2"
dest: "/tmp/cdi-controller.yaml"
when: byo_template.stat.exists == true

- name: Render CDI deprovision yaml
template:
src: "cdi-controller.yaml.j2"
dest: "/tmp/cdi-deprovision.yml"
- name: Download and render cdi-controller.yaml from {{ cdi_release_manifest_url }}
block:
- name: Download CDI Template
get_url:
url: "{{ cdi_release_manifest_url }}/{{ release_tag }}/cdi-controller.yaml.j2"
dest: "/tmp/cdi-controller.yaml.j2"

- name: Render CDI deprovision yaml
template:
src: "/tmp/cdi-controller.yaml.j2"
dest: "/tmp/cdi-controller.yaml"

when: byo_template.stat.exists == false

when: cdi_template.stat.exists == false

- name: Delete CDI Resources
command: kubectl delete -f /tmp/cdi-deprovision.yml -n {{ cdi_namespace }} --ignore-not-found
command: kubectl delete -f /tmp/cdi-controller.yaml -n {{ cdi_namespace }} --ignore-not-found

51 changes: 27 additions & 24 deletions roles/cdi/tasks/provision.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
---
# CDI Deployment
- name: Check if namespace {{ cdi_namespace }} exists
shell: "{{ cluster_command }} get ns | grep -w {{ cdi_namespace }} | awk '{ print $1 }'"
shell: "{{ cluster_command }} get ns {{ cdi_namespace }}"
ignore_errors: yes
register: ns

- name: Create {{ cdi_namespace }} namespace using kubectl
shell: kubectl create namespace {{ cdi_namespace }}
when: ns.stdout != cdi_namespace
when: ns.rc != 0
and platform == "kubernetes"

- name: Create {{ cdi_namespace }} namespace using oc
shell: oc new-project {{ cdi_namespace }}
when: ns.stdout != cdi_namespace
when: ns.rc != 0
and platform == "openshift"

- name: Render {{ cdi_namespace }} ResourceQuota deployment yaml
Expand All @@ -27,32 +28,34 @@
path: "{{ cdi_template_dir }}/cdi-controller.yaml.j2"
register: byo_template

- name: Check for cdi-controller.yaml.j2 version v{{ version }} in {{ cdi_offline_template_dir }}
stat:
path: "{{ cdi_offline_template_dir }}/v{{ version }}/cdi-controller.yaml.j2"
register: offline_templates
when: byo_template.stat.exists == False
- name: Render CDI deployment yaml from template in {{ cdi_template_dir }}
template:
src: "cdi-controller.yaml.j2"
dest: "/tmp/cdi-controller.yml"
when: byo_template.stat.exists == true

- name: Download CDI Template
get_url:
url: "{{ cdi_release_manifest_url }}/{{ release_tag }}/cdi-controller.yaml.j2"
dest: "{{ cdi_template_dir }}/cdi-controller.yaml.j2"
when: byo_template.stat.exists == False and offline_templates.stat.exists == False
- name: Get CDI from {{ cdi_release_manifest_url }}
block:
- name: Check for cdi-controller.yaml.j2 template in /tmp
stat:
path: "/tmp/cdi-controller.yaml.j2"
register: downloaded_template

- name: Render offline template
template:
src: "{{ cdi_offline_template_dir }}/v{{ version }}/cdi-controller.yaml.j2"
dest: "/tmp/cdi-provision.yaml"
when: (offline_templates is not skipped) and (offline_templates.stat.exists == True)
- name: Download CDI Template
get_url:
url: "{{ cdi_release_manifest_url }}/{{ release_tag }}/cdi-controller.yaml.j2"
dest: "/tmp/cdi-controller.yaml.j2"
when: downloaded_template.stat.exists == false

- name: Render CDI deployment yaml
template:
src: "cdi-controller.yaml.j2"
dest: "/tmp/cdi-provision.yml"
when: (offline_templates is skipped) or (offline_templates.stat.exists == False)
- name: Render CDI deployment yaml
template:
src: "/tmp/cdi-controller.yaml.j2"
dest: "/tmp/cdi-controller.yaml"

when: byo_template.stat.exists == false

- name: Create CDI deployment
command: "{{ cluster_command }} apply -f /tmp/cdi-provision.yml"
command: "{{ cluster_command }} apply -f /tmp/cdi-controller.yaml"

- name: Enable privileged containers in the security context
command: "oc adm policy add-scc-to-user privileged -z cdi-sa -n {{ cdi_namespace }}"
Expand Down
105 changes: 0 additions & 105 deletions roles/cdi/templates/cdi-controller-deployment.yml

This file was deleted.

5 changes: 3 additions & 2 deletions roles/kubevirt/tasks/provision.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
---
- name: Check if {{ namespace }} exists
shell: "{{ cluster_command }} get ns | grep -w {{ namespace }} | awk '{ print $1 }'"
shell: "{{ cluster_command }} get ns {{ namespace }}"
ignore_errors: yes
register: ns

- name: Create {{ namespace }} namespace
shell: "{{ cluster_command }} create namespace {{ namespace }}"
when: ns.stdout != namespace
when: ns.rc != 0

- name: Add Privileged Policy
command: "oc adm policy add-scc-to-user privileged -z {{ item }} -n {{ namespace }}"
Expand Down

0 comments on commit 04c2c27

Please sign in to comment.