kubekey/pipeline/roles/precheck/tasks/main.yaml
joyceliu 2a676185e2 feat: kubekey gitops
Signed-off-by: joyceliu <joyceliu@yunify.com>
2024-01-05 15:14:36 +08:00

115 lines
4.3 KiB
YAML

---
- name: Stop if either kube_control_plane or kube_node group is empty
assert:
that: "'{{ item }}' in groups"
loop:
- kube_control_plane
- kube_node
run_once: true
- name: Stop if etcd group is empty in external etcd mode
assert:
that: "'etcd' in groups"
fail_msg: "Group 'etcd' cannot be empty in external etcd mode"
run_once: true
when:
- etcd_deployment_type != "kubeadm"
- name: Stop if the os does not support
assert:
that: (allow_unsupported_distribution_setup | default:false) or os.release.ID in supported_os_distributions
fail_msg: "{{ os.release.ID }} is not a known OS"
- name: Stop if unknown network plugin
vars:
require_network_plugin: ['calico', 'flannel', 'weave', 'cloud', 'cilium', 'cni', 'kube-ovn', 'kube-router', 'macvlan', 'custom_cni']
assert:
that: kube_network_plugin in require_network_plugin
fail_msg: "{{ kube_network_plugin }} is not supported"
when:
- kube_network_plugin | defined
- name: Stop if unsupported version of Kubernetes
assert:
that: kube_version | version:'>=,{{kube_version_min_required}}'
fail_msg: "The current release of Kubespray only support newer version of Kubernetes than {{ kube_version_min_required }} - You are trying to apply {{ kube_version }}"
- name: Stop if even number of etcd hosts
assert:
that: not groups.etcd | length | divisibleby:2
when:
- inventory_hostname in groups['etcd']
- name: Stop if memory is too small for masters
assert:
that: process.memInfo.MemTotal | cut:' kB' >= minimal_master_memory_mb
when:
- inventory_hostname in groups['kube_control_plane']
- name: Stop if memory is too small for nodes
assert:
that: process.memInfo.MemTotal | cut:' kB' >= minimal_node_memory_mb
when:
- inventory_hostname in groups['kube_node']
# This assertion will fail on the safe side: One can indeed schedule more pods
# on a node than the CIDR-range has space for when additional pods use the host
# network namespace. It is impossible to ascertain the number of such pods at
# provisioning time, so to establish a guarantee, we factor these out.
# NOTICE: the check blatantly ignores the inet6-case
- name: Guarantee that enough network address space is available for all pods
assert:
that: "(kubelet_max_pods | default_if_none:110 | integer) <= (2 | pow: {{ 32 - kube_network_node_prefix | integer }} - 2)"
fail_msg: "Do not schedule more pods on a node than inet addresses are available."
when:
- inventory_hostname in groups['k8s_cluster']
- kube_network_node_prefix | defined
- kube_network_plugin != 'calico'
- name: Stop if access_ip is not pingable
command: ping -c1 {{ access_ip }}
when:
- access_ip | defined
- ping_access_ip
changed_when: false
- name: Stop if kernel version is too low
assert:
that: os.kernelVersion | split:'-' | first | version:'>=,4.9.17'
when:
- kube_network_plugin == 'cilium' or (cilium_deploy_additionally | default:false)
- name: Stop if bad hostname
vars:
regex: '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$'
assert:
that: inventory_hostname | match:regex
fail_msg: "Hostname must consist of lower case alphanumeric characters, '.' or '-', and must start and end with an alphanumeric character"
- name: Stop if etcd deployment type is not host, docker or kubeadm
vars:
require_etcd_deployment_type: ['kubekey', 'external', 'kubeadm']
assert:
that: etcd_deployment_type in require_etcd_deployment_type
fail_msg: "The etcd deployment type, 'etcd_deployment_type', must be host, docker or kubeadm"
when:
- inventory_hostname in groups['etcd']
- name: Stop if container manager is not docker, crio or containerd
vars:
require_container_manager: ['docker', 'crio', 'containerd']
assert:
that: container_manager in require_container_manager
fail_msg: "The container manager, 'container_manager', must be docker, crio or containerd"
run_once: true
- name: Ensure minimum containerd version
require_containerd_version: ['latest', 'edge', 'stable']
assert:
that: containerd_version | version:'>=,{{containerd_min_version_required}}'
fail_msg: "containerd_version is too low. Minimum version {{ containerd_min_version_required }}"
run_once: yes
when:
- not containerd_version in require_containerd_version
- container_manager == 'containerd'