From 9e8a747b0b46825553c6682e5ca6fea98fb40b3b Mon Sep 17 00:00:00 2001 From: Timofei Larkin Date: Fri, 2 Oct 2026 10:30:52 +0300 Subject: [PATCH] fix(platform): gate the MetalLB driver on its deps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cozystack.metallb-iad hard-depends on cozystack.metallb and on cozystack.address-controller, and a driver Package rendered without both beside it never leaves DependenciesNotReady — the wedge the velero and bucket-application comments in system.yaml already record for default packages, reachable here through an opt-in one. MetalLB is absent in three ways: on isp-hosted, which never calls the common-packages helper; on a slim variant that did not opt into it; and wherever disabledPackages names it. The core is absent unless enabled. Rather than restate those rules for the driver, the driver is gated on each dependency's own include having rendered a Package, so they cannot drift when either's rules change. The class-agnostic core stays in the variant-agnostic body: it carries no MetalLB dependency and is usable with another driver. Assisted-by: LLM Signed-off-by: Timofei Larkin --- packages/core/platform/templates/_helpers.tpl | 10 +- .../platform/templates/bundles/system.yaml | 7 +- .../bundles_metallb_iad_variant_test.yaml | 142 ++++++++++++++++++ 3 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 packages/core/platform/tests/bundles_metallb_iad_variant_test.yaml diff --git a/packages/core/platform/templates/_helpers.tpl b/packages/core/platform/templates/_helpers.tpl index 8c3443a8b..f9f37c3a3 100644 --- a/packages/core/platform/templates/_helpers.tpl +++ b/packages/core/platform/templates/_helpers.tpl @@ -224,7 +224,15 @@ cozystack-scheduler (emitted with its own variant in both branches) {{include "cozystack.platform.package.default" (list "cozystack.kubeovn-plunger" $root) }} {{- end }} {{include "cozystack.platform.package.full.default" (list "cozystack.cozy-proxy" $root) }} -{{include "cozystack.platform.package.full.default" (list "cozystack.metallb" $root) }} +{{- $metallb := include "cozystack.platform.package.full.default" (list "cozystack.metallb" $root) }} +{{ $metallb }} +{{- /* Gated on its dependencies' own includes rendering a Package, so it + follows their emission rules rather than restating them. The core is + rendered here only for that test; bundles/system.yaml emits it. */ -}} +{{- $addressController := include "cozystack.platform.package.optional.default" (list "cozystack.address-controller" $root) }} +{{- if and (trim $metallb) (trim $addressController) }} +{{include "cozystack.platform.package.optional.default" (list "cozystack.metallb-iad" $root) }} +{{- end }} {{include "cozystack.platform.package.default" (list "cozystack.reloader" $root) }} {{include "cozystack.platform.package.default" (list "cozystack.linstor-scheduler" $root) }} {{include "cozystack.platform.package.default" (list "cozystack.snapshot-controller" $root) }} diff --git a/packages/core/platform/templates/bundles/system.yaml b/packages/core/platform/templates/bundles/system.yaml index 6dea77ef8..704babdb4 100644 --- a/packages/core/platform/templates/bundles/system.yaml +++ b/packages/core/platform/templates/bundles/system.yaml @@ -387,11 +387,8 @@ variants and opt-in on the slim ones. */}} {{- end }} {{include "cozystack.platform.package.optional.default" (list "cozystack.hetzner-robotlb" $) }} {{include "cozystack.platform.package.optional.default" (list "cozystack.talos-log-collector" $) }} -{{- /* IP addresses as a first-class resource: the class-agnostic core plus the - MetalLB driver. Enable both together — the driver's PackageSource - dependsOn the core (and cozystack.metallb, which the isp-hosted variant - never emits), so enabling only the driver leaves it waiting forever. */}} +{{- /* Its MetalLB driver, cozystack.metallb-iad, is emitted from the + common-packages helper. */}} {{include "cozystack.platform.package.optional.default" (list "cozystack.address-controller" $) }} -{{include "cozystack.platform.package.optional.default" (list "cozystack.metallb-iad" $) }} {{- end }} diff --git a/packages/core/platform/tests/bundles_metallb_iad_variant_test.yaml b/packages/core/platform/tests/bundles_metallb_iad_variant_test.yaml new file mode 100644 index 000000000..2145ae8c2 --- /dev/null +++ b/packages/core/platform/tests/bundles_metallb_iad_variant_test.yaml @@ -0,0 +1,142 @@ +suite: the MetalLB address driver is emitted only beside MetalLB and the address core +templates: + - templates/bundles/system.yaml +release: + name: cozystack + namespace: cozy-system + +tests: + - it: emits the driver on isp-full when enabled + set: + bundles: + system: + enabled: true + variant: isp-full + enabledPackages: + - cozystack.address-controller + - cozystack.metallb-iad + asserts: + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.metallb-iad + any: true + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.metallb + any: true + + - it: withholds the driver on isp-hosted even when enabled + set: + bundles: + system: + enabled: true + variant: isp-hosted + enabledPackages: + - cozystack.address-controller + - cozystack.metallb-iad + asserts: + # any: true is REQUIRED inside the matcher for the negative to search the + # whole document set; without it containsDocument matches nothing and + # `not: true` passes vacuously. + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.metallb-iad + any: true + not: true + # The core carries no MetalLB dependency, so it is still available there. + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.address-controller + any: true + + - it: withholds the driver on a slim variant that did not opt into MetalLB + set: + bundles: + system: + enabled: true + variant: isp-slim + enabledPackages: + - cozystack.address-controller + - cozystack.metallb-iad + asserts: + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.metallb-iad + any: true + not: true + + - it: emits the driver on a slim variant that opted into MetalLB + set: + bundles: + system: + enabled: true + variant: isp-slim + enabledPackages: + - cozystack.metallb + - cozystack.address-controller + - cozystack.metallb-iad + asserts: + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.metallb-iad + any: true + + - it: withholds the driver where disabledPackages removes MetalLB + set: + bundles: + system: + enabled: true + variant: isp-full + enabledPackages: + - cozystack.address-controller + - cozystack.metallb-iad + disabledPackages: + - cozystack.metallb + asserts: + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.metallb-iad + any: true + not: true + + - it: withholds the driver when the address core is not enabled + set: + bundles: + system: + enabled: true + variant: isp-full + enabledPackages: + - cozystack.metallb-iad + asserts: + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.metallb-iad + any: true + not: true + + - it: withholds the driver where disabledPackages removes the address core + set: + bundles: + system: + enabled: true + variant: isp-full + enabledPackages: + - cozystack.address-controller + - cozystack.metallb-iad + disabledPackages: + - cozystack.address-controller + asserts: + - containsDocument: + apiVersion: cozystack.io/v1alpha1 + kind: Package + name: cozystack.metallb-iad + any: true + not: true