2018-08-23 22:17:18 +08:00
---
2022-04-14 16:08:46 +08:00
- name : Stop if legacy encapsulation variables are detected (ipip)
assert :
that :
- ipip is not defined
msg : "'ipip' configuration variable is deprecated, please configure your inventory with 'calico_ipip_mode' set to 'Always' or 'CrossSubnet' according to your specific needs"
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
- name : Stop if legacy encapsulation variables are detected (ipip_mode)
assert :
that :
- ipip_mode is not defined
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"
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2022-07-12 00:49:48 +08:00
- name : Stop if legacy encapsulation variables are detected (calcio_ipam_autoallocateblocks)
assert :
that :
- calcio_ipam_autoallocateblocks is not defined
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"
2024-08-28 13:30:56 +08:00
run_once : true
2022-07-12 00:49:48 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2022-04-14 16:08:46 +08:00
- name : Stop if incompatible network plugin and cloudprovider
assert :
that :
- calico_ipip_mode == 'Never'
- calico_vxlan_mode in ['Always', 'CrossSubnet']
msg : "When using cloud_provider azure and network_plugin calico calico_ipip_mode must be 'Never' and calico_vxlan_mode 'Always' or 'CrossSubnet'"
when :
- cloud_provider is defined and cloud_provider == 'azure'
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
- name : Stop if supported Calico versions
assert :
that :
- "calico_version in calico_crds_archive_checksums.keys()"
msg : "Calico version not supported {{ calico_version }} not in {{ calico_crds_archive_checksums.keys() }}"
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2023-03-10 21:48:40 +08:00
- name : Check if calicoctl.sh exists
2023-03-08 16:31:12 +08:00
stat :
path : "{{ bin_dir }}/calicoctl.sh"
2023-03-10 21:48:40 +08:00
register : calicoctl_sh_exists
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2023-03-21 12:51:06 +08:00
- name : Check if calico ready
command : "{{ bin_dir }}/calicoctl.sh get ClusterInformation default"
register : calico_ready
2024-08-28 13:30:56 +08:00
run_once : true
ignore_errors : true
2023-03-21 12:51:06 +08:00
retries : 5
delay : 10
until : calico_ready.rc == 0
2023-03-10 21:48:40 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
when : calicoctl_sh_exists.stat.exists
2022-04-14 16:08:46 +08:00
- name : Check that current calico version is enough for upgrade
2024-08-28 13:30:56 +08:00
run_once : true
2023-08-10 15:57:27 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
when : calicoctl_sh_exists.stat.exists and calico_ready.rc == 0
2023-03-08 16:31:12 +08:00
block :
- name : Get current calico version
shell : "set -o pipefail && {{ bin_dir }}/calicoctl.sh version | grep 'Client Version:' | awk '{ print $3}'"
args :
executable : /bin/bash
register : calico_version_on_server
changed_when : false
- name : Assert that current calico version is enough for upgrade
assert :
that :
- calico_version_on_server.stdout is version(calico_min_version_required, '>=')
msg : >
Your version of calico is not fresh enough for upgrade.
Minimum version is {{ calico_min_version_required }} supported by the previous kubespray release.
But current version is {{ calico_version_on_server.stdout }}.
2022-04-14 16:08:46 +08:00
2024-04-30 18:46:30 +08:00
- name : "Check that cluster_id is set and a valid IPv4 address if calico_rr enabled"
2022-04-14 16:08:46 +08:00
assert :
that :
- cluster_id is defined
2024-04-30 18:46:30 +08:00
- cluster_id is ansible.utils.ipv4
msg : "A unique cluster_id is required if using calico_rr, and it must be a valid IPv4 address"
2022-04-14 16:08:46 +08:00
when :
- peer_with_calico_rr
- inventory_hostname == groups['kube_control_plane'][0]
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
- name : "Check that calico_rr nodes are in k8s_cluster group"
assert :
that :
- '"k8s_cluster" in group_names'
msg : "calico_rr must be a child group of k8s_cluster group"
when :
- '"calico_rr" in group_names'
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2018-08-23 22:17:18 +08:00
- name : "Check vars defined correctly"
assert :
that :
- "calico_pool_name is defined"
2018-10-18 03:27:11 +08:00
- "calico_pool_name is match('^[a-zA-Z0-9-_\\\\.]{2,63}$')"
2020-03-12 16:20:37 +08:00
msg : "calico_pool_name contains invalid characters"
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2020-03-12 16:20:37 +08:00
- name : "Check calico network backend defined correctly"
assert :
that :
- "calico_network_backend in ['bird', 'vxlan', 'none']"
msg : "calico network backend is not 'bird', 'vxlan' or 'none'"
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2020-03-12 16:20:37 +08:00
- name : "Check ipip and vxlan mode defined correctly"
2024-08-28 13:30:56 +08:00
run_once : true
2023-08-10 15:57:27 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2020-03-12 16:20:37 +08:00
assert :
that :
- "calico_ipip_mode in ['Always', 'CrossSubnet', 'Never']"
- "calico_vxlan_mode in ['Always', 'CrossSubnet', 'Never']"
msg : "calico inter host encapsulation mode is not 'Always', 'CrossSubnet' or 'Never'"
- name : "Check ipip and vxlan mode if simultaneously enabled"
assert :
that :
- "calico_vxlan_mode in ['Never']"
msg : "IP in IP and VXLAN mode is mutualy exclusive modes"
when :
- "calico_ipip_mode in ['Always', 'CrossSubnet']"
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2020-03-12 16:20:37 +08:00
- name : "Check ipip and vxlan mode if simultaneously enabled"
assert :
that :
- "calico_ipip_mode in ['Never']"
msg : "IP in IP and VXLAN mode is mutualy exclusive modes"
when :
- "calico_vxlan_mode in ['Always', 'CrossSubnet']"
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2021-01-05 01:07:56 +08:00
- name : "Get Calico {{ calico_pool_name }} configuration"
2022-08-30 23:07:02 +08:00
command : "{{ bin_dir }}/calicoctl.sh get ipPool {{ calico_pool_name }} -o json"
2024-08-28 13:30:56 +08:00
failed_when : false
changed_when : false
check_mode : false
2021-01-05 01:07:56 +08:00
register : calico
2024-08-28 13:30:56 +08:00
run_once : true
2021-03-24 08:26:05 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2021-01-05 01:07:56 +08:00
- name : "Set calico_pool_conf"
set_fact :
calico_pool_conf : '{{ calico.stdout | from_json }}'
when : calico.rc == 0 and calico.stdout
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2021-01-05 01:07:56 +08:00
- name : "Check if inventory match current cluster configuration"
assert :
that :
2023-12-12 21:38:36 +08:00
- calico_pool_conf.spec.blockSize | int == calico_pool_blocksize | int
2021-01-05 01:07:56 +08:00
- calico_pool_conf.spec.cidr == (calico_pool_cidr | default(kube_pods_subnet))
2021-01-22 12:39:26 +08:00
- not calico_pool_conf.spec.ipipMode is defined or calico_pool_conf.spec.ipipMode == calico_ipip_mode
- not calico_pool_conf.spec.vxlanMode is defined or calico_pool_conf.spec.vxlanMode == calico_vxlan_mode
2021-01-05 01:07:56 +08:00
msg : "Your inventory doesn't match the current cluster configuration"
when :
- calico_pool_conf is defined
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2022-04-08 15:02:42 +08:00
- name : "Check kdd calico_datastore if calico_apiserver_enabled"
assert :
that : calico_datastore == "kdd"
2022-04-14 16:08:46 +08:00
msg : "When using calico apiserver you need to use the kubernetes datastore"
2022-04-08 15:02:42 +08:00
when :
- calico_apiserver_enabled
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2022-04-08 15:02:42 +08:00
- name : "Check kdd calico_datastore if typha_enabled"
assert :
that : calico_datastore == "kdd"
2022-04-14 16:08:46 +08:00
msg : "When using typha you need to use the kubernetes datastore"
2022-04-08 15:02:42 +08:00
when :
- typha_enabled
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-14 16:08:46 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"
2022-04-29 15:35:13 +08:00
2022-06-14 05:10:12 +08:00
- name : "Check ipip mode is Never for calico ipv6"
2022-04-29 15:35:13 +08:00
assert :
that :
- "calico_ipip_mode_ipv6 in ['Never']"
msg : "Calico doesn't support ipip tunneling for the IPv6"
when :
- enable_dual_stack_networks
2024-08-28 13:30:56 +08:00
run_once : true
2022-04-29 15:35:13 +08:00
delegate_to : "{{ groups['kube_control_plane'][0] }}"