diff --git a/roles/kubernetes-apps/network_plugin/multus/tasks/main.yml b/roles/kubernetes-apps/network_plugin/multus/tasks/main.yml index 232d3e403..3cf9f7ae5 100644 --- a/roles/kubernetes-apps/network_plugin/multus/tasks/main.yml +++ b/roles/kubernetes-apps/network_plugin/multus/tasks/main.yml @@ -7,5 +7,5 @@ resource: "{{ item.item.type }}" filename: "{{ kube_config_dir }}/{{ item.item.file }}" 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 diff --git a/roles/network_plugin/multus/tasks/main.yml b/roles/network_plugin/multus/tasks/main.yml index 3552b05ba..4dcd4fb22 100644 --- a/roles/network_plugin/multus/tasks/main.yml +++ b/roles/network_plugin/multus/tasks/main.yml @@ -10,12 +10,28 @@ - {name: multus-clusterrole, file: multus-clusterrole.yml, type: clusterrole} - {name: multus-clusterrolebinding, file: multus-clusterrolebinding.yml, type: clusterrolebinding} 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 template: - src: "{{ item.file }}.j2" + src: multus-daemonset.yml.j2 dest: "{{ kube_config_dir }}/{{ item.file }}" - mode: 0644 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 + 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 diff --git a/roles/network_plugin/multus/templates/multus-daemonset.yml.j2 b/roles/network_plugin/multus/templates/multus-daemonset.yml.j2 index 494dee295..19f91bae8 100644 --- a/roles/network_plugin/multus/templates/multus-daemonset.yml.j2 +++ b/roles/network_plugin/multus/templates/multus-daemonset.yml.j2 @@ -2,7 +2,11 @@ kind: DaemonSet apiVersion: apps/v1 metadata: +{% if container_manager_types|length >= 2 %} + name: kube-multus-{{ container_manager }}-{{ image_arch }} +{% else %} name: kube-multus-ds-{{ image_arch }} +{% endif %} namespace: kube-system labels: tier: node @@ -22,6 +26,9 @@ spec: dnsPolicy: ClusterFirstWithHostNet nodeSelector: kubernetes.io/arch: {{ image_arch }} +{% if container_manager_types|length >= 2 %} + kubespray.io/container_manager: {{ container_manager }} +{% endif %} tolerations: - operator: Exists serviceAccountName: multus @@ -52,6 +59,7 @@ spec: {% if container_manager == 'crio' %} - name: run mountPath: {{ multus_cni_run_dir }} + mountPropagation: HostToContainer {% endif %} - name: cni mountPath: {{ multus_cni_conf_dir }}