forked from kubevirt/kubevirt-ssp-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
113 lines (100 loc) · 3.87 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
- name: Set operatorVersion and targetVersion
operator_sdk.util.k8s_status:
api_version: "{{ cr_info.apiVersion }}"
kind: "{{ cr_info.kind }}"
name: "{{ cr_info.metadata.name }}"
namespace: "{{ cr_info.metadata.namespace }}"
status:
operatorVersion: "{{ operator_version }}"
targetVersion: "{{ operator_version }}"
# tasks file for KubevirtCommonTemplatesBundle
- name: Install VM templates
k8s:
state: present
namespace: "{{ cr_info.metadata.namespace }}"
definition: "{{ item | from_yaml }}"
apply: yes
with_items: "{{ lookup('file', 'common-templates-'+ version +'.yaml').split('\n---\n') | select('search', '(^|\n)[^#]') | list }}"
register: ct_status
# Get all templates
- name: Fetching all templates
set_fact:
templates: "{{ lookup('k8s', api_version=ct_status.results[0].result.apiVersion, kind='template') }}"
- name: Fetch old cr
block:
- set_fact:
old_cr: "{{ lookup('k8s', api_version='kubevirt.io/v1', kind='KubevirtCommonTemplatesBundle') }}"
- set_fact:
old_cr_exists: true
rescue:
- set_fact:
old_cr_exists: false
- name: Filter for templates owned by the old cr
set_fact:
old_cr_templates: "{{ templates | k8s_owned_by(old_cr) }}"
when: "{{ old_cr_exists==true }}"
# Inject ownerReferences
- name: Inject owner references for KubevirtCommonTemplatesBundle
include_role:
name: ClaimOwnership
vars:
object: "{{ item }}"
owner: "{{ cr_info }}"
when: "{{ old_cr_exists==true }}"
with_items: "{{ old_cr_templates }}" # Templates
- name: "Count all new templates in file"
set_fact:
new_templates: "{{ lookup('file', 'common-templates-'+ version +'.yaml').split('\n---\n') | select('search', '(^|\n)[^#]') | list | length }}"
- name: "Set label"
set_fact:
label: "template.kubevirt.io/version={{ version }}"
- name: "Get all templates"
set_fact:
deployed_templates_after: "{{ lookup('k8s', api_version=ct_status.results[0].result.apiVersion, kind='template', label_selector=label) | length }}"
- name: "Set Available status"
set_fact:
available: "{{ true if new_templates <= deployed_templates_after else false }}"
- name: Set progressing condition
operator_sdk.util.k8s_status:
api_version: "{{ cr_info.apiVersion }}"
kind: "{{ cr_info.kind }}"
name: "{{ cr_info.metadata.name }}"
namespace: "{{ cr_info.metadata.namespace }}"
conditions:
- type: Progressing
status: "False"
reason: "progressing"
message: "Templates progressing (deployed templates: {{ deployed_templates_after }}, desired deployed templated: {{ new_templates }})."
- name: Set available condition
operator_sdk.util.k8s_status:
api_version: "{{ cr_info.apiVersion }}"
kind: "{{ cr_info.kind }}"
name: "{{ cr_info.metadata.name }}"
namespace: "{{ cr_info.metadata.namespace }}"
conditions:
- type: Available
status: "True"
reason: "available"
message: "Common templates available (deployed templates: {{ deployed_templates_after }}, desired deployed templated: {{ new_templates }})."
- name: Set degraded condition
operator_sdk.util.k8s_status:
api_version: "{{ cr_info.apiVersion }}"
kind: "{{ cr_info.kind }}"
name: "{{ cr_info.metadata.name }}"
namespace: "{{ cr_info.metadata.namespace }}"
conditions:
- type: Degraded
status: "False"
reason: "degraded"
message: "Templates degraded (deployed templates: {{ deployed_templates_after }}, desired deployed templated: {{ new_templates }})."
# Update observerVersion when the CR is Available to indicate a successfull upgrade
- name: Set observedVersion
operator_sdk.util.k8s_status:
api_version: "{{ cr_info.apiVersion }}"
kind: "{{ cr_info.kind }}"
name: "{{ cr_info.metadata.name }}"
namespace: "{{ cr_info.metadata.namespace }}"
status:
observedVersion: "{{ operator_version }}"
when: "{{ available==true }}"