---
- name: Stop if unknown network plugin
  assert:
    that: .cluster_require.require_network_plugin | has .kubernetes.kube_network_plugin
    fail_msg: |
      kube_network_plugin:"{{ .kubernetes.kube_network_plugin }}" is not supported
  when: and .kubernetes.kube_network_plugin (ne .kubernetes.kube_network_plugin "")

# 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: le .kubernetes.kubelet.max_pods  (sub (pow 2 (sub 32 .kubernetes.controller_manager.kube_network_node_prefix))  2)
    fail_msg: do not schedule more pods on a node than inet addresses are available.
  when:
    - .groups.k8s_cluster | default list | has .inventory_name
    - .kubernetes.controller_manager.kube_network_node_prefix
    - .kubernetes.kube_network_plugin | ne "calico"

