Skip to content

Commit d4cb5da

Browse files
authored
Merge pull request #12295 from VannTen/ci/collection
CI: Simplify running playbooks as collection + various CI Fixes
2 parents 62f4982 + f55de03 commit d4cb5da

8 files changed

+392
-407
lines changed

tests/scripts/testcases_run.sh

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,16 @@ export ANSIBLE_BECOME_USER=root
3030
if [[ "${TESTCASE}" =~ "collection" ]]; then
3131
# Build and install collection
3232
ansible-galaxy collection build
33-
ansible-galaxy collection install kubernetes_sigs-kubespray-$(grep "^version:" galaxy.yml | awk '{print $2}').tar.gz
34-
35-
# Simply remove all of our files and directories except for our tests directory
36-
# to be absolutely certain that none of our playbooks or roles
37-
# are interfering with our collection
38-
find -mindepth 1 -maxdepth 1 ! -regex './\(tests\|inventory\)' -exec rm -rfv {} +
39-
40-
cat > cluster.yml <<EOF
41-
- name: Install Kubernetes
42-
ansible.builtin.import_playbook: kubernetes_sigs.kubespray.cluster
43-
EOF
44-
45-
cat > upgrade-cluster.yml <<EOF
46-
- name: Install Kubernetes
47-
ansible.builtin.import_playbook: kubernetes_sigs.kubespray.upgrade-cluster
48-
EOF
49-
50-
cat > reset.yml <<EOF
51-
- name: Remove Kubernetes
52-
ansible.builtin.import_playbook: kubernetes_sigs.kubespray.reset
53-
EOF
54-
55-
cat > remove-node.yml <<EOF
56-
- name: Remove node from Kubernetes
57-
ansible.builtin.import_playbook: kubernetes_sigs.kubespray.remove_node
58-
EOF
59-
33+
ansible-galaxy collection install kubernetes_sigs-kubespray-*.tar.gz
6034
fi
61-
6235
run_playbook () {
63-
playbook=$1
36+
if [[ "${TESTCASE}" =~ "collection" ]]; then
37+
playbook=kubernetes_sigs.kubespray.$1
38+
else
39+
playbook=$1.yml
40+
fi
6441
shift
42+
6543
ansible-playbook \
6644
-e @tests/common_vars.yml \
6745
-e @tests/${TESTCASE_FILE} \
@@ -71,11 +49,10 @@ ansible-playbook \
7149
}
7250

7351

74-
7552
## START KUBESPRAY
7653

7754
# Create cluster
78-
run_playbook cluster.yml
55+
run_playbook cluster
7956

8057
# Repeat deployment if testing upgrade
8158
if [ "${UPGRADE_TEST}" != "false" ]; then
@@ -85,10 +62,10 @@ if [ "${UPGRADE_TEST}" != "false" ]; then
8562

8663
case "${UPGRADE_TEST}" in
8764
"basic")
88-
run_playbook cluster.yml
65+
run_playbook cluster
8966
;;
9067
"graceful")
91-
run_playbook upgrade-cluster.yml
68+
run_playbook upgrade-cluster
9269
;;
9370
*)
9471
;;
@@ -97,36 +74,23 @@ fi
9774

9875
# Test control plane recovery
9976
if [ "${RECOVER_CONTROL_PLANE_TEST}" != "false" ]; then
100-
run_playbook reset.yml --limit "${RECOVER_CONTROL_PLANE_TEST_GROUPS}" -e reset_confirmation=yes
101-
run_playbook recover-control-plane.yml -e etcd_retries=10 --limit "etcd:kube_control_plane"
102-
fi
103-
104-
# Tests Cases
105-
## Test Control Plane API
106-
run_playbook tests/testcases/010_check-apiserver.yml
107-
run_playbook tests/testcases/015_check-nodes-ready.yml
108-
109-
## Test that all nodes are Ready
110-
111-
if [[ ! ( "$TESTCASE" =~ "macvlan" ) ]]; then
112-
run_playbook tests/testcases/020_check-pods-running.yml
113-
run_playbook tests/testcases/030_check-network.yml
114-
if [[ ! ( "$TESTCASE" =~ "hardening" ) ]]; then
115-
# TODO: We need to remove this condition by finding alternative container
116-
# image instead of netchecker which doesn't work at hardening environments.
117-
run_playbook tests/testcases/040_check-network-adv.yml
118-
fi
77+
run_playbook reset --limit "${RECOVER_CONTROL_PLANE_TEST_GROUPS}" -e reset_confirmation=yes
78+
run_playbook recover-control-plane -e etcd_retries=10 --limit "etcd:kube_control_plane"
11979
fi
12080

121-
## Kubernetes conformance tests
122-
run_playbook tests/testcases/100_check-k8s-conformance.yml
81+
# Run tests
82+
ansible-playbook \
83+
-e @tests/common_vars.yml \
84+
-e @tests/${TESTCASE_FILE} \
85+
-e local_release_dir=${PWD}/downloads \
86+
tests/testcases/tests.yml
12387

12488
# Test node removal procedure
12589
if [ "${REMOVE_NODE_CHECK}" = "true" ]; then
126-
run_playbook remove-node.yml -e skip_confirmation=yes -e node=${REMOVE_NODE_NAME}
90+
run_playbook remove-node -e skip_confirmation=yes -e node=${REMOVE_NODE_NAME}
12791
fi
12892

12993
# Clean up at the end, this is to allow stage1 tests to include cleanup test
13094
if [ "${RESET_CHECK}" = "true" ]; then
131-
run_playbook reset.yml -e reset_confirmation=yes
95+
run_playbook reset -e reset_confirmation=yes
13296
fi
Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
---
2-
- name: Testcases for apiserver
3-
hosts: kube_control_plane
2+
- name: Check the API servers are responding
3+
uri:
4+
url: "https://{{ (access_ip if (ipv4_stack | default(true)) else access_ip6) | default(ansible_default_ipv4.address if (ipv4_stack | default(true)) else ansible_default_ipv6.address) | ansible.utils.ipwrap }}:{{ kube_apiserver_port | default(6443) }}/version"
5+
validate_certs: false
6+
status_code: 200
7+
register: apiserver_response
8+
retries: 12
9+
delay: 5
10+
until: apiserver_response is success
411

5-
tasks:
6-
- name: Check the API servers are responding
7-
uri:
8-
url: "https://{{ (access_ip if (ipv4_stack | default(true)) else access_ip6) | default(ansible_default_ipv4.address if (ipv4_stack | default(true)) else ansible_default_ipv6.address) | ansible.utils.ipwrap }}:{{ kube_apiserver_port | default(6443) }}/version"
9-
validate_certs: false
10-
status_code: 200
11-
register: apiserver_response
12-
retries: 12
13-
delay: 5
14-
until: apiserver_response is success
15-
16-
- name: Check API servers version
17-
assert:
18-
that:
19-
- apiserver_response.json.gitVersion == kube_version
20-
fail_msg: "apiserver version different than expected {{ kube_version }}"
21-
when: kube_version is defined
12+
- name: Check API servers version
13+
assert:
14+
that:
15+
- apiserver_response.json.gitVersion == ('v' + kube_version)
16+
fail_msg: "apiserver is {{ apiserver_response.json.gitVersion }}, expected {{ kube_version }}"
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
---
2-
- name: Testcases checking nodes
3-
hosts: kube_control_plane[0]
4-
tasks:
2+
- import_role: # noqa name[missing]
3+
name: cluster-dump
54

6-
- import_role: # noqa name[missing]
7-
name: cluster-dump
5+
- name: Check kubectl output
6+
command: "{{ bin_dir }}/kubectl get nodes"
7+
changed_when: false
8+
register: get_nodes
89

9-
- name: Check kubectl output
10-
command: "{{ bin_dir }}/kubectl get nodes"
11-
changed_when: false
12-
register: get_nodes
13-
14-
- name: Check that all nodes are running and ready
15-
command: "{{ bin_dir }}/kubectl get nodes --no-headers -o yaml"
16-
changed_when: false
17-
register: get_nodes_yaml
18-
until:
19-
# Check that all nodes are Status=Ready
20-
- '(get_nodes_yaml.stdout | from_yaml)["items"] | map(attribute = "status.conditions") | map("items2dict", key_name="type", value_name="status") | map(attribute="Ready") | list | min'
21-
retries: 30
22-
delay: 10
10+
- name: Check that all nodes are running and ready
11+
command: "{{ bin_dir }}/kubectl get nodes --no-headers -o yaml"
12+
changed_when: false
13+
register: get_nodes_yaml
14+
until:
15+
# Check that all nodes are Status=Ready
16+
- '(get_nodes_yaml.stdout | from_yaml)["items"] | map(attribute = "status.conditions") | map("items2dict", key_name="type", value_name="status") | map(attribute="Ready") | list | min'
17+
retries: 30
18+
delay: 10
Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,39 @@
11
---
2-
- name: Testcases checking pods
3-
hosts: kube_control_plane[0]
4-
tasks:
2+
- import_role: # noqa name[missing]
3+
name: cluster-dump
54

6-
- import_role: # noqa name[missing]
7-
name: cluster-dump
5+
- name: Check kubectl output
6+
command: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide"
7+
changed_when: false
88

9-
- name: Check kubectl output
10-
command: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide"
11-
changed_when: false
12-
13-
- name: Check that all pods are running and ready
14-
command: "{{ bin_dir }}/kubectl get pods --all-namespaces --no-headers -o yaml"
15-
changed_when: false
9+
- name: Check pods
10+
vars:
11+
query_pods_not_running: "items[?status.phase != 'Running']"
12+
query_pods_not_ready: "items[?(status.conditions[?type == 'Ready'])[0].status != 'True']"
13+
pods_not_running: "{{ run_pods_log.stdout | from_json | json_query(query_pods_not_running + '.metadata') }}"
14+
pods_not_ready: "{{ run_pods_log.stdout | from_json | json_query(query_pods_not_ready + '.metadata') }}"
15+
block:
16+
- name: Check that all pods are running
17+
command: "{{ bin_dir }}/kubectl get pods --all-namespaces -o json"
1618
register: run_pods_log
19+
changed_when: false
1720
until:
1821
# Check that all pods are running
19-
- '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.phase") | unique | list == ["Running"]'
22+
- run_pods_log.stdout | from_json | json_query(query_pods_not_running) == []
2023
# Check that all pods are ready
21-
- '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.containerStatuses") | map("map", attribute = "ready") | map("min") | min'
24+
- run_pods_log.stdout | from_json | json_query(query_pods_not_ready) == []
2225
retries: 30
2326
delay: 10
24-
25-
- name: Check kubectl output
26-
command: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide"
27-
changed_when: false
27+
rescue:
28+
- name: Describe broken pods
29+
command: "{{ bin_dir }}/kubectl describe pod -n {{ item.namespace }} {{ item.name }}"
30+
loop: "{{ pods_not_running + pods_not_ready }}"
31+
loop_control:
32+
label: "{{ item.namespace }}/{{ item.name }}"
33+
- name: Get logs from broken pods
34+
command: "{{ bin_dir }}/kubectl logs -n {{ item.namespace }} {{ item.pod }}"
35+
loop: "{{ pods_not_running + pods_not_ready }}"
36+
loop_control:
37+
label: "{{ item.namespace }}/{{ item.name }}"
38+
- name: Fail CI
39+
fail: {}

0 commit comments

Comments
 (0)