81 lines
2.9 KiB
YAML
81 lines
2.9 KiB
YAML
---
|
|
- hosts: kube-master[0]
|
|
|
|
tasks:
|
|
|
|
- name: Force binaries directory for Container Linux by CoreOS
|
|
set_fact:
|
|
bin_dir: "/opt/bin"
|
|
when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
|
|
|
|
- set_fact:
|
|
bin_dir: "/usr/local/bin"
|
|
when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
|
|
|
|
- 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
|
|
until:
|
|
# 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
|
|
no_log: true
|
|
|
|
- name: Get pod names
|
|
shell: "{{bin_dir}}/kubectl get pods -n test -o json"
|
|
register: pods
|
|
no_log: true
|
|
|
|
- name: Get hostnet pods
|
|
command: "{{bin_dir}}/kubectl get pods -n test -o
|
|
jsonpath='{range .items[?(.spec.hostNetwork)]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
|
|
register: hostnet_pods
|
|
no_log: true
|
|
|
|
- name: Get running pods
|
|
command: "{{bin_dir}}/kubectl get pods -n test -o
|
|
jsonpath='{range .items[?(.status.phase==\"Running\")]}{.metadata.name} {.status.podIP} {.status.containerStatuses} {end}'"
|
|
register: running_pods
|
|
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')}}"
|
|
|
|
- set_fact:
|
|
kube_pods_subnet: 10.233.64.0/18
|
|
pod_names: "{{ (pods.stdout | from_json)['items'] | map(attribute = 'metadata.name') | list }}"
|
|
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}}
|
|
|
|
- name: Check pods IP are in correct network
|
|
assert:
|
|
that: item | ipaddr(kube_pods_subnet)
|
|
when: not item in pods_hostnet and item in pods_running
|
|
with_items: "{{pod_ips}}"
|
|
|
|
- name: Ping between pods is working
|
|
shell: "{{bin_dir}}/kubectl -n test 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 -n test 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}}"
|