From 974902af31e6ff53eb54d39d9f4e9e9fc245e961 Mon Sep 17 00:00:00 2001
From: bozzo <bozzo@users.noreply.github.com>
Date: Tue, 17 Mar 2020 10:40:21 +0100
Subject: [PATCH] Update Kube-router version to v0.4.0 (#5756)

---
 README.md                                     |  2 +-
 roles/download/defaults/main.yml              |  2 +-
 .../network_plugin/kube-router/tasks/main.yml | 28 ++++++++-----------
 .../kube-router/templates/cni-conf.json.j2    | 26 +++++++++++------
 .../kube-router/templates/kube-router.yml.j2  |  2 ++
 5 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/README.md b/README.md
index 972c054ca..dfc740540 100644
--- a/README.md
+++ b/README.md
@@ -125,7 +125,7 @@ Note: Upstart/SysV init based OS types are not supported.
   - [cilium](https://github.com/cilium/cilium) v1.5.5
   - [contiv](https://github.com/contiv/install) v1.2.1
   - [flanneld](https://github.com/coreos/flannel) v0.11.0
-  - [kube-router](https://github.com/cloudnativelabs/kube-router) v0.2.5
+  - [kube-router](https://github.com/cloudnativelabs/kube-router) v0.4.0
   - [multus](https://github.com/intel/multus-cni) v3.4
   - [weave](https://github.com/weaveworks/weave) v2.5.2
 - Application
diff --git a/roles/download/defaults/main.yml b/roles/download/defaults/main.yml
index 83a2c1e2e..0188ff8df 100644
--- a/roles/download/defaults/main.yml
+++ b/roles/download/defaults/main.yml
@@ -82,7 +82,7 @@ pod_infra_version: 3.1
 contiv_version: 1.2.1
 cilium_version: "v1.7.1"
 kube_ovn_version: "v0.6.0"
-kube_router_version: "v0.2.5"
+kube_router_version: "v0.4.0"
 multus_version: "v3.4"
 
 # Get kubernetes major version (i.e. 1.15.4 => 1.15)
diff --git a/roles/network_plugin/kube-router/tasks/main.yml b/roles/network_plugin/kube-router/tasks/main.yml
index 83c81f28f..6c4a10508 100644
--- a/roles/network_plugin/kube-router/tasks/main.yml
+++ b/roles/network_plugin/kube-router/tasks/main.yml
@@ -37,7 +37,7 @@
 
 - name: kube-router | Slurp cni config
   slurp:
-    src: /etc/cni/net.d/10-kuberouter.conf
+    src: /etc/cni/net.d/10-kuberouter.conflist
   register: cni_config_slurp
   ignore_errors: true
 
@@ -49,30 +49,24 @@
 
 - name: kube-router | Set host_subnet variable
   set_fact:
-    host_subnet: "{{ cni_config.ipam.subnet }}"
+    host_subnet: "{{ cni_config | json_query('plugins[?bridge==`kube-bridge`].ipam.subnet') | first }}"
   when:
     - cni_config is defined
-    - cni_config.ipam is defined
-    - cni_config.ipam.subnet is defined
-
-- name: kube-router | Set wanted cni config variable
-  set_fact:
-    wanted_cni_config: "{{ lookup('template', 'cni-conf.json.j2') }}"
-
-- name: kube-router | Set wanted_cni_config variable
-  set_fact:
-    wanted_cni_config: "{{ wanted_cni_config | combine({ 'ipam': { 'subnet': host_subnet }}, recursive=True) }}"
-  when: host_subnet is defined
+    - cni_config | json_query('plugins[?bridge==`kube-bridge`].ipam.subnet') | length > 0
 
 - name: kube-router | Create cni config
-  copy:
-    content: "{{ wanted_cni_config | to_nice_json }}"
-    dest: /etc/cni/net.d/10-kuberouter.conf
+  template:
+    src: cni-conf.json.j2
+    dest: /etc/cni/net.d/10-kuberouter.conflist
     owner: kube
-  changed_when: wanted_cni_config != cni_config
   notify:
     - reset_kube_router
 
+- name: kube-router | Delete old configuration
+  file:
+    path: /etc/cni/net.d/10-kuberouter.conf
+    state: absent
+
 - name: kube-router | Create manifest
   template:
     src: kube-router.yml.j2
diff --git a/roles/network_plugin/kube-router/templates/cni-conf.json.j2 b/roles/network_plugin/kube-router/templates/cni-conf.json.j2
index 7b1048122..c5327c1d0 100644
--- a/roles/network_plugin/kube-router/templates/cni-conf.json.j2
+++ b/roles/network_plugin/kube-router/templates/cni-conf.json.j2
@@ -1,13 +1,21 @@
 {
-  "name":"kubernetes",
-  "cniVersion": "0.2.0",
-  "type":"bridge",
-  "bridge":"kube-bridge",
-  "isDefaultGateway":true,
+   "cniVersion":"0.3.0",
+   "name":"kubernetes",
+   "plugins":[
+      {
+         "name":"kubernetes",
+         "type":"bridge",
+         "bridge":"kube-bridge",
+         "isDefaultGateway":true,
 {% if kube_router_support_hairpin_mode %}
-  "hairpinMode":true,
+          "hairpinMode":true,
 {% endif %}
-  "ipam": {
-    "type":"host-local"
-  }
+         "ipam":{
+{% if host_subnet is defined %}
+            "subnet": "{{ host_subnet }}",
+{% endif %}
+            "type":"host-local"
+         }
+      }
+   ]
 }
diff --git a/roles/network_plugin/kube-router/templates/kube-router.yml.j2 b/roles/network_plugin/kube-router/templates/kube-router.yml.j2
index b791a3e8f..127be8a8c 100644
--- a/roles/network_plugin/kube-router/templates/kube-router.yml.j2
+++ b/roles/network_plugin/kube-router/templates/kube-router.yml.j2
@@ -69,6 +69,8 @@ spec:
           valueFrom:
             fieldRef:
               fieldPath: spec.nodeName
+        - name: KUBE_ROUTER_CNI_CONF_FILE
+          value: /etc/cni/net.d/10-kuberouter.conflist
         livenessProbe:
           httpGet:
             path: /healthz
-- 
GitLab