|
| 1 | +/* |
| 2 | +Copyright 2026 Cozystack contributors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package rest |
| 18 | + |
| 19 | +import "net/http" |
| 20 | + |
| 21 | +// registerPhysicalStorage wires the `linstor physical-storage` and |
| 22 | +// `linstor physical-storage create-device-pool` endpoints. |
| 23 | +// |
| 24 | +// Cozystack provisions storage pools out-of-band through Talos |
| 25 | +// extensions / kubelet, so the device-pool create path is explicitly |
| 26 | +// out of scope: returning 501 keeps `linstor` CLI from claiming |
| 27 | +// success and fixes a piraeus-operator code path that would |
| 28 | +// otherwise loop on a 404. The list endpoint surfaces an empty bag |
| 29 | +// (we don't enumerate raw devices) so the CLI's |
| 30 | +// `linstor physical-storage list` doesn't error. |
| 31 | +func (s *Server) registerPhysicalStorage(mux *http.ServeMux) { |
| 32 | + mux.HandleFunc("GET /v1/physical-storage", handleEmptyPhysicalStorage) |
| 33 | + mux.HandleFunc("GET /v1/nodes/{node}/physical-storage", |
| 34 | + handleEmptyPhysicalStorage) |
| 35 | + mux.HandleFunc("POST /v1/physical-storage/{node}", |
| 36 | + handlePhysicalStorageCreateNotImplemented) |
| 37 | +} |
| 38 | + |
| 39 | +// handleEmptyPhysicalStorage returns the empty-pool envelope golinstor |
| 40 | +// expects. The shape is `[]` for the cluster-wide list and a JSON |
| 41 | +// object with a `nodes: {}` entry for the per-node variant; both |
| 42 | +// decode cleanly when empty. |
| 43 | +func handleEmptyPhysicalStorage(w http.ResponseWriter, _ *http.Request) { |
| 44 | + writeJSON(w, http.StatusOK, []struct{}{}) |
| 45 | +} |
| 46 | + |
| 47 | +// handlePhysicalStorageCreateNotImplemented surfaces 501 with a |
| 48 | +// LINSTOR-shaped ApiCallRc body explaining the boundary. piraeus- |
| 49 | +// operator's `LinstorSatelliteConfiguration.spec.storagePools` would |
| 50 | +// otherwise retry the call indefinitely. |
| 51 | +func handlePhysicalStorageCreateNotImplemented(w http.ResponseWriter, _ *http.Request) { |
| 52 | + writeError(w, http.StatusNotImplemented, |
| 53 | + "physical-storage create is out of scope for blockstor; "+ |
| 54 | + "provision storage pools via Talos extensions / static node config") |
| 55 | +} |
0 commit comments