From efef80f67b3b95bcc8af295f720f1a7d5db18d24 Mon Sep 17 00:00:00 2001
From: Steven Reitsma <steven@properchaos.nl>
Date: Tue, 3 Mar 2020 15:33:38 +0100
Subject: [PATCH] Add support for HA deployment of OpenStack Cinder CSI plugin
 (#5691)

---
 .../cinder-csi-controllerplugin.yml.j2         | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/roles/kubernetes-apps/csi_driver/cinder/templates/cinder-csi-controllerplugin.yml.j2 b/roles/kubernetes-apps/csi_driver/cinder/templates/cinder-csi-controllerplugin.yml.j2
index e360a448f..afc066edd 100644
--- a/roles/kubernetes-apps/csi_driver/cinder/templates/cinder-csi-controllerplugin.yml.j2
+++ b/roles/kubernetes-apps/csi_driver/cinder/templates/cinder-csi-controllerplugin.yml.j2
@@ -24,6 +24,11 @@ spec:
           args:
             - "--v=5"
             - "--csi-address=$(ADDRESS)"
+{% if cinder_csi_controller_replicas is defined and cinder_csi_controller_replicas > 1 %}
+            - --leader-election
+            - --leader-election-type=leases
+            - --leader-election-namespace=kube-system
+{% endif %}
           env:
             - name: ADDRESS
               value: /var/lib/csi/sockets/pluginproxy/csi.sock
@@ -37,6 +42,11 @@ spec:
             - "--csi-address=$(ADDRESS)"
 {% if cinder_topology is defined and cinder_topology %}
             - --feature-gates=Topology=true
+{% endif %}
+{% if cinder_csi_controller_replicas is defined and cinder_csi_controller_replicas > 1 %}
+            - --enable-leader-election
+            - --leader-election-type=leases
+            - --leader-election-namespace=kube-system
 {% endif %}
           env:
             - name: ADDRESS
@@ -49,6 +59,10 @@ spec:
           image: {{ cinder_csi_snapshotter_image_repo }}:{{ cinder_csi_snapshotter_image_tag }}
           args:
             - "--csi-address=$(ADDRESS)"
+{% if cinder_csi_controller_replicas is defined and cinder_csi_controller_replicas > 1 %}
+            - --leader-election
+            - --leader-election-namespace=kube-system
+{% endif %}
           env:
             - name: ADDRESS
               value: /var/lib/csi/sockets/pluginproxy/csi.sock
@@ -60,6 +74,10 @@ spec:
           image: {{ cinder_csi_resizer_image_repo }}:{{ cinder_csi_resizer_image_tag }}
           args:
             - "--csi-address=$(ADDRESS)"
+{% if cinder_csi_controller_replicas is defined and cinder_csi_controller_replicas > 1 %}
+            - --leader-election
+            - --leader-election-namespace=kube-system
+{% endif %}
           env:
             - name: ADDRESS
               value: /var/lib/csi/sockets/pluginproxy/csi.sock
-- 
GitLab