2016-11-28 20:18:06 +08:00
|
|
|
---
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Testcases for calico
|
|
|
|
hosts: kube_node
|
2016-11-28 20:18:06 +08:00
|
|
|
tasks:
|
2020-08-06 04:22:55 +08:00
|
|
|
- name: Test tunl0 routes
|
2024-10-25 20:53:24 +08:00
|
|
|
command: "/sbin/ip route"
|
|
|
|
register: routes
|
|
|
|
failed_when: routes.stdout_lines
|
|
|
|
| select('contains', '/' ~ calico_pool_blocksize|d(26))
|
|
|
|
| select('contains', 'tunl0') | length == 0
|
2018-10-11 15:45:00 +08:00
|
|
|
when:
|
2024-11-05 00:30:04 +08:00
|
|
|
- (calico_ipip_mode is defined and calico_ipip_mode != 'Never')
|
2023-07-05 11:36:54 +08:00
|
|
|
- kube_network_plugin | default('calico') == 'calico'
|
2016-11-28 20:18:06 +08:00
|
|
|
|
2024-10-25 20:53:24 +08:00
|
|
|
|
2023-07-26 22:36:22 +08:00
|
|
|
- name: Advanced testcases for network
|
|
|
|
hosts: k8s_cluster
|
2016-11-28 20:18:06 +08:00
|
|
|
vars:
|
|
|
|
agent_report_interval: 10
|
|
|
|
netcheck_namespace: default
|
|
|
|
netchecker_port: 31081
|
|
|
|
|
|
|
|
tasks:
|
2020-02-18 16:15:29 +08:00
|
|
|
- name: Force binaries directory for Container Linux by CoreOS and Flatcar
|
2016-11-28 20:18:06 +08:00
|
|
|
set_fact:
|
|
|
|
bin_dir: "/opt/bin"
|
2021-10-02 00:11:23 +08:00
|
|
|
when: ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
|
2016-11-28 20:18:06 +08:00
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- name: Force binaries directory on other hosts
|
|
|
|
set_fact:
|
2016-11-28 20:18:06 +08:00
|
|
|
bin_dir: "/usr/local/bin"
|
2021-10-02 00:11:23 +08:00
|
|
|
when: not ansible_os_family in ["Flatcar", "Flatcar Container Linux by Kinvolk"]
|
2016-11-28 20:18:06 +08:00
|
|
|
|
2023-06-30 17:51:57 +08:00
|
|
|
- import_role: # noqa name[missing]
|
2020-04-01 22:23:29 +08:00
|
|
|
name: cluster-dump
|
|
|
|
|
2020-08-06 04:22:55 +08:00
|
|
|
- name: Wait for netchecker server
|
2024-10-25 20:53:24 +08:00
|
|
|
command: "{{ bin_dir }}/kubectl get pods --field-selector=status.phase==Running -o jsonpath-as-json={.items[*].metadata.name} --namespace {{ netcheck_namespace }}"
|
|
|
|
register: pods_json
|
|
|
|
until:
|
|
|
|
- pods_json.stdout | from_json | select('match', 'netchecker-server.*') | length == 1
|
|
|
|
- (pods_json.stdout | from_json | select('match', 'netchecker-agent.*') | length)
|
|
|
|
>= (groups['k8s_cluster'] | intersect(ansible_play_hosts) | length * 2)
|
2016-11-28 20:18:06 +08:00
|
|
|
retries: 3
|
|
|
|
delay: 10
|
2021-03-24 08:26:05 +08:00
|
|
|
when: inventory_hostname == groups['kube_control_plane'][0]
|
2019-01-26 00:14:22 +08:00
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- name: Get netchecker pods
|
|
|
|
command: "{{ bin_dir }}/kubectl -n {{ netcheck_namespace }} describe pod -l app={{ item }}"
|
2019-01-26 00:14:22 +08:00
|
|
|
run_once: true
|
2021-03-24 08:26:05 +08:00
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
2019-01-26 00:14:22 +08:00
|
|
|
with_items:
|
|
|
|
- netchecker-agent
|
|
|
|
- netchecker-agent-hostnet
|
2024-10-25 20:53:24 +08:00
|
|
|
when: not pods_json is success
|
2019-01-26 00:14:22 +08:00
|
|
|
|
2023-06-30 17:51:57 +08:00
|
|
|
- debug: # noqa name[missing]
|
2019-05-16 15:27:43 +08:00
|
|
|
var: nca_pod.stdout_lines
|
2021-03-24 08:26:05 +08:00
|
|
|
when: inventory_hostname == groups['kube_control_plane'][0]
|
2016-11-28 20:18:06 +08:00
|
|
|
|
|
|
|
- name: Get netchecker agents
|
2019-05-16 15:27:43 +08:00
|
|
|
uri:
|
|
|
|
url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/agents/"
|
2024-08-28 13:30:56 +08:00
|
|
|
return_content: true
|
2016-11-28 20:18:06 +08:00
|
|
|
run_once: true
|
2021-03-24 08:26:05 +08:00
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
2016-11-28 20:18:06 +08:00
|
|
|
register: agents
|
2017-02-20 22:09:34 +08:00
|
|
|
retries: 18
|
2016-11-28 20:18:06 +08:00
|
|
|
delay: "{{ agent_report_interval }}"
|
2023-07-05 11:36:54 +08:00
|
|
|
until: agents.content | length > 0 and
|
2016-11-28 20:18:06 +08:00
|
|
|
agents.content[0] == '{' and
|
2023-07-05 11:36:54 +08:00
|
|
|
agents.content | from_json | length >= groups['k8s_cluster'] | intersect(ansible_play_hosts) | length * 2
|
2016-12-27 19:38:54 +08:00
|
|
|
failed_when: false
|
2019-01-28 19:33:18 +08:00
|
|
|
|
2016-11-28 20:18:06 +08:00
|
|
|
- name: Check netchecker status
|
2019-05-16 15:27:43 +08:00
|
|
|
uri:
|
|
|
|
url: "http://{{ ansible_default_ipv4.address }}:{{ netchecker_port }}/api/v1/connectivity_check"
|
|
|
|
status_code: 200
|
2024-08-28 13:30:56 +08:00
|
|
|
return_content: true
|
2021-03-24 08:26:05 +08:00
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
2016-11-28 20:18:06 +08:00
|
|
|
run_once: true
|
2022-03-18 09:05:39 +08:00
|
|
|
register: connectivity_check
|
2016-11-28 20:18:06 +08:00
|
|
|
retries: 3
|
|
|
|
delay: "{{ agent_report_interval }}"
|
2023-07-05 11:36:54 +08:00
|
|
|
until: connectivity_check.content | length > 0 and
|
2022-03-18 09:05:39 +08:00
|
|
|
connectivity_check.content[0] == '{'
|
2016-12-27 19:38:54 +08:00
|
|
|
failed_when: false
|
2018-10-20 19:56:55 +08:00
|
|
|
when:
|
|
|
|
- agents.content != '{}'
|
2016-11-28 20:18:06 +08:00
|
|
|
|
2023-06-30 17:51:57 +08:00
|
|
|
- debug: # noqa name[missing]
|
2024-10-25 20:53:24 +08:00
|
|
|
var: pods_json
|
2019-01-26 00:14:22 +08:00
|
|
|
run_once: true
|
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- name: Get kube-proxy logs
|
|
|
|
command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app=kube-proxy"
|
2020-05-01 14:38:05 +08:00
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2022-03-18 09:05:39 +08:00
|
|
|
- not connectivity_check is success
|
2019-01-26 00:14:22 +08:00
|
|
|
|
2019-05-16 15:27:43 +08:00
|
|
|
- name: Get logs from other apps
|
|
|
|
command: "{{ bin_dir }}/kubectl -n kube-system logs -l k8s-app={{ item }} --all-containers"
|
2020-05-01 14:38:05 +08:00
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2022-03-18 09:05:39 +08:00
|
|
|
- not connectivity_check is success
|
2019-01-26 00:14:22 +08:00
|
|
|
with_items:
|
|
|
|
- kube-router
|
|
|
|
- flannel
|
|
|
|
- canal-node
|
|
|
|
- calico-node
|
|
|
|
- cilium
|
|
|
|
|
2022-03-18 09:05:39 +08:00
|
|
|
- name: Parse agents list
|
|
|
|
set_fact:
|
|
|
|
agents_check_result: "{{ agents.content | from_json }}"
|
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
2016-11-28 20:18:06 +08:00
|
|
|
run_once: true
|
2019-01-26 00:14:22 +08:00
|
|
|
when:
|
2022-03-18 09:05:39 +08:00
|
|
|
- agents is success
|
|
|
|
- agents.content is defined
|
|
|
|
- agents.content[0] == '{'
|
2019-01-26 00:14:22 +08:00
|
|
|
|
2023-06-30 17:51:57 +08:00
|
|
|
- debug: # noqa name[missing]
|
2022-03-18 09:05:39 +08:00
|
|
|
var: agents_check_result
|
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
2019-01-26 00:14:22 +08:00
|
|
|
run_once: true
|
|
|
|
when:
|
2022-03-18 09:05:39 +08:00
|
|
|
- agents_check_result is defined
|
|
|
|
|
|
|
|
- name: Parse connectivity check
|
|
|
|
set_fact:
|
|
|
|
connectivity_check_result: "{{ connectivity_check.content | from_json }}"
|
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
|
|
run_once: true
|
|
|
|
when:
|
|
|
|
- connectivity_check is success
|
|
|
|
- connectivity_check.content is defined
|
|
|
|
- connectivity_check.content[0] == '{'
|
2016-12-15 17:28:03 +08:00
|
|
|
|
2023-06-30 17:51:57 +08:00
|
|
|
- debug: # noqa name[missing]
|
2022-03-18 09:05:39 +08:00
|
|
|
var: connectivity_check_result
|
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
2016-12-15 17:28:03 +08:00
|
|
|
run_once: true
|
2018-10-20 19:56:55 +08:00
|
|
|
when:
|
2022-03-18 09:05:39 +08:00
|
|
|
- connectivity_check_result is defined
|
|
|
|
|
|
|
|
- name: Check connectivity with all netchecker agents
|
|
|
|
assert:
|
|
|
|
that:
|
|
|
|
- agents_check_result is defined
|
|
|
|
- connectivity_check_result is defined
|
|
|
|
- agents_check_result.keys() | length > 0
|
|
|
|
- not connectivity_check_result.Absent
|
|
|
|
- not connectivity_check_result.Outdated
|
|
|
|
msg: "Connectivity check to netchecker agents failed"
|
|
|
|
delegate_to: "{{ groups['kube_control_plane'][0] }}"
|
|
|
|
run_once: true
|
2018-11-04 17:07:38 +08:00
|
|
|
|
|
|
|
- name: Create macvlan network conf
|
2024-10-25 20:53:24 +08:00
|
|
|
command:
|
|
|
|
cmd: "{{ bin_dir }}/kubectl create -f -"
|
|
|
|
stdin: |
|
2018-11-04 17:07:38 +08:00
|
|
|
apiVersion: "k8s.cni.cncf.io/v1"
|
|
|
|
kind: NetworkAttachmentDefinition
|
|
|
|
metadata:
|
|
|
|
name: macvlan-conf
|
|
|
|
spec:
|
|
|
|
config: '{
|
2020-05-07 02:13:09 +08:00
|
|
|
"cniVersion": "0.4.0",
|
2018-11-04 17:07:38 +08:00
|
|
|
"type": "macvlan",
|
|
|
|
"master": "eth0",
|
|
|
|
"mode": "bridge",
|
|
|
|
"ipam": {
|
|
|
|
"type": "host-local",
|
|
|
|
"subnet": "192.168.1.0/24",
|
|
|
|
"rangeStart": "192.168.1.200",
|
|
|
|
"rangeEnd": "192.168.1.216",
|
|
|
|
"routes": [
|
|
|
|
{ "dst": "0.0.0.0/0" }
|
|
|
|
],
|
|
|
|
"gateway": "192.168.1.1"
|
|
|
|
}
|
|
|
|
}'
|
2024-10-25 20:53:24 +08:00
|
|
|
---
|
2018-11-04 17:07:38 +08:00
|
|
|
apiVersion: v1
|
|
|
|
kind: Pod
|
|
|
|
metadata:
|
|
|
|
name: samplepod
|
|
|
|
annotations:
|
|
|
|
k8s.v1.cni.cncf.io/networks: macvlan-conf
|
|
|
|
spec:
|
|
|
|
containers:
|
|
|
|
- name: samplepod
|
|
|
|
command: ["/bin/bash", "-c", "sleep 2000000000000"]
|
|
|
|
image: dougbtv/centos-network
|
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2023-07-05 11:36:54 +08:00
|
|
|
- kube_network_plugin_multus | default(false) | bool
|
2018-11-04 17:07:38 +08:00
|
|
|
|
2020-07-28 16:39:08 +08:00
|
|
|
- name: Check secondary macvlan interface
|
|
|
|
command: "{{ bin_dir }}/kubectl exec samplepod -- ip addr show dev net1"
|
2018-11-04 17:07:38 +08:00
|
|
|
register: output
|
|
|
|
until: output.rc == 0
|
|
|
|
retries: 90
|
|
|
|
changed_when: false
|
|
|
|
when:
|
2021-03-24 08:26:05 +08:00
|
|
|
- inventory_hostname == groups['kube_control_plane'][0]
|
2023-07-05 11:36:54 +08:00
|
|
|
- kube_network_plugin_multus | default(false) | bool
|