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.

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