From 356081816753cc1d6b1e5d6bb899e77d7ccb5c98 Mon Sep 17 00:00:00 2001 From: Felix Matouschek Date: Wed, 3 Apr 2024 17:26:49 +0200 Subject: [PATCH] fix: Return early to avoid adding empty groups. If no VMIs were found in a namespace then return early to avoid adding empty groups. Signed-off-by: Felix Matouschek --- plugins/inventory/kubevirt.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/inventory/kubevirt.py b/plugins/inventory/kubevirt.py index 587d7a1..04697b8 100644 --- a/plugins/inventory/kubevirt.py +++ b/plugins/inventory/kubevirt.py @@ -448,6 +448,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): f"Error fetching VirtualMachineInstance list: {self.format_dynamic_api_exc(exc)}" ) from exc + if not vmi_list.items: + # Return early if no VMIs were found to avoid adding empty groups. + return + services = self.get_ssh_services_for_namespace(client, namespace) name = self._sanitize_group_name(name)