2016-02-10 18:51:39 +08:00
|
|
|
---
|
2017-01-09 23:45:48 +08:00
|
|
|
- hosts: kube-master[0]
|
2016-02-10 18:51:39 +08:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
|
2017-01-05 18:35:16 +08:00
|
|
|
- name: Force binaries directory for Container Linux by CoreOS
|
2016-11-16 01:17:30 +08:00
|
|
|
set_fact:
|
|
|
|
bin_dir: "/opt/bin"
|
2017-01-05 23:32:08 +08:00
|
|
|
when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
|
2016-11-16 01:17:30 +08:00
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
bin_dir: "/usr/local/bin"
|
2017-01-05 23:32:08 +08:00
|
|
|
when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
|
2016-11-16 01:17:30 +08:00
|
|
|
|
2017-02-03 23:50:58 +08:00
|
|
|
- name: Check kubectl output
|
|
|
|
shell: "{{bin_dir}}/kubectl get pods --all-namespaces -owide"
|
|
|
|
register: get_pods
|
|
|
|
|
2017-09-10 04:38:38 +08:00
|
|
|
- debug: msg="{{get_pods.stdout.split('\n')}}"
|
2017-02-03 23:50:58 +08:00
|
|
|
|
2016-02-10 18:51:39 +08:00
|
|
|
- name: Get pod names
|
2016-11-16 01:17:30 +08:00
|
|
|
shell: "{{bin_dir}}/kubectl get pods -o json"
|
2016-02-10 18:51:39 +08:00
|
|
|
register: pods
|
2017-04-04 18:12:24 +08:00
|
|
|
until: '"ContainerCreating" not in pods.stdout'
|
|
|
|
retries: 60
|
|
|
|
delay: 2
|
2016-11-28 20:18:06 +08:00
|
|
|
no_log: true
|
|
|
|
|
|
|
|
- name: Get hostnet pods
|
|
|
|
command: "{{bin_dir}}/kubectl get pods -o
|
2017-02-03 23:50:58 +08:00
|
|
|
jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
|
2016-11-28 20:18:06 +08:00
|
|
|
register: hostnet_pods
|
|
|
|
|
|
|
|
- name: Get running pods
|
|
|
|
command: "{{bin_dir}}/kubectl get pods -o
|
2017-02-03 23:50:58 +08:00
|
|
|
jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
|
2016-11-28 20:18:06 +08:00
|
|
|
register: running_pods
|
2016-02-10 18:51:39 +08:00
|
|
|
|
|
|
|
- set_fact:
|
2017-02-23 22:14:28 +08:00
|
|
|
kube_pods_subnet: 10.233.64.0/18
|
2016-02-10 18:51:39 +08:00
|
|
|
pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute = 'metadata.name') | list }}"
|
2016-11-28 20:18:06 +08:00
|
|
|
pod_ips: "{{ (pods.stdout | from_json)['items'] | selectattr('status.podIP', 'defined') | map(attribute = 'status.podIP') | list }}"
|
|
|
|
pods_hostnet: |
|
|
|
|
{% set list = hostnet_pods.stdout.split(" ") %}
|
|
|
|
{{list}}
|
|
|
|
pods_running: |
|
|
|
|
{% set list = running_pods.stdout.split(" ") %}
|
|
|
|
{{list}}
|
2016-02-10 18:51:39 +08:00
|
|
|
|
|
|
|
- name: Check pods IP are in correct network
|
|
|
|
assert:
|
|
|
|
that: item | ipaddr(kube_pods_subnet)
|
2016-11-28 20:18:06 +08:00
|
|
|
when: not item in pods_hostnet and item in pods_running
|
2016-05-11 23:37:15 +08:00
|
|
|
with_items: "{{pod_ips}}"
|
2016-02-10 18:51:39 +08:00
|
|
|
|
|
|
|
- name: Ping between pods is working
|
2016-11-28 20:18:06 +08:00
|
|
|
shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
|
|
|
|
when: not item[0] in pods_hostnet and not item[1] in pods_hostnet
|
|
|
|
with_nested:
|
|
|
|
- "{{pod_names}}"
|
|
|
|
- "{{pod_ips}}"
|
|
|
|
|
|
|
|
- name: Ping between hostnet pods is working
|
|
|
|
shell: "{{bin_dir}}/kubectl exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
|
|
|
|
when: item[0] in pods_hostnet and item[1] in pods_hostnet
|
|
|
|
with_nested:
|
|
|
|
- "{{pod_names}}"
|
|
|
|
- "{{pod_ips}}"
|