Browse Source

[multus] added support for mixed type of container engine (#9224)

* [multus] added support for mixed type of container engine

* [multus] fixed for using with cluster/upgrade-cluster/scale playbooks
pull/9674/head
Vitaly Yakovenko 1 year ago
committed by GitHub
parent
commit
d919c58e21
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 5 deletions
  1. 10
      roles/kubernetes-apps/network_plugin/multus/tasks/main.yml
  2. 20
      roles/network_plugin/multus/tasks/main.yml
  3. 8
      roles/network_plugin/multus/templates/multus-daemonset.yml.j2

10
roles/kubernetes-apps/network_plugin/multus/tasks/main.yml

@ -7,5 +7,11 @@
resource: "{{ item.item.type }}"
filename: "{{ kube_config_dir }}/{{ item.item.file }}"
state: "latest"
with_items: "{{ multus_manifest_1.results }} + {{ multus_manifest_2.results }}"
when: inventory_hostname == groups['kube_control_plane'][0] and not item is skipped
delegate_to: "{{ groups['kube_control_plane'][0] }}"
run_once: true
with_items: "{{ multus_manifest_1.results }} + {{ multus_nodes_list|map('extract', hostvars, 'multus_manifest_2')|list|json_query('[].results') }}"
loop_control:
label: "{{ item.item.name }}"
vars:
multus_nodes_list: "{{ groups['k8s_cluster'] if ansible_play_batch|length == ansible_play_hosts_all|length else ansible_play_batch }}"
when: not item is skipped

20
roles/network_plugin/multus/tasks/main.yml

@ -10,12 +10,26 @@
- {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 }}"
- 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

8
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 }}

Loading…
Cancel
Save