2016-11-28 12:18:06 +00:00
|
|
|
---
|
|
|
|
- hosts: kube-node
|
|
|
|
tasks:
|
|
|
|
- name: Test tunl0 routes
|
|
|
|
shell: "! /sbin/ip ro | grep '/26 via' | grep -v tunl0"
|
2018-10-11 07:45:00 +00:00
|
|
|
when:
|
|
|
|
- (ipip|default(false) or cloud_provider is defined)
|
|
|
|
- kube_network_plugin == 'calico'
|
2016-11-28 12:18:06 +00:00
|
|
|
|
|
|
|
- hosts: k8s-cluster
|
|
|
|
vars:
|
|
|
|
agent_report_interval: 10
|
|
|
|
netcheck_namespace: default
|
|
|
|
netchecker_port: 31081
|
|
|
|
|
|
|
|
tasks:
|
2017-01-05 10:35:16 +00:00
|
|
|
- name: Force binaries directory for Container Linux by CoreOS
|
2016-11-28 12:18:06 +00:00
|
|
|
set_fact:
|
|
|
|
bin_dir: "/opt/bin"
|
2017-01-05 15:32:08 +00:00
|
|
|
when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
|
2016-11-28 12:18:06 +00:00
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
bin_dir: "/usr/local/bin"
|
2017-01-05 15:32:08 +00:00
|
|
|
when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
|
2016-11-28 12:18:06 +00:00
|
|
|
|
|
|
|
- name: Wait for netchecker server
|
|
|
|
shell: "{{ bin_dir }}/kubectl get pods --namespace {{netcheck_namespace}} | grep ^netchecker-server"
|
|
|
|
delegate_to: "{{groups['kube-master'][0]}}"
|
|
|
|
run_once: true
|
|
|
|
register: ncs_pod
|
|
|
|
until: ncs_pod.stdout.find('Running') != -1
|
|
|
|
retries: 3
|
|
|
|
delay: 10
|
|
|
|
|
|
|
|
- name: Wait for netchecker agents
|
|
|
|
shell: "{{ bin_dir }}/kubectl get pods --namespace {{netcheck_namespace}} | grep '^netchecker-agent-.*Running'"
|
|
|
|
run_once: true
|
|
|
|
delegate_to: "{{groups['kube-master'][0]}}"
|
|
|
|
register: nca_pod
|
2018-10-11 07:45:00 +00:00
|
|
|
until: nca_pod.stdout_lines|length >= groups['kube-node']|intersect(play_hosts)|length * 2
|
2016-11-28 12:18:06 +00:00
|
|
|
retries: 3
|
|
|
|
delay: 10
|
|
|
|
|
|
|
|
- name: Get netchecker agents
|
|
|
|
uri: url=http://localhost:{{netchecker_port}}/api/v1/agents/ return_content=yes
|
|
|
|
run_once: true
|
2017-02-17 20:14:10 +00:00
|
|
|
delegate_to: "{{groups['kube-master'][0]}}"
|
2016-11-28 12:18:06 +00:00
|
|
|
register: agents
|
2017-02-20 14:09:34 +00:00
|
|
|
retries: 18
|
2016-11-28 12:18:06 +00:00
|
|
|
delay: "{{ agent_report_interval }}"
|
2018-10-11 07:45:00 +00:00
|
|
|
until: agents.content|length > 0 and
|
2016-11-28 12:18:06 +00:00
|
|
|
agents.content[0] == '{' and
|
2018-10-11 07:45:00 +00:00
|
|
|
agents.content|from_json|length >= groups['kube-node']|intersect(play_hosts)|length * 2
|
2016-12-27 11:38:54 +00:00
|
|
|
failed_when: false
|
2016-11-28 12:18:06 +00:00
|
|
|
no_log: true
|
|
|
|
|
|
|
|
- debug: var=agents.content|from_json
|
2018-10-16 22:33:30 +00:00
|
|
|
failed_when: not agents is success and not agents.content=='{}'
|
2016-11-28 12:18:06 +00:00
|
|
|
run_once: true
|
2017-02-20 14:09:34 +00:00
|
|
|
|
2016-11-28 12:18:06 +00:00
|
|
|
- name: Check netchecker status
|
|
|
|
uri: url=http://localhost:{{netchecker_port}}/api/v1/connectivity_check status_code=200 return_content=yes
|
2017-02-17 20:14:10 +00:00
|
|
|
delegate_to: "{{groups['kube-master'][0]}}"
|
2016-11-28 12:18:06 +00:00
|
|
|
run_once: true
|
|
|
|
register: result
|
|
|
|
retries: 3
|
|
|
|
delay: "{{ agent_report_interval }}"
|
|
|
|
no_log: true
|
2016-12-27 11:38:54 +00:00
|
|
|
failed_when: false
|
2018-10-20 11:56:55 +00:00
|
|
|
when:
|
|
|
|
- agents.content != '{}'
|
2016-11-28 12:18:06 +00:00
|
|
|
|
|
|
|
- debug: var=result.content|from_json
|
2018-10-16 22:33:30 +00:00
|
|
|
failed_when: not result is success
|
2016-11-28 12:18:06 +00:00
|
|
|
run_once: true
|
2018-10-20 11:56:55 +00:00
|
|
|
when: not agents.content == '{}'
|
2017-02-20 14:09:34 +00:00
|
|
|
delegate_to: "{{groups['kube-master'][0]}}"
|
2016-12-15 09:28:03 +00:00
|
|
|
|
|
|
|
- debug: msg="Cannot get reports from agents, consider as PASSING"
|
|
|
|
run_once: true
|
2018-10-20 11:56:55 +00:00
|
|
|
when:
|
|
|
|
- agents.content == '{}'
|
2018-11-04 09:07:38 +00:00
|
|
|
|
|
|
|
- name: Create macvlan network conf
|
|
|
|
# We cannot use only shell: below because Ansible will render the text
|
|
|
|
# with leading spaces, which means the shell will never find the string
|
|
|
|
# EOF at the beginning of a line. We can avoid Ansible's unhelpful
|
|
|
|
# heuristics by using the cmd parameter like this:
|
|
|
|
shell:
|
|
|
|
cmd: |
|
|
|
|
cat <<EOF | {{ bin_dir }}/kubectl create -f -
|
|
|
|
apiVersion: "k8s.cni.cncf.io/v1"
|
|
|
|
kind: NetworkAttachmentDefinition
|
|
|
|
metadata:
|
|
|
|
name: macvlan-conf
|
|
|
|
spec:
|
|
|
|
config: '{
|
|
|
|
"cniVersion": "0.3.0",
|
|
|
|
"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"
|
|
|
|
}
|
|
|
|
}'
|
|
|
|
EOF
|
|
|
|
when:
|
|
|
|
- kube_network_plugin_multus|default(false)
|
|
|
|
|
|
|
|
- name: Annotate pod with macvlan network
|
|
|
|
# We cannot use only shell: below because Ansible will render the text
|
|
|
|
# with leading spaces, which means the shell will never find the string
|
|
|
|
# EOF at the beginning of a line. We can avoid Ansible's unhelpful
|
|
|
|
# heuristics by using the cmd parameter like this:
|
|
|
|
shell:
|
|
|
|
cmd: |
|
|
|
|
cat <<EOF | {{ bin_dir }}/kubectl create -f -
|
|
|
|
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
|
|
|
|
EOF
|
|
|
|
when:
|
|
|
|
- kube_network_plugin_multus|default(false)
|
|
|
|
|
|
|
|
- name: Check secondary macvlan interface
|
|
|
|
shell: "{{ bin_dir }}/kubectl exec samplepod -- ip addr show dev net1"
|
|
|
|
register: output
|
|
|
|
until: output.rc == 0
|
|
|
|
retries: 90
|
|
|
|
changed_when: false
|
|
|
|
when:
|
|
|
|
- kube_network_plugin_multus|default(false)
|