From eca11fa58fe9f50e06a857a3c577ef245f39d208 Mon Sep 17 00:00:00 2001 From: Myasnikov Daniil Date: Fri, 23 Oct 2026 14:32:43 +0000 Subject: [PATCH] fix(tenant): stop the gateway release waiting on TenantGateway listeners and certificates helm-controller waits on every object of a release with the kstatus poller on install and on every upgrade. kstatus reads a TenantGateway at Ready=False/ListenersNotReady as InProgress, and a TenantGateway sits there whenever one listener certificate is pending, which depends on ACME or DNS and, under HTTP-01, on routes that other releases own. After a platform upgrade the gateway release therefore times out, retries without end under RetryOnFailure, holds a helm-controller worker meanwhile, and fails the tenant release that waits on it. It used to pass because health is judged only inside a Helm action: the release was installed while the TenantGateway had no status yet or was still Ready, and the listeners whose certificates do not issue came later with other releases' routes. An always-true expression replaces kstatus for TenantGateway and keeps the wait on. Flux checks status.observedGeneration against the generation before it evaluates any expression, so the release still waits until the controller has observed the new spec, but not for listener or certificate health. The poller strategy is set explicitly because expressions are only evaluated under it. Assisted-by: LLM Signed-off-by: Myasnikov Daniil (cherry picked from commit 5265ee662c591db409c8ef1ed8bb457cf29f5c22) Signed-off-by: Myasnikov Daniil --- packages/apps/tenant/templates/gateway.yaml | 17 +++++++ .../apps/tenant/tests/gateway_wait_test.yaml | 44 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 packages/apps/tenant/tests/gateway_wait_test.yaml diff --git a/packages/apps/tenant/templates/gateway.yaml b/packages/apps/tenant/templates/gateway.yaml index cf7efd53c..ec5e1d619 100644 --- a/packages/apps/tenant/templates/gateway.yaml +++ b/packages/apps/tenant/templates/gateway.yaml @@ -50,6 +50,23 @@ spec: retryInterval: 30s remediation: retries: -1 + {{- /* Listener certificates depend on ACME or DNS and, under HTTP-01, on + routes other releases own, so the TenantGateway sits at + Ready=False/ListenersNotReady while any of them is pending, which + kstatus reads as InProgress until the wait runs out. The expression + replaces kstatus for this kind only. Flux still reads InProgress + while status.observedGeneration lags the generation, before any + expression runs, so the release still waits for the controller to + observe the current TenantGateway spec, never for listener or + certificate health. The strategy is pinned because expressions are + read only under poller, and the UseHelm3Defaults gate turns the + default to legacy. */}} + waitStrategy: + name: poller + healthCheckExprs: + - apiVersion: gateway.cozystack.io/v1alpha1 + kind: TenantGateway + current: "true" valuesFrom: - kind: Secret name: cozystack-values diff --git a/packages/apps/tenant/tests/gateway_wait_test.yaml b/packages/apps/tenant/tests/gateway_wait_test.yaml new file mode 100644 index 000000000..889a3673c --- /dev/null +++ b/packages/apps/tenant/tests/gateway_wait_test.yaml @@ -0,0 +1,44 @@ +suite: tenant gateway HelmRelease waits for the TenantGateway generation, not its certificates + +# A TenantGateway reads Ready=False/ListenersNotReady while any listener's +# certificate is pending, and kstatus reads that as InProgress, so under the +# default wait every upgrade of this release times out and retries. The release +# swaps kstatus for an always-Current expression on that kind. The wait itself +# must stay on: Flux still holds it while status.observedGeneration lags, and +# that is the only gate left between the gateway spec and its controller. The +# list is pinned whole because a `failed` or `inProgress` expression that reads +# status would wait again, at least until the controller's first status write. +templates: + - templates/gateway.yaml + +release: + name: tenant-test + namespace: tenant-test + +tests: + - it: reads the TenantGateway through an expression under the poller wait + set: + gateway: true + asserts: + # Pins the document first: the notExists checks below pass on an empty render. + - equal: + path: metadata.name + value: gateway + - equal: + path: spec.waitStrategy.name + value: poller + - equal: + path: spec.healthCheckExprs + value: + - apiVersion: gateway.cozystack.io/v1alpha1 + kind: TenantGateway + current: "true" + - notExists: + path: spec.install.disableWait + - notExists: + path: spec.upgrade.disableWait + + - it: renders no gateway release when the tenant does not own one + asserts: + - hasDocuments: + count: 0