From 71ab2602391826aedc5cce158ac8fe865b2836aa Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 27 Nov 2026 21:00:42 +0100 Subject: [PATCH] fix(linstor): keep scheduler and GUI off a stale endpoint on a switch Under backend blockstor linstor-scheduler and linstor-gui read the API endpoint from the LinstorCluster the linstor release renders. The backend reaches both charts in one platform render, and dependsOn holds them back only while the linstor release is not Ready, so on a switch they can upgrade before the linstor release has written externalController. They then fell back to the values, linstor-controller, a Service piraeus-operator removes in external mode, and nothing rendered them again: the scheduler stayed pointed at a deleted controller. Fail the render instead while the LinstorCluster names no external controller. The platform's HelmReleases use the RetryOnFailure strategy, and a failed render stores no release, so helm-controller retries after the retry interval without counting a failure until the linstor release has written the endpoint. Under backend linstor nothing changes. Assisted-by: LLM Signed-off-by: Andrei Kvapil --- packages/system/linstor-gui/README.md | 2 +- .../system/linstor-gui/templates/_helpers.tpl | 19 ++++++++----- .../linstor-gui/tests/api_client_test.yaml | 14 +++++----- packages/system/linstor-gui/values.yaml | 2 +- .../linstor-scheduler/templates/_helpers.tpl | 27 +++++++++++++------ .../tests/api_client_test.yaml | 17 +++++------- packages/system/linstor-scheduler/values.yaml | 5 ++-- 7 files changed, 49 insertions(+), 37 deletions(-) diff --git a/packages/system/linstor-gui/README.md b/packages/system/linstor-gui/README.md index 8f13f02e7..4ce6829d4 100644 --- a/packages/system/linstor-gui/README.md +++ b/packages/system/linstor-gui/README.md @@ -60,6 +60,6 @@ then open . | Name | Description | Value | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------- | -| `linstor.backend` | Storage backend the platform runs, `linstor` or `blockstor`. Under `blockstor` the endpoint and client Secret are read from the LinstorCluster the `linstor` package renders, and the two values below apply only while it runs an in-cluster controller. | `linstor` | +| `linstor.backend` | Storage backend the platform runs, `linstor` or `blockstor`. Under `blockstor` the endpoint and client Secret are read from the LinstorCluster the `linstor` package renders, the render fails until that object names an external controller, and the two values below apply only under `linstor`. | `linstor` | | `linstor.endpoint` | In-cluster URL of the LINSTOR controller REST API (HTTPS, mTLS) | `https://linstor-controller.cozy-linstor.svc:3371` | | `linstor.clientSecret` | Kubernetes Secret with `tls.crt`, `tls.key`, `ca.crt` used as the mTLS client certificate against the LINSTOR controller. Created by the `linstor` package. | `linstor-client-tls` | diff --git a/packages/system/linstor-gui/templates/_helpers.tpl b/packages/system/linstor-gui/templates/_helpers.tpl index cfdc2b4bd..699df70bb 100644 --- a/packages/system/linstor-gui/templates/_helpers.tpl +++ b/packages/system/linstor-gui/templates/_helpers.tpl @@ -25,10 +25,14 @@ which name the in-cluster controller and the Secret piraeus-operator issues for it. Under backend blockstor the linstor package decides: it renders the LinstorCluster that points piraeus-operator, and through it linstor-csi, at the API, so this chart reads the same two fields and follows wherever they -point. A LinstorCluster still running an in-cluster controller leaves the -values in effect. The package depends on cozystack.linstor, so the -LinstorCluster exists before this chart renders; a render that finds none, or -more than one, fails rather than guess. +point. The package depends on cozystack.linstor, so the LinstorCluster +exists before this chart renders; a render that finds none, or more than one, +fails rather than guess. One without externalController fails as well: on a +backend switch this release can upgrade before the linstor release has +rewritten the LinstorCluster, and falling back to the values would leave the +GUI on linstor-controller, which piraeus-operator removes, with nothing to +render it again. Failing keeps the HelmRelease retrying until the endpoint is +there. */}} {{- define "linstor-gui.apiClient" -}} {{- $backend := .Values.linstor.backend | default "linstor" -}} @@ -43,10 +47,11 @@ more than one, fails rather than guess. {{- fail (printf "linstor.backend is blockstor, so the LINSTOR API endpoint is read from the LinstorCluster the linstor package renders, but the cluster has %d LinstorClusters" (len $clusters)) -}} {{- end -}} {{- $spec := (index $clusters 0).spec | default dict -}} -{{- with dig "externalController" "url" "" $spec -}} -{{- $endpoint = . -}} -{{- $clientSecret = dig "apiTLS" "clientSecretName" "linstor-client-tls" $spec -}} +{{- $endpoint = dig "externalController" "url" "" $spec -}} +{{- if not $endpoint -}} +{{- fail "linstor.backend is blockstor, but the LinstorCluster has no spec.externalController.url yet: the linstor release has not switched it to blockstor-apiserver. This release is retried until it has" -}} {{- end -}} +{{- $clientSecret = dig "apiTLS" "clientSecretName" "linstor-client-tls" $spec -}} {{- end -}} endpoint: {{ $endpoint | quote }} clientSecret: {{ $clientSecret | quote }} diff --git a/packages/system/linstor-gui/tests/api_client_test.yaml b/packages/system/linstor-gui/tests/api_client_test.yaml index 44b674449..db96411aa 100644 --- a/packages/system/linstor-gui/tests/api_client_test.yaml +++ b/packages/system/linstor-gui/tests/api_client_test.yaml @@ -83,9 +83,10 @@ tests: secretName: linstor-client-tls defaultMode: 0444 - # While a LinstorCluster still runs its own controller under blockstor, - # that controller is the API linstor-csi uses, so this chart stays on it. - - it: keeps the values while the LinstorCluster runs an in-cluster controller + # On a backend switch this release can upgrade before the linstor release + # has written externalController. Falling back to the values would leave + # the GUI on linstor-controller for good; failing has Flux retry it. + - it: refuses blockstor while the LinstorCluster has no external controller yet set: linstor.backend: blockstor kubernetesProvider: @@ -95,11 +96,10 @@ tests: apiVersion: piraeus.io/v1 metadata: {name: linstorcluster} spec: {} - template: templates/configmap-nginx.yaml + template: templates/deployment.yaml asserts: - - matchRegex: - path: data["nginx.conf"] - pattern: "proxy_pass https://linstor-controller.cozy-linstor.svc:3371;" + - failedTemplate: + errorPattern: "linstor.backend is blockstor, but the LinstorCluster has no spec.externalController.url yet" - it: refuses blockstor when no LinstorCluster tells it where the API is set: diff --git a/packages/system/linstor-gui/values.yaml b/packages/system/linstor-gui/values.yaml index 48414c905..efc91e535 100644 --- a/packages/system/linstor-gui/values.yaml +++ b/packages/system/linstor-gui/values.yaml @@ -12,7 +12,7 @@ image: ## @param replicas Number of linstor-gui replicas replicas: 1 ## @section LINSTOR controller connection -## @param linstor.backend Storage backend the platform runs, `linstor` or `blockstor`. Under `blockstor` the endpoint and client Secret are read from the LinstorCluster the `linstor` package renders, and the two values below apply only while it runs an in-cluster controller. +## @param linstor.backend Storage backend the platform runs, `linstor` or `blockstor`. Under `blockstor` the endpoint and client Secret are read from the LinstorCluster the `linstor` package renders, the render fails until that object names an external controller, and the two values below apply only under `linstor`. ## @param linstor.endpoint In-cluster URL of the LINSTOR controller REST API (HTTPS, mTLS) ## @param linstor.clientSecret Kubernetes Secret with `tls.crt`, `tls.key`, `ca.crt` used as the mTLS client certificate against the LINSTOR controller. Created by the `linstor` package. linstor: diff --git a/packages/system/linstor-scheduler/templates/_helpers.tpl b/packages/system/linstor-scheduler/templates/_helpers.tpl index a15579251..3dea1ece5 100644 --- a/packages/system/linstor-scheduler/templates/_helpers.tpl +++ b/packages/system/linstor-scheduler/templates/_helpers.tpl @@ -8,11 +8,20 @@ Under backend linstor it returns nothing: the values name the in-cluster controller and the Secret piraeus-operator issues for it. Under backend blockstor the linstor package decides: it renders the LinstorCluster that points piraeus-operator, and through it linstor-csi, at the API, so the -scheduler reads the same two fields and follows wherever they point. A -LinstorCluster still running an in-cluster controller leaves the values in -effect. The package depends on cozystack.linstor, so the LinstorCluster -exists before this chart renders; a render that finds none, or more than -one, fails rather than guess. +scheduler reads the same two fields and follows wherever they point. The +package depends on cozystack.linstor, so the LinstorCluster exists before +this chart renders; a render that finds none, or more than one, fails rather +than guess. + +A LinstorCluster without externalController fails the render too. The +backend reaches this chart and the linstor chart in the same platform +render, and dependsOn holds this release back only while the linstor release +is not Ready, so on a switch it can upgrade first, against the LinstorCluster +the linstor release has not rewritten yet. Falling back to the values there +would leave the scheduler on linstor-controller, a Service piraeus-operator +removes once it sees externalController, and nothing would render this +release again. Failing keeps the HelmRelease retrying until the linstor +release has written the endpoint. */}} {{- define "linstor-scheduler.cozystack.apiClient" -}} {{- $backend := .Values.linstor.backend | default "linstor" -}} @@ -25,9 +34,11 @@ one, fails rather than guess. {{- fail (printf "linstor-scheduler.linstor.backend is blockstor, so the LINSTOR API endpoint is read from the LinstorCluster the linstor package renders, but the cluster has %d LinstorClusters" (len $clusters)) -}} {{- end -}} {{- $spec := (index $clusters 0).spec | default dict -}} -{{- with dig "externalController" "url" "" $spec }} -endpoint: {{ . | quote }} +{{- $endpoint := dig "externalController" "url" "" $spec -}} +{{- if not $endpoint -}} +{{- fail "linstor-scheduler.linstor.backend is blockstor, but the LinstorCluster has no spec.externalController.url yet: the linstor release has not switched it to blockstor-apiserver. This release is retried until it has" -}} +{{- end }} +endpoint: {{ $endpoint | quote }} clientSecret: {{ dig "apiTLS" "clientSecretName" "linstor-client-tls" $spec | quote }} {{- end -}} -{{- end -}} {{- end }} diff --git a/packages/system/linstor-scheduler/tests/api_client_test.yaml b/packages/system/linstor-scheduler/tests/api_client_test.yaml index f0f2ad77c..deed4eac2 100644 --- a/packages/system/linstor-scheduler/tests/api_client_test.yaml +++ b/packages/system/linstor-scheduler/tests/api_client_test.yaml @@ -74,9 +74,10 @@ tests: path: metadata.annotations["secret.reloader.stakater.com/reload"] value: linstor-client-tls - # While a LinstorCluster still runs its own controller under blockstor, - # that controller is the API linstor-csi uses, so the scheduler stays on it. - - it: keeps the values while the LinstorCluster runs an in-cluster controller + # On a backend switch this release can upgrade before the linstor release + # has written externalController. Falling back to the values would leave + # the scheduler on linstor-controller for good; failing has Flux retry it. + - it: refuses blockstor while the LinstorCluster has no external controller yet set: linstor-scheduler.linstor.backend: blockstor kubernetesProvider: @@ -87,14 +88,8 @@ tests: metadata: {name: linstorcluster} spec: {} asserts: - - contains: - path: spec.template.spec.containers[1].env - content: - name: LS_CONTROLLERS - value: https://linstor-controller.cozy-linstor.svc:3371 - - equal: - path: metadata.annotations["secret.reloader.stakater.com/reload"] - value: linstor-client-tls + - failedTemplate: + errorPattern: "backend is blockstor, but the LinstorCluster has no spec.externalController.url yet" - it: refuses blockstor when no LinstorCluster tells it where the API is set: diff --git a/packages/system/linstor-scheduler/values.yaml b/packages/system/linstor-scheduler/values.yaml index 854ae5940..981c3ad6e 100644 --- a/packages/system/linstor-scheduler/values.yaml +++ b/packages/system/linstor-scheduler/values.yaml @@ -11,8 +11,9 @@ linstor-scheduler: linstor: # The storage backend the platform runs, linstor or blockstor. Under # blockstor the endpoint and client Secret come from the LinstorCluster - # the linstor package renders (templates/_helpers.tpl), and the two - # values below apply only while it runs an in-cluster controller. + # the linstor package renders (templates/_helpers.tpl), the render + # fails until that object names an external controller, and the two + # values below apply only under linstor. backend: linstor endpoint: "https://linstor-controller.cozy-linstor.svc:3371" clientSecret: "linstor-client-tls"