You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.9 KiB

  1. ---
  2. - hosts: kube-node
  3. tasks:
  4. - name: Test tunl0 routes
  5. shell: "! /sbin/ip ro | grep '/26 via' | grep -v tunl0"
  6. when:
  7. - (ipip|default(false) or cloud_provider is defined)
  8. - kube_network_plugin == 'calico'
  9. - hosts: k8s-cluster
  10. vars:
  11. agent_report_interval: 10
  12. netcheck_namespace: default
  13. netchecker_port: 31081
  14. tasks:
  15. - name: Force binaries directory for Container Linux by CoreOS
  16. set_fact:
  17. bin_dir: "/opt/bin"
  18. when: ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  19. - set_fact:
  20. bin_dir: "/usr/local/bin"
  21. when: not ansible_os_family in ["CoreOS", "Container Linux by CoreOS"]
  22. - name: Wait for netchecker server
  23. shell: "{{ bin_dir }}/kubectl get pods --namespace {{netcheck_namespace}} | grep ^netchecker-server"
  24. delegate_to: "{{groups['kube-master'][0]}}"
  25. run_once: true
  26. register: ncs_pod
  27. until: ncs_pod.stdout.find('Running') != -1
  28. retries: 3
  29. delay: 10
  30. - name: Wait for netchecker agents
  31. shell: "{{ bin_dir }}/kubectl get pods --namespace {{netcheck_namespace}} | grep '^netchecker-agent-.*Running'"
  32. run_once: true
  33. delegate_to: "{{groups['kube-master'][0]}}"
  34. register: nca_pod
  35. until: nca_pod.stdout_lines|length >= groups['kube-node']|intersect(play_hosts)|length * 2
  36. retries: 3
  37. delay: 10
  38. - name: Get netchecker agents
  39. uri: url=http://localhost:{{netchecker_port}}/api/v1/agents/ return_content=yes
  40. run_once: true
  41. delegate_to: "{{groups['kube-master'][0]}}"
  42. register: agents
  43. retries: 18
  44. delay: "{{ agent_report_interval }}"
  45. until: agents.content|length > 0 and
  46. agents.content[0] == '{' and
  47. agents.content|from_json|length >= groups['kube-node']|intersect(play_hosts)|length * 2
  48. failed_when: false
  49. no_log: true
  50. - debug: var=agents.content|from_json
  51. failed_when: not agents is success and not agents.content=='{}'
  52. run_once: true
  53. - name: Check netchecker status
  54. uri: url=http://localhost:{{netchecker_port}}/api/v1/connectivity_check status_code=200 return_content=yes
  55. delegate_to: "{{groups['kube-master'][0]}}"
  56. run_once: true
  57. register: result
  58. retries: 3
  59. delay: "{{ agent_report_interval }}"
  60. no_log: true
  61. failed_when: false
  62. when:
  63. - agents.content != '{}'
  64. - debug: var=result.content|from_json
  65. failed_when: not result is success
  66. run_once: true
  67. when: not agents.content == '{}'
  68. delegate_to: "{{groups['kube-master'][0]}}"
  69. - debug: msg="Cannot get reports from agents, consider as PASSING"
  70. run_once: true
  71. when:
  72. - agents.content == '{}'
  73. - name: Create macvlan network conf
  74. # We cannot use only shell: below because Ansible will render the text
  75. # with leading spaces, which means the shell will never find the string
  76. # EOF at the beginning of a line. We can avoid Ansible's unhelpful
  77. # heuristics by using the cmd parameter like this:
  78. shell:
  79. cmd: |
  80. cat <<EOF | {{ bin_dir }}/kubectl create -f -
  81. apiVersion: "k8s.cni.cncf.io/v1"
  82. kind: NetworkAttachmentDefinition
  83. metadata:
  84. name: macvlan-conf
  85. spec:
  86. config: '{
  87. "cniVersion": "0.3.0",
  88. "type": "macvlan",
  89. "master": "eth0",
  90. "mode": "bridge",
  91. "ipam": {
  92. "type": "host-local",
  93. "subnet": "192.168.1.0/24",
  94. "rangeStart": "192.168.1.200",
  95. "rangeEnd": "192.168.1.216",
  96. "routes": [
  97. { "dst": "0.0.0.0/0" }
  98. ],
  99. "gateway": "192.168.1.1"
  100. }
  101. }'
  102. EOF
  103. when:
  104. - kube_network_plugin_multus|default(false)
  105. - name: Annotate pod with macvlan network
  106. # We cannot use only shell: below because Ansible will render the text
  107. # with leading spaces, which means the shell will never find the string
  108. # EOF at the beginning of a line. We can avoid Ansible's unhelpful
  109. # heuristics by using the cmd parameter like this:
  110. shell:
  111. cmd: |
  112. cat <<EOF | {{ bin_dir }}/kubectl create -f -
  113. apiVersion: v1
  114. kind: Pod
  115. metadata:
  116. name: samplepod
  117. annotations:
  118. k8s.v1.cni.cncf.io/networks: macvlan-conf
  119. spec:
  120. containers:
  121. - name: samplepod
  122. command: ["/bin/bash", "-c", "sleep 2000000000000"]
  123. image: dougbtv/centos-network
  124. EOF
  125. when:
  126. - kube_network_plugin_multus|default(false)
  127. - name: Check secondary macvlan interface
  128. shell: "{{ bin_dir }}/kubectl exec samplepod -- ip addr show dev net1"
  129. register: output
  130. until: output.rc == 0
  131. retries: 90
  132. changed_when: false
  133. when:
  134. - kube_network_plugin_multus|default(false)