Skip to content

Commit 76445ba

Browse files
committed
fix(monitoring): reject a negative tracingStorages storage
The storage guard only matched zero-shaped values, so -1Gi passed it and the schema's quantity pattern alike, rendered into the VTCluster/VTSingle spec, and left the release failing under retries: -1 once the API server refused the PVC. Refuse a leading minus in the same guard, so the error names the field before anything is applied and matches what the message promises. Signed-off-by: Alexey Artamonov <[email protected]> Assisted-by: LLM
1 parent cf7a568 commit 76445ba

2 files changed

Lines changed: 41 additions & 12 deletions

File tree

‎packages/system/monitoring/templates/_helpers.tpl‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
- name is at most 42 characters: the operator names the StatefulSet
222222
vtstorage-<name>, and each pod carries the label controller-revision-hash:
223223
vtstorage-<name>-<hash> (hash up to 10 characters, value capped at 63).
224-
- storage is not zero: in single mode the operator mounts an EmptyDir when
224+
- storage is positive: in single mode the operator mounts an EmptyDir when
225225
the requested size IsZero, so the store reports operational with no volume.
226226
- retentionDiskUsageBytes uses the operator's BytesString grammar, which
227227
rejects the Kubernetes-quantity `Gi` suffix that storage uses.
@@ -241,8 +241,9 @@
241241
{{- if and (ne $mode "cluster") (ne $mode "single") -}}
242242
{{- fail (printf "monitoring: tracingStorages[%s].mode must be either \"cluster\" or \"single\"" $name) -}}
243243
{{- end -}}
244-
{{- if regexMatch "^[+-]?[0.]*([KMGTPE]i|[numkMGTPE]|[eE][+-]?[0-9]+)?$" ($s.storage | default "" | toString) -}}
245-
{{- fail (printf "monitoring: tracingStorages[%s].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule." $name) -}}
244+
{{- $storage := $s.storage | default "" | toString -}}
245+
{{- if or (regexMatch "^[+-]?[0.]*([KMGTPE]i|[numkMGTPE]|[eE][+-]?[0-9]+)?$" $storage) (hasPrefix "-" $storage) -}}
246+
{{- fail (printf "monitoring: tracingStorages[%s].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created." $name) -}}
246247
{{- end -}}
247248
{{- with $s.retentionDiskUsageBytes -}}
248249
{{- $bytes := . | toString -}}

‎packages/system/monitoring/tests/vtraces_tracingstorages_required_test.yaml‎

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ tests:
268268
storage: ""
269269
asserts:
270270
- failedTemplate:
271-
errorMessage: "monitoring: tracingStorages[generic].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule."
271+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
272272

273273
- it: rejects a zero storage (0Gi) in single mode (the operator would mount an EmptyDir)
274274
templates:
@@ -281,7 +281,7 @@ tests:
281281
storage: 0Gi
282282
asserts:
283283
- failedTemplate:
284-
errorMessage: "monitoring: tracingStorages[generic].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule."
284+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
285285

286286
- it: rejects a zero storage (0) in single mode (the operator would mount an EmptyDir)
287287
templates:
@@ -294,7 +294,7 @@ tests:
294294
storage: "0"
295295
asserts:
296296
- failedTemplate:
297-
errorMessage: "monitoring: tracingStorages[generic].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule."
297+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
298298

299299
- it: rejects a zero storage (0.0) in single mode (the operator would mount an EmptyDir)
300300
templates:
@@ -307,7 +307,7 @@ tests:
307307
storage: "0.0"
308308
asserts:
309309
- failedTemplate:
310-
errorMessage: "monitoring: tracingStorages[generic].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule."
310+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
311311

312312
- it: rejects a zero storage (0e3) in single mode (the operator would mount an EmptyDir)
313313
templates:
@@ -320,7 +320,7 @@ tests:
320320
storage: "0e3"
321321
asserts:
322322
- failedTemplate:
323-
errorMessage: "monitoring: tracingStorages[generic].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule."
323+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
324324

325325
- it: rejects a zero storage (.0) in single mode (the operator would mount an EmptyDir)
326326
templates:
@@ -333,7 +333,7 @@ tests:
333333
storage: ".0"
334334
asserts:
335335
- failedTemplate:
336-
errorMessage: "monitoring: tracingStorages[generic].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule."
336+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
337337

338338
- it: rejects a zero storage (0m) in single mode (the operator would mount an EmptyDir)
339339
templates:
@@ -346,7 +346,7 @@ tests:
346346
storage: "0m"
347347
asserts:
348348
- failedTemplate:
349-
errorMessage: "monitoring: tracingStorages[generic].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule."
349+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
350350

351351
- it: rejects a zero storage (+0) in single mode (the operator would mount an EmptyDir)
352352
templates:
@@ -359,7 +359,7 @@ tests:
359359
storage: "+0"
360360
asserts:
361361
- failedTemplate:
362-
errorMessage: "monitoring: tracingStorages[generic].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule."
362+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
363363

364364
- it: rejects a zero storage (-0Mi) in single mode (the operator would mount an EmptyDir)
365365
templates:
@@ -372,7 +372,35 @@ tests:
372372
storage: "-0Mi"
373373
asserts:
374374
- failedTemplate:
375-
errorMessage: "monitoring: tracingStorages[generic].storage must be a non-zero Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule."
375+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
376+
377+
- it: rejects a negative storage (-1Gi)
378+
templates:
379+
- templates/vtraces/vtraces.yaml
380+
set:
381+
tracingStorages:
382+
- name: generic
383+
mode: cluster
384+
retentionPeriod: "14d"
385+
storage: "-1Gi"
386+
asserts:
387+
- failedTemplate:
388+
errorMessage: "monitoring: tracingStorages[generic].storage must be a positive Kubernetes quantity (e.g. 10Gi). A zero size makes the operator mount an EmptyDir instead of a PVC in single mode, so the backend reports Ready while every stored span is lost on the next reschedule; a negative one fails the release when the PVC is created."
389+
390+
- it: accepts an explicitly signed positive storage (+5Gi)
391+
templates:
392+
- templates/vtraces/vtraces.yaml
393+
set:
394+
tracingStorages:
395+
- name: generic
396+
mode: single
397+
retentionPeriod: "14d"
398+
storage: "+5Gi"
399+
asserts:
400+
- containsDocument:
401+
apiVersion: operator.victoriametrics.com/v1
402+
kind: VTSingle
403+
name: generic
376404

377405
- it: accepts a non-zero storage written with an exponent (5e3)
378406
templates:

0 commit comments

Comments
 (0)