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