From 52904ee6adfe06c099c7decefa461a153c318f08 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Unai=20Arr=C3=ADen?= <unaittxu@gmail.com>
Date: Fri, 14 Oct 2022 01:50:47 +0200
Subject: [PATCH] Avoid MetalLB speaker image download when MetalLB speaker is
 disabled (#9248)

* Avoid MetalLB speaker image download when metallb_speaker_enabled is set to

* Move metallb_speaker_enabled var to allow outside metalLB role references

* Move metallb_speaker_enabled var to allow outside metalLB role references

* Improve metallb_speaker_enabled default values
---
 inventory/sample/group_vars/k8s_cluster/addons.yml | 2 +-
 roles/download/defaults/main.yml                   | 2 +-
 roles/kubernetes-apps/metallb/defaults/main.yml    | 2 +-
 roles/kubespray-defaults/defaults/main.yaml        | 1 +
 4 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/inventory/sample/group_vars/k8s_cluster/addons.yml b/inventory/sample/group_vars/k8s_cluster/addons.yml
index 70311748e..a5cdd9269 100644
--- a/inventory/sample/group_vars/k8s_cluster/addons.yml
+++ b/inventory/sample/group_vars/k8s_cluster/addons.yml
@@ -161,7 +161,7 @@ cert_manager_enabled: false
 
 # MetalLB deployment
 metallb_enabled: false
-metallb_speaker_enabled: true
+metallb_speaker_enabled: "{{ metallb_enabled }}"
 # metallb_ip_range:
 #   - "10.5.0.50-10.5.0.99"
 # metallb_pool_name: "loadbalanced"
diff --git a/roles/download/defaults/main.yml b/roles/download/defaults/main.yml
index 808781e1d..088f58a53 100644
--- a/roles/download/defaults/main.yml
+++ b/roles/download/defaults/main.yml
@@ -1695,7 +1695,7 @@ downloads:
     - kube_control_plane
 
   metallb_speaker:
-    enabled: "{{ metallb_enabled }}"
+    enabled: "{{ metallb_speaker_enabled }}"
     container: true
     repo: "{{ metallb_speaker_image_repo }}"
     tag: "{{ metallb_version }}"
diff --git a/roles/kubernetes-apps/metallb/defaults/main.yml b/roles/kubernetes-apps/metallb/defaults/main.yml
index 3679aebe8..dc96fdc7d 100644
--- a/roles/kubernetes-apps/metallb/defaults/main.yml
+++ b/roles/kubernetes-apps/metallb/defaults/main.yml
@@ -5,7 +5,7 @@ metallb_protocol: "layer2"
 metallb_port: "7472"
 metallb_memberlist_port: "7946"
 metallb_peers: []
-metallb_speaker_enabled: true
+metallb_speaker_enabled: "{{ metallb_enabled }}"
 metallb_speaker_nodeselector:
   kubernetes.io/os: "linux"
 metallb_controller_nodeselector:
diff --git a/roles/kubespray-defaults/defaults/main.yaml b/roles/kubespray-defaults/defaults/main.yaml
index a34eae913..6fb515986 100644
--- a/roles/kubespray-defaults/defaults/main.yaml
+++ b/roles/kubespray-defaults/defaults/main.yaml
@@ -409,6 +409,7 @@ ingress_alb_enabled: false
 cert_manager_enabled: false
 expand_persistent_volumes: false
 metallb_enabled: false
+metallb_speaker_enabled: "{{ metallb_enabled }}"
 argocd_enabled: false
 
 ## When OpenStack is used, Cinder version can be explicitly specified if autodetection fails (Fixed in 1.9: https://github.com/kubernetes/kubernetes/issues/50461)
-- 
GitLab