From db85fa960c78d69d50d2eb8e903defb1ca7bc7de Mon Sep 17 00:00:00 2001 From: Techno Tim Date: Sun, 2 Aug 2026 23:52:27 -0500 Subject: [PATCH] fix(metallb): guard cilium_bgp when undefined; clarify apiserver_endpoint docs (#683) * fix(metallb): guard cilium_bgp variable before evaluating - The 'Deploy metallb manifest' and 'Deploy metallb pool' conditionals evaluate 'not cilium_bgp' directly, which raises an undefined-variable error when the k3s_server role runs without cilium_bgp in scope and no Cilium variables are set - Guard with 'cilium_bgp is not defined' so the condition resolves cleanly when Cilium BGP is not configured - Fixes #644 * docs(apiserver): clarify apiserver_endpoint must be a free routable IP - Note that apiserver_endpoint must be an unassigned, routable IP on the network and that it is exposed by kube-vip / MetalLB - Fixes #678 * fix(molecule): wait for MetalLB resources before asserting images - The MetalLB image-tag assertion crashed with 'list object has no element 0' when the controller Deployment was not yet observable at verify time - Retry the MetalLB controller/speaker lookup until the resources appear - Fail with a clear message if MetalLB is genuinely absent --- inventory/sample/group_vars/all.yml | 4 +++- .../tasks/test/verify-components.yml | 14 ++++++++++++++ roles/k3s_server/tasks/main.yml | 2 +- roles/k3s_server_post/tasks/main.yml | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/inventory/sample/group_vars/all.yml b/inventory/sample/group_vars/all.yml index ac0cb71b..f1559257 100644 --- a/inventory/sample/group_vars/all.yml +++ b/inventory/sample/group_vars/all.yml @@ -47,7 +47,9 @@ kube_vip_bgp_as: "64513" # Defines the AS for the BGP server kube_vip_bgp_peeraddress: "192.168.30.1" # Defines the address for the BGP peer kube_vip_bgp_peeras: "64512" # Defines the AS for the BGP peer -# apiserver_endpoint is virtual ip-address which will be configured on each master +# apiserver_endpoint is virtual ip-address which will be configured on each master. +# This must be a free, routable IP on your network (not already assigned to a host +# or service), and is used by kube-vip / MetalLB to expose the Kubernetes API. apiserver_endpoint: 192.168.30.222 # k3s_token is required masters can talk together securely diff --git a/molecule/resources/verify_from_outside/tasks/test/verify-components.yml b/molecule/resources/verify_from_outside/tasks/test/verify-components.yml index debc2989..a72285fa 100644 --- a/molecule/resources/verify_from_outside/tasks/test/verify-components.yml +++ b/molecule/resources/verify_from_outside/tasks/test/verify-components.yml @@ -219,12 +219,26 @@ namespace: metallb-system kubeconfig: "{{ kubecfg_path }}" register: metallb_info + until: metallb_info.resources | length > 0 + retries: 15 + delay: 10 loop: - { kind: Deployment, name: controller } - { kind: DaemonSet, name: speaker } loop_control: label: "{{ item.kind }}/{{ item.name }}" + - name: Fail with a clear message if MetalLB resources are missing + ansible.builtin.fail: + msg: >- + Did not find {{ item.kind | lower }} {{ item.name }} in + metallb-system. Expected MetalLB to be deployed in this + scenario (verify_lb: {{ verify_lb }}). + when: item.resources | length == 0 + loop: "{{ metallb_info.results }}" + loop_control: + label: "{{ item.item.kind }}/{{ item.item.name }}" + - name: Assert MetalLB controller and speaker use the expected image tags ansible.builtin.assert: that: diff --git a/roles/k3s_server/tasks/main.yml b/roles/k3s_server/tasks/main.yml index d0306c92..ae406e0d 100644 --- a/roles/k3s_server/tasks/main.yml +++ b/roles/k3s_server/tasks/main.yml @@ -27,7 +27,7 @@ - name: Deploy metallb manifest ansible.builtin.include_tasks: metallb.yml tags: metallb - when: kube_vip_lb_ip_range is not defined and (not cilium_bgp or cilium_iface is not defined) + when: kube_vip_lb_ip_range is not defined and (cilium_bgp is not defined or cilium_iface is not defined) - name: Deploy kube-vip manifest ansible.builtin.include_tasks: kube-vip.yml diff --git a/roles/k3s_server_post/tasks/main.yml b/roles/k3s_server_post/tasks/main.yml index 1a02d8de..dbb38dca 100644 --- a/roles/k3s_server_post/tasks/main.yml +++ b/roles/k3s_server_post/tasks/main.yml @@ -12,7 +12,7 @@ - name: Deploy metallb pool ansible.builtin.include_tasks: metallb.yml tags: metallb - when: kube_vip_lb_ip_range is not defined and (not cilium_bgp or cilium_iface is not defined) + when: kube_vip_lb_ip_range is not defined and (cilium_bgp is not defined or cilium_iface is not defined) - name: Remove tmp directory used for manifests ansible.builtin.file: