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
|
|
|
|
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
|
2016-11-28 12:18:06 +00:00
|
|
|
no_log: true
|
|
|
|
|
|
|
|
- name: Get hostnet pods
|
|
|
|
command: "{{bin_dir}}/kubectl get pods -o
|
|
|
|
jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {end}'"
|
|
|
|
register: hostnet_pods
|
|
|
|
|
|
|
|
- name: Get running pods
|
|
|
|
command: "{{bin_dir}}/kubectl get pods -o
|
|
|
|
jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {end}'"
|
|
|
|
register: running_pods
|
2016-02-10 10:51:39 +00:00
|
|
|
|
|
|
|
- set_fact:
|
|
|
|
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}}"
|