From e6fb686156c839445247df28299e854ca30e7433 Mon Sep 17 00:00:00 2001
From: Scott Charron <sc@canroot.com>
Date: Tue, 11 Jun 2019 03:20:21 -0400
Subject: [PATCH] added the ability to define and deploy multiple address pools
 to metallb (#4757)

---
 contrib/metallb/README.md                              |  2 ++
 contrib/metallb/roles/provision/defaults/main.yml      |  6 ++++++
 .../roles/provision/templates/metallb-config.yml.j2    | 10 +++++++++-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/contrib/metallb/README.md b/contrib/metallb/README.md
index 412863340..e3b19ac82 100644
--- a/contrib/metallb/README.md
+++ b/contrib/metallb/README.md
@@ -6,5 +6,7 @@ This playbook aims to automate [this](https://metallb.universe.tf/tutorial/layer
 
 ## Install
 ```
+Defaults can be found in contrib/metallb/roles/provision/defaults/main.yml. You can override the defaults by copying the contents of this file to somewhere in inventory/mycluster/group_vars such as inventory/mycluster/groups_vars/k8s-cluster/addons.yml and making any adjustments as required.
+
 ansible-playbook --ask-become -i inventory/sample/hosts.ini contrib/metallb/metallb.yml
 ```
diff --git a/contrib/metallb/roles/provision/defaults/main.yml b/contrib/metallb/roles/provision/defaults/main.yml
index a45858d19..4a7c7c471 100644
--- a/contrib/metallb/roles/provision/defaults/main.yml
+++ b/contrib/metallb/roles/provision/defaults/main.yml
@@ -1,6 +1,12 @@
 ---
 metallb:
   ip_range: "10.5.0.50-10.5.0.99"
+  protocol: "layer2"
+  # additional_address_pools:
+  #   kube_service_pool:
+  #     ip_range: "10.5.1.50-10.5.1.99"
+  #     protocol: "layer2"
+  #     auto_assign: false
   limits:
     cpu: "100m"
     memory: "100Mi"
diff --git a/contrib/metallb/roles/provision/templates/metallb-config.yml.j2 b/contrib/metallb/roles/provision/templates/metallb-config.yml.j2
index 2e58f2d5f..6f2f87339 100644
--- a/contrib/metallb/roles/provision/templates/metallb-config.yml.j2
+++ b/contrib/metallb/roles/provision/templates/metallb-config.yml.j2
@@ -8,6 +8,14 @@ data:
   config: |
     address-pools:
     - name: loadbalanced
-      protocol: layer2
+      protocol: {{ metallb.protocol }}
       addresses:
       - {{ metallb.ip_range }}
+{% if metallb.additional_address_pools is defined %}{% for pool in metallb.additional_address_pools %}
+    - name: {{ pool }}
+      protocol: {{ metallb.additional_address_pools[pool].protocol }}
+      addresses:
+      - {{ metallb.additional_address_pools[pool].ip_range }}
+      auto-assign: {{ metallb.additional_address_pools[pool].auto_assign }}
+{% endfor %}
+{% endif %}
-- 
GitLab