[multus] added support for mixed type of container engine

This commit is contained in:
Vitaly Yakovenko 2022-08-26 13:45:45 +02:00
parent e6976a54e1
commit 58f62d8f47
3 changed files with 28 additions and 4 deletions

View file

@ -7,5 +7,5 @@
resource: "{{ item.item.type }}" resource: "{{ item.item.type }}"
filename: "{{ kube_config_dir }}/{{ item.item.file }}" filename: "{{ kube_config_dir }}/{{ item.item.file }}"
state: "latest" state: "latest"
with_items: "{{ multus_manifest_1.results }} + {{ multus_manifest_2.results }}" with_items: "{{ multus_manifest_1.results }} + {{ groups['k8s_cluster']|map('extract', hostvars, 'multus_manifest_2')|list|json_query('[].results') }}"
when: inventory_hostname == groups['kube_control_plane'][0] and not item is skipped when: inventory_hostname == groups['kube_control_plane'][0] and not item is skipped

View file

@ -10,12 +10,28 @@
- {name: multus-clusterrole, file: multus-clusterrole.yml, type: clusterrole} - {name: multus-clusterrole, file: multus-clusterrole.yml, type: clusterrole}
- {name: multus-clusterrolebinding, file: multus-clusterrolebinding.yml, type: clusterrolebinding} - {name: multus-clusterrolebinding, file: multus-clusterrolebinding.yml, type: clusterrolebinding}
register: multus_manifest_1 register: multus_manifest_1
when: inventory_hostname == groups['kube_control_plane'][0]
- name: Multus | Check container engine type
set_fact:
container_manager_types: "{{ ansible_play_hosts_all|map('extract', hostvars, ['container_manager'])|list|unique }}"
run_once: true
when: inventory_hostname == groups['kube_control_plane'][0]
- name: Multus | Copy manifest templates - name: Multus | Copy manifest templates
template: template:
src: "{{ item.file }}.j2" src: multus-daemonset.yml.j2
dest: "{{ kube_config_dir }}/{{ item.file }}" dest: "{{ kube_config_dir }}/{{ item.file }}"
mode: 0644
with_items: with_items:
- {name: multus-daemonset, file: multus-daemonset.yml, type: daemonset} - {name: multus-daemonset-containerd, file: multus-daemonset-containerd.yml, type: daemonset, engine: containerd }
- {name: multus-daemonset-docker, file: multus-daemonset-docker.yml, type: daemonset, engine: docker }
- {name: multus-daemonset-crio, file: multus-daemonset-crio.yml, type: daemonset, engine: crio }
register: multus_manifest_2 register: multus_manifest_2
vars:
query: "*|[?container_manager=='{{ container_manager }}']|[0].inventory_hostname"
vars_from_node: "{{ hostvars|json_query(query) }}"
delegate_to: "{{ groups['kube_control_plane'][0] }}"
when:
- item.engine in container_manager_types
- hostvars[inventory_hostname].container_manager == item.engine
- inventory_hostname == vars_from_node

View file

@ -2,7 +2,11 @@
kind: DaemonSet kind: DaemonSet
apiVersion: apps/v1 apiVersion: apps/v1
metadata: metadata:
{% if container_manager_types|length >= 2 %}
name: kube-multus-{{ container_manager }}-{{ image_arch }}
{% else %}
name: kube-multus-ds-{{ image_arch }} name: kube-multus-ds-{{ image_arch }}
{% endif %}
namespace: kube-system namespace: kube-system
labels: labels:
tier: node tier: node
@ -22,6 +26,9 @@ spec:
dnsPolicy: ClusterFirstWithHostNet dnsPolicy: ClusterFirstWithHostNet
nodeSelector: nodeSelector:
kubernetes.io/arch: {{ image_arch }} kubernetes.io/arch: {{ image_arch }}
{% if container_manager_types|length >= 2 %}
kubespray.io/container_manager: {{ container_manager }}
{% endif %}
tolerations: tolerations:
- operator: Exists - operator: Exists
serviceAccountName: multus serviceAccountName: multus
@ -52,6 +59,7 @@ spec:
{% if container_manager == 'crio' %} {% if container_manager == 'crio' %}
- name: run - name: run
mountPath: {{ multus_cni_run_dir }} mountPath: {{ multus_cni_run_dir }}
mountPropagation: HostToContainer
{% endif %} {% endif %}
- name: cni - name: cni
mountPath: {{ multus_cni_conf_dir }} mountPath: {{ multus_cni_conf_dir }}