2016-02-10 10:51:39 +00:00
|
|
|
---
|
2017-01-09 15:45:48 +00:00
|
|
|
- hosts: kube-master[0]
|
2019-04-23 23:12:00 +00:00
|
|
|
vars:
|
|
|
|
test_image_repo: busybox
|
|
|
|
test_image_tag: latest
|
2016-02-10 10:51:39 +00:00
|
|
|
|
|
|
|
tasks:
|
2020-08-28 09:28:53 +00:00
|
|
|
- name: Force binaries directory for Flatcar Container Linux by Kinvolk
|
2016-11-15 17:17:30 +00:00
|
|
|
set_fact:
|
|
|
|
bin_dir: "/opt/bin"
|
2020-08-28 09:28:53 +00:00
|
|
|
when: ansible_os_family in ["Flatcar Container Linux by Kinvolk"]
|
2016-11-15 17:17:30 +00:00
|
|
|
|
2019-05-16 07:27:43 +00:00
|
|
|
- name: Force binaries directory for other hosts
|
|
|
|
set_fact:
|
2016-11-15 17:17:30 +00:00
|
|
|
bin_dir: "/usr/local/bin"
|
2020-08-28 09:28:53 +00:00
|
|
|
when: not ansible_os_family in ["Flatcar Container Linux by Kinvolk"]
|
2016-11-15 17:17:30 +00:00
|
|
|
|
2020-07-27 13:24:17 +00:00
|
|
|
- name: Create test namespace # noqa 301 305
|
2019-05-02 21:24:21 +00:00
|
|
|
shell: "{{ bin_dir }}/kubectl create namespace test"
|
2019-04-23 23:12:00 +00:00
|
|
|
|
2020-07-28 15:39:47 +00:00
|
|
|
- name: Run 2 busybox pods in test ns # noqa 305
|
2020-05-03 19:36:34 +00:00
|
|
|
shell: "{{ bin_dir }}/kubectl run {{ item }} --image={{ test_image_repo }}:{{ test_image_tag }} --namespace test --command -- tail -f /dev/null"
|
2020-07-28 15:39:47 +00:00
|
|
|
changed_when: false
|
2020-05-03 19:36:34 +00:00
|
|
|
loop:
|
|
|
|
- busybox1
|
|
|
|
- busybox2
|
2019-04-23 23:12:00 +00:00
|
|
|
|
2020-04-01 14:23:29 +00:00
|
|
|
- import_role:
|
|
|
|
name: cluster-dump
|
|
|
|
|
2020-07-28 15:39:47 +00:00
|
|
|
- name: Check that all pods are running and ready # noqa 305
|
2019-05-02 21:24:21 +00:00
|
|
|
shell: "{{ bin_dir }}/kubectl get pods --namespace test --no-headers -o yaml"
|
2020-07-28 15:39:47 +00:00
|
|
|
changed_when: false
|
2019-04-20 13:11:40 +00:00
|
|
|
register: run_pods_log
|
2017-09-26 09:38:58 +00:00
|
|
|
until:
|
2019-04-20 13:11:40 +00:00
|
|
|
# Check that all pods are running
|
|
|
|
- '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.phase") | unique | list == ["Running"]'
|
|
|
|
# Check that all pods are ready
|
|
|
|
- '(run_pods_log.stdout | from_yaml)["items"] | map(attribute = "status.containerStatuses") | map("map", attribute = "ready") | map("min") | min'
|
|
|
|
retries: 18
|
|
|
|
delay: 10
|
|
|
|
failed_when: false
|
2016-11-28 12:18:06 +00:00
|
|
|
no_log: true
|
|
|
|
|
2020-07-28 15:39:47 +00:00
|
|
|
- name: Get pod names # noqa 305
|
2019-05-02 21:24:21 +00:00
|
|
|
shell: "{{ bin_dir }}/kubectl get pods -n test -o json"
|
2020-07-28 15:39:47 +00:00
|
|
|
changed_when: false
|
2017-09-26 09:38:58 +00:00
|
|
|
register: pods
|
|
|
|
no_log: true
|
|
|
|
|
2019-05-16 07:27:43 +00:00
|
|
|
- debug:
|
|
|
|
msg: "{{ pods.stdout.split('\n') }}"
|
2019-04-23 23:12:00 +00:00
|
|
|
failed_when: not run_pods_log is success
|
|
|
|
|
2020-07-28 15:39:47 +00:00
|
|
|
- name: Get hostnet pods
|
2019-05-02 21:24:21 +00:00
|
|
|
command: "{{ bin_dir }}/kubectl get pods -n test -o
|
2020-06-29 19:39:59 +00:00
|
|
|
jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
|
2020-07-28 15:39:47 +00:00
|
|
|
changed_when: false
|
2016-11-28 12:18:06 +00:00
|
|
|
register: hostnet_pods
|
2017-09-15 12:19:37 +00:00
|
|
|
no_log: true
|
2016-11-28 12:18:06 +00:00
|
|
|
|
2020-07-28 15:39:47 +00:00
|
|
|
- name: Get running pods
|
2019-05-02 21:24:21 +00:00
|
|
|
command: "{{ bin_dir }}/kubectl get pods -n test -o
|
2020-06-29 19:39:59 +00:00
|
|
|
jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
|
2020-07-28 15:39:47 +00:00
|
|
|
changed_when: False
|
2016-11-28 12:18:06 +00:00
|
|
|
register: running_pods
|
2017-09-15 12:19:37 +00:00
|
|
|
no_log: true
|
|
|
|
|
2020-07-28 15:39:47 +00:00
|
|
|
- name: Check kubectl output # noqa 305
|
2019-05-02 21:24:21 +00:00
|
|
|
shell: "{{ bin_dir }}/kubectl get pods --all-namespaces -owide"
|
2020-07-28 15:39:47 +00:00
|
|
|
changed_when: False
|
2017-09-15 12:19:37 +00:00
|
|
|
register: get_pods
|
|
|
|
no_log: true
|
|
|
|
|
2019-05-16 07:27:43 +00:00
|
|
|
- debug:
|
|
|
|
msg: "{{ get_pods.stdout.split('\n') }}"
|
2016-02-10 10:51:39 +00:00
|
|
|
|
2019-05-16 07:27:43 +00:00
|
|
|
- name: Set networking facts
|
|
|
|
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(" ") %}
|
2019-05-02 21:24:21 +00:00
|
|
|
{{ list }}
|
2016-11-28 12:18:06 +00:00
|
|
|
pods_running: |
|
|
|
|
{% set list = running_pods.stdout.split(" ") %}
|
2019-05-02 21:24:21 +00:00
|
|
|
{{ list }}
|
2016-02-10 10:51:39 +00:00
|
|
|
|
|
|
|
- name: Check pods IP are in correct network
|
|
|
|
assert:
|
|
|
|
that: item | ipaddr(kube_pods_subnet)
|
2019-05-16 07:27:43 +00:00
|
|
|
when:
|
|
|
|
- not item in pods_hostnet
|
|
|
|
- item in pods_running
|
2019-05-02 21:24:21 +00:00
|
|
|
with_items: "{{ pod_ips }}"
|
2016-02-10 10:51:39 +00:00
|
|
|
|
2020-07-28 08:39:08 +00:00
|
|
|
- name: Ping between pods is working
|
|
|
|
command: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- ping -c 4 {{ item[1] }}"
|
2019-05-16 07:27:43 +00:00
|
|
|
when:
|
|
|
|
- not item[0] in pods_hostnet
|
|
|
|
- not item[1] in pods_hostnet
|
2016-11-28 12:18:06 +00:00
|
|
|
with_nested:
|
2019-05-02 21:24:21 +00:00
|
|
|
- "{{ pod_names }}"
|
|
|
|
- "{{ pod_ips }}"
|
2016-11-28 12:18:06 +00:00
|
|
|
|
2020-07-28 08:39:08 +00:00
|
|
|
- name: Ping between hostnet pods is working
|
|
|
|
command: "{{ bin_dir }}/kubectl -n test exec {{ item[0] }} -- ping -c 4 {{ item[1] }}"
|
2019-05-16 07:27:43 +00:00
|
|
|
when:
|
|
|
|
- item[0] in pods_hostnet
|
|
|
|
- item[1] in pods_hostnet
|
2016-11-28 12:18:06 +00:00
|
|
|
with_nested:
|
2019-05-02 21:24:21 +00:00
|
|
|
- "{{ pod_names }}"
|
|
|
|
- "{{ pod_ips }}"
|