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.

208 lines
7.6 KiB

  1. ---
  2. - name: Stop if legacy encapsulation variables are detected (ipip)
  3. assert:
  4. that:
  5. - ipip is not defined
  6. msg: "'ipip' configuration variable is deprecated, please configure your inventory with 'calico_ipip_mode' set to 'Always' or 'CrossSubnet' according to your specific needs"
  7. run_once: true
  8. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  9. - name: Stop if legacy encapsulation variables are detected (ipip_mode)
  10. assert:
  11. that:
  12. - ipip_mode is not defined
  13. msg: "'ipip_mode' configuration variable is deprecated, please configure your inventory with 'calico_ipip_mode' set to 'Always' or 'CrossSubnet' according to your specific needs"
  14. run_once: true
  15. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  16. - name: Stop if legacy encapsulation variables are detected (calcio_ipam_autoallocateblocks)
  17. assert:
  18. that:
  19. - calcio_ipam_autoallocateblocks is not defined
  20. msg: "'calcio_ipam_autoallocateblocks' configuration variable is deprecated, it's a typo, please configure your inventory with 'calico_ipam_autoallocateblocks' set to 'true' or 'false' according to your specific needs"
  21. run_once: true
  22. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  23. - name: Stop if incompatible network plugin and cloudprovider
  24. assert:
  25. that:
  26. - calico_ipip_mode == 'Never'
  27. - calico_vxlan_mode in ['Always', 'CrossSubnet']
  28. msg: "When using cloud_provider azure and network_plugin calico calico_ipip_mode must be 'Never' and calico_vxlan_mode 'Always' or 'CrossSubnet'"
  29. when:
  30. - cloud_provider is defined and cloud_provider == 'azure'
  31. run_once: true
  32. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  33. - name: Stop if supported Calico versions
  34. assert:
  35. that:
  36. - "calico_version in calico_crds_archive_checksums.keys()"
  37. msg: "Calico version not supported {{ calico_version }} not in {{ calico_crds_archive_checksums.keys() }}"
  38. run_once: true
  39. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  40. - name: Check if calicoctl.sh exists
  41. stat:
  42. path: "{{ bin_dir }}/calicoctl.sh"
  43. register: calicoctl_sh_exists
  44. run_once: true
  45. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  46. - name: Check if calico ready
  47. command: "{{ bin_dir }}/calicoctl.sh get ClusterInformation default"
  48. register: calico_ready
  49. run_once: true
  50. ignore_errors: true
  51. retries: 5
  52. delay: 10
  53. until: calico_ready.rc == 0
  54. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  55. when: calicoctl_sh_exists.stat.exists
  56. - name: Check that current calico version is enough for upgrade
  57. run_once: true
  58. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  59. when: calicoctl_sh_exists.stat.exists and calico_ready.rc == 0
  60. block:
  61. - name: Get current calico version
  62. shell: "set -o pipefail && {{ bin_dir }}/calicoctl.sh version | grep 'Client Version:' | awk '{ print $3}'"
  63. args:
  64. executable: /bin/bash
  65. register: calico_version_on_server
  66. changed_when: false
  67. - name: Assert that current calico version is enough for upgrade
  68. assert:
  69. that:
  70. - calico_version_on_server.stdout is version(calico_min_version_required, '>=')
  71. msg: >
  72. Your version of calico is not fresh enough for upgrade.
  73. Minimum version is {{ calico_min_version_required }} supported by the previous kubespray release.
  74. But current version is {{ calico_version_on_server.stdout }}.
  75. - name: "Check that cluster_id is set and a valid IPv4 address if calico_rr enabled"
  76. assert:
  77. that:
  78. - cluster_id is defined
  79. - cluster_id is ansible.utils.ipv4
  80. msg: "A unique cluster_id is required if using calico_rr, and it must be a valid IPv4 address"
  81. when:
  82. - peer_with_calico_rr
  83. - inventory_hostname == groups['kube_control_plane'][0]
  84. run_once: true
  85. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  86. - name: "Check that calico_rr nodes are in k8s_cluster group"
  87. assert:
  88. that:
  89. - '"k8s_cluster" in group_names'
  90. msg: "calico_rr must be a child group of k8s_cluster group"
  91. when:
  92. - '"calico_rr" in group_names'
  93. run_once: true
  94. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  95. - name: "Check vars defined correctly"
  96. assert:
  97. that:
  98. - "calico_pool_name is defined"
  99. - "calico_pool_name is match('^[a-zA-Z0-9-_\\\\.]{2,63}$')"
  100. msg: "calico_pool_name contains invalid characters"
  101. run_once: true
  102. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  103. - name: "Check calico network backend defined correctly"
  104. assert:
  105. that:
  106. - "calico_network_backend in ['bird', 'vxlan', 'none']"
  107. msg: "calico network backend is not 'bird', 'vxlan' or 'none'"
  108. run_once: true
  109. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  110. - name: "Check ipip and vxlan mode defined correctly"
  111. run_once: true
  112. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  113. assert:
  114. that:
  115. - "calico_ipip_mode in ['Always', 'CrossSubnet', 'Never']"
  116. - "calico_vxlan_mode in ['Always', 'CrossSubnet', 'Never']"
  117. msg: "calico inter host encapsulation mode is not 'Always', 'CrossSubnet' or 'Never'"
  118. - name: "Check ipip and vxlan mode if simultaneously enabled"
  119. assert:
  120. that:
  121. - "calico_vxlan_mode in ['Never']"
  122. msg: "IP in IP and VXLAN mode is mutualy exclusive modes"
  123. when:
  124. - "calico_ipip_mode in ['Always', 'CrossSubnet']"
  125. run_once: true
  126. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  127. - name: "Check ipip and vxlan mode if simultaneously enabled"
  128. assert:
  129. that:
  130. - "calico_ipip_mode in ['Never']"
  131. msg: "IP in IP and VXLAN mode is mutualy exclusive modes"
  132. when:
  133. - "calico_vxlan_mode in ['Always', 'CrossSubnet']"
  134. run_once: true
  135. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  136. - name: "Get Calico {{ calico_pool_name }} configuration"
  137. command: "{{ bin_dir }}/calicoctl.sh get ipPool {{ calico_pool_name }} -o json"
  138. failed_when: false
  139. changed_when: false
  140. check_mode: false
  141. register: calico
  142. run_once: true
  143. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  144. - name: "Set calico_pool_conf"
  145. set_fact:
  146. calico_pool_conf: '{{ calico.stdout | from_json }}'
  147. when: calico.rc == 0 and calico.stdout
  148. run_once: true
  149. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  150. - name: "Check if inventory match current cluster configuration"
  151. assert:
  152. that:
  153. - calico_pool_conf.spec.blockSize | int == calico_pool_blocksize | int
  154. - calico_pool_conf.spec.cidr == (calico_pool_cidr | default(kube_pods_subnet))
  155. - not calico_pool_conf.spec.ipipMode is defined or calico_pool_conf.spec.ipipMode == calico_ipip_mode
  156. - not calico_pool_conf.spec.vxlanMode is defined or calico_pool_conf.spec.vxlanMode == calico_vxlan_mode
  157. msg: "Your inventory doesn't match the current cluster configuration"
  158. when:
  159. - calico_pool_conf is defined
  160. run_once: true
  161. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  162. - name: "Check kdd calico_datastore if calico_apiserver_enabled"
  163. assert:
  164. that: calico_datastore == "kdd"
  165. msg: "When using calico apiserver you need to use the kubernetes datastore"
  166. when:
  167. - calico_apiserver_enabled
  168. run_once: true
  169. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  170. - name: "Check kdd calico_datastore if typha_enabled"
  171. assert:
  172. that: calico_datastore == "kdd"
  173. msg: "When using typha you need to use the kubernetes datastore"
  174. when:
  175. - typha_enabled
  176. run_once: true
  177. delegate_to: "{{ groups['kube_control_plane'][0] }}"
  178. - name: "Check ipip mode is Never for calico ipv6"
  179. assert:
  180. that:
  181. - "calico_ipip_mode_ipv6 in ['Never']"
  182. msg: "Calico doesn't support ipip tunneling for the IPv6"
  183. when:
  184. - enable_dual_stack_networks
  185. run_once: true
  186. delegate_to: "{{ groups['kube_control_plane'][0] }}"