forked from metal3-io/metal3-dev-env
-
Notifications
You must be signed in to change notification settings - Fork 5
/
verify.yml
108 lines (96 loc) · 3.61 KB
/
verify.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
---
- name: Define number of BMH's
set_fact:
NUMBER_OF_BMH: "{{ NUM_OF_MASTER_REPLICAS|int + NUM_OF_WORKER_REPLICAS|int }}"
- name: Wait until cluster becomes provisioned.
shell: "kubectl get cluster -n metal3 -o json | jq -r '.items[] | .status.phase'"
register: provisioned_cluster
retries: 100
delay: 20
until: (provisioned_cluster.stdout == "provisioned") or
(provisioned_cluster.stdout == "Provisioned")
- name: Wait until "{{ NUMBER_OF_BMH }}" BMHs become provisioned.
shell: |
kubectl get bmh -n metal3 -o json | jq -r '[ .items[]
| select (.status.provisioning.state == "provisioned")
| .metadata.name ] | length'
register: provisioned_bmh
retries: 200
delay: 30
until: provisioned_bmh.stdout == NUMBER_OF_BMH
- name: Wait until "{{ NUMBER_OF_BMH }}" machines become running.
shell: |
kubectl get machines -n metal3 -o json | jq -r '[ .items[]
| select (.status.phase == "Running" or .status.phase == "running")
| .metadata.name ] | length'
register: provisioned_machines
retries: 150
delay: 20
until: provisioned_machines.stdout == NUMBER_OF_BMH
- name: Define username variable as "{{ IMAGE_USERNAME }}" for target node
set_fact:
username: "{{ IMAGE_USERNAME }}"
- name: Fetch target cluster kubeconfig
shell: "kubectl get secrets {{ CLUSTER_NAME }}-kubeconfig -n {{ NAMESPACE }} -o json | jq -r '.data.value'| base64 -d > /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml"
# Install Calico
- name: Download Calico manifest
get_url:
url: https://docs.projectcalico.org/manifests/calico.yaml
dest: /tmp/
mode: '664'
register: calico_manifest
- name: Replace the POD_CIDR in calico config
replace:
path: /tmp/calico.yaml
regexp: "192.168.0.0/16"
replace: "{{ POD_CIDR }}"
register: updated_manifest
- name: Add IP_AUTODETECTION_METHOD in calico config Ubuntu
blockinfile:
path: /tmp/calico.yaml
insertafter: "{{ POD_CIDR }}"
block: |
# for indentation
- name: IP_AUTODETECTION_METHOD
value: "interface=enp2s0"
when:
ansible_distribution == "Ubuntu"
- name: Add IP_AUTODETECTION_METHOD in calico config Centos
blockinfile:
path: /tmp/calico.yaml
insertafter: "{{ POD_CIDR }}"
block: |
# for indentation
- name: IP_AUTODETECTION_METHOD
value: "interface=eth1"
- name: FELIX_IPTABLESBACKEND
value: "NFT"
when:
ansible_distribution == "CentOS"
- name: Apply Calico manifest
k8s:
state: present
src: "/tmp/calico.yaml"
kubeconfig: "/tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml"
register: install_cni
# Check for pods & nodes on the target cluster
- name: Check if pods in running state
shell: "kubectl get pods --kubeconfig /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml -A -o json | jq -r '.items[].status.phase' | grep -v Running"
retries: 150
delay: 20
register: running_pods
failed_when: >
(running_pods.stderr != "") or
(running_pods.rc > 1) or
(running_pods.stdout != "")
until: running_pods.stdout == ""
- name: Check if nodes in ready state
shell: "kubectl get nodes --kubeconfig /tmp/kubeconfig-{{ CLUSTER_NAME }}.yaml | grep -w Ready | wc -l"
retries: 150
delay: 3
register: ready_nodes
failed_when: >
(ready_nodes.stderr != "") or
(ready_nodes.rc != 0) or
(ready_nodes.stdout != NUMBER_OF_BMH)
until: ready_nodes.stdout == NUMBER_OF_BMH