2016-02-10 18:51:39 +08:00
|
|
|
---
|
2017-01-09 23:45:48 +08:00
|
|
|
- hosts: kube-master[0]
|
2019-04-24 07:12:00 +08:00
|
|
|
vars:
|
|
|
|
test_image_repo: busybox
|
|
|
|
test_image_tag: latest
|
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
|
|
|
|
2019-04-24 07:12:00 +08:00
|
|
|
- name: Create test namespace
|
|
|
|
shell: "{{bin_dir}}/kubectl create namespace test"
|
|
|
|
|
|
|
|
- name: Run a replica controller composed of 2 pods in test ns
|
|
|
|
shell: "{{bin_dir}}/kubectl run test --image={{test_image_repo}}:{{test_image_tag}} --namespace test --replicas=2 --command -- tail -f /dev/null"
|
|
|
|
|
2019-04-20 21:11:40 +08:00
|
|
|
- name: Check that all pods are running and ready
|
|
|
|
shell: "{{bin_dir}}/kubectl get pods --namespace test --no-headers -o yaml"
|
|
|
|
register: run_pods_log
|
2017-09-26 17:38:58 +08:00
|
|
|
until:
|
2019-04-20 21:11:40 +08: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 20:18:06 +08:00
|
|
|
no_log: true
|
|
|
|
|
2017-09-26 17:38:58 +08:00
|
|
|
- name: Get pod names
|
2018-04-05 04:26:16 +08:00
|
|
|
shell: "{{bin_dir}}/kubectl get pods -n test -o json"
|
2017-09-26 17:38:58 +08:00
|
|
|
register: pods
|
|
|
|
no_log: true
|
|
|
|
|
2019-04-24 07:12:00 +08:00
|
|
|
- debug: msg="{{pods.stdout.split('\n')}}"
|
|
|
|
failed_when: not run_pods_log is success
|
|
|
|
|
2016-11-28 20:18:06 +08:00
|
|
|
- name: Get hostnet pods
|
2018-04-05 04:26:16 +08:00
|
|
|
command: "{{bin_dir}}/kubectl get pods -n test -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
|
2017-09-15 20:19:37 +08:00
|
|
|
no_log: true
|
2016-11-28 20:18:06 +08:00
|
|
|
|
|
|
|
- name: Get running pods
|
2018-04-05 04:26:16 +08:00
|
|
|
command: "{{bin_dir}}/kubectl get pods -n test -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
|
2017-09-15 20:19:37 +08:00
|
|
|
no_log: true
|
|
|
|
|
|
|
|
- name: Check kubectl output
|
|
|
|
shell: "{{bin_dir}}/kubectl get pods --all-namespaces -owide"
|
|
|
|
register: get_pods
|
|
|
|
no_log: true
|
|
|
|
|
|
|
|
- debug: msg="{{get_pods.stdout.split('\n')}}"
|
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
|
2019-04-24 04:36:03 +08:00
|
|
|
shell: "{{bin_dir}}/kubectl -n test exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
|
2016-11-28 20:18:06 +08:00
|
|
|
when: not item[0] in pods_hostnet and not item[1] in pods_hostnet
|
|
|
|
with_nested:
|
2019-04-01 17:38:33 +08:00
|
|
|
- "{{pod_names}}"
|
|
|
|
- "{{pod_ips}}"
|
2016-11-28 20:18:06 +08:00
|
|
|
|
|
|
|
- name: Ping between hostnet pods is working
|
2019-04-24 04:36:03 +08:00
|
|
|
shell: "{{bin_dir}}/kubectl -n test exec {{item[0]}} -- ping -c 4 {{ item[1] }}"
|
2016-11-28 20:18:06 +08:00
|
|
|
when: item[0] in pods_hostnet and item[1] in pods_hostnet
|
|
|
|
with_nested:
|
2019-04-01 17:38:33 +08:00
|
|
|
- "{{pod_names}}"
|
|
|
|
- "{{pod_ips}}"
|
2019-04-24 07:12:00 +08:00
|
|
|
|
|
|
|
- name: Delete test namespace
|
|
|
|
shell: "{{bin_dir}}/kubectl delete namespace test"
|