Skip to content

Commit 36a1719

Browse files
Merge pull request #1918 from tremes/insights-duration-validation
OCPBUGS-35196: Insights types - fix duration validation
2 parents 54bdb80 + fd5b4f3 commit 36a1719

File tree

10 files changed

+358
-12
lines changed

10 files changed

+358
-12
lines changed

insights/v1alpha1/tests/datagathers.insights.openshift.io/InsightsOnDemandDataGather.yaml

Lines changed: 140 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,143 @@ tests:
257257
spec: {} # No spec is required for a DataGather
258258
status:
259259
dataGatherState: Running
260-
expectedStatusError: "status.dataGatherState: Invalid value: \"string\": dataGatherState cannot transition from Failed to Running"
260+
expectedStatusError: "status.dataGatherState: Invalid value: \"string\": dataGatherState cannot transition from Failed to Running"
261+
- name: lastGatherDuration can be updated with a trailing zero value
262+
initial: |
263+
apiVersion: insights.openshift.io/v1alpha1
264+
kind: DataGather
265+
spec: {} # No spec is required for a DataGather
266+
updated: |
267+
apiVersion: insights.openshift.io/v1alpha1
268+
kind: DataGather
269+
spec: {} # No spec is required for a DataGather
270+
status:
271+
gatherers:
272+
- name: testGatherer
273+
lastGatherDuration: 1m0s
274+
conditions:
275+
- type: Gathered
276+
status: "True"
277+
reason: OK
278+
message: "test message"
279+
lastTransitionTime: "2024-12-01T08:04:21Z"
280+
expected: |
281+
apiVersion: insights.openshift.io/v1alpha1
282+
kind: DataGather
283+
spec: {} # No spec is required for a DataGather
284+
status:
285+
gatherers:
286+
- name: testGatherer
287+
lastGatherDuration: 1m0s
288+
conditions:
289+
- type: Gathered
290+
status: "True"
291+
reason: OK
292+
message: "test message"
293+
lastTransitionTime: "2024-12-01T08:04:21Z"
294+
- name: lastGatherDuration can be updated with a leading zero value
295+
initial: |
296+
apiVersion: insights.openshift.io/v1alpha1
297+
kind: DataGather
298+
spec: {} # No spec is required for a DataGather
299+
updated: |
300+
apiVersion: insights.openshift.io/v1alpha1
301+
kind: DataGather
302+
spec: {} # No spec is required for a DataGather
303+
status:
304+
gatherers:
305+
- name: testGatherer
306+
lastGatherDuration: 0m11s
307+
conditions:
308+
- type: Gathered
309+
status: "True"
310+
reason: OK
311+
message: "test message"
312+
lastTransitionTime: "2024-12-01T08:04:21Z"
313+
expected: |
314+
apiVersion: insights.openshift.io/v1alpha1
315+
kind: DataGather
316+
spec: {} # No spec is required for a DataGather
317+
status:
318+
gatherers:
319+
- name: testGatherer
320+
lastGatherDuration: 0m11s
321+
conditions:
322+
- type: Gathered
323+
status: "True"
324+
reason: OK
325+
message: "test message"
326+
lastTransitionTime: "2024-12-01T08:04:21Z"
327+
- name: lastGatherDuration can be updated with a decimal number value
328+
initial: |
329+
apiVersion: insights.openshift.io/v1alpha1
330+
kind: DataGather
331+
spec: {} # No spec is required for a DataGather
332+
updated: |
333+
apiVersion: insights.openshift.io/v1alpha1
334+
kind: DataGather
335+
spec: {} # No spec is required for a DataGather
336+
status:
337+
gatherers:
338+
- name: testGatherer
339+
lastGatherDuration: 1m0.77s
340+
conditions:
341+
- type: Gathered
342+
status: "True"
343+
reason: OK
344+
message: "test message"
345+
lastTransitionTime: "2024-12-01T08:04:21Z"
346+
expected: |
347+
apiVersion: insights.openshift.io/v1alpha1
348+
kind: DataGather
349+
spec: {} # No spec is required for a DataGather
350+
status:
351+
gatherers:
352+
- name: testGatherer
353+
lastGatherDuration: 1m0.77s
354+
conditions:
355+
- type: Gathered
356+
status: "True"
357+
reason: OK
358+
message: "test message"
359+
lastTransitionTime: "2024-12-01T08:04:21Z"
360+
- name: lastGatherDuration cannot be updated with an invalid value
361+
initial: |
362+
apiVersion: insights.openshift.io/v1alpha1
363+
kind: DataGather
364+
spec: {} # No spec is required for a DataGather
365+
updated: |
366+
apiVersion: insights.openshift.io/v1alpha1
367+
kind: DataGather
368+
spec: {} # No spec is required for a DataGather
369+
status:
370+
gatherers:
371+
- name: testGatherer
372+
lastGatherDuration: 1d2h
373+
conditions:
374+
- type: Gathered
375+
status: "True"
376+
reason: OK
377+
message: "test message"
378+
lastTransitionTime: "2024-12-01T08:04:21Z"
379+
expectedStatusError: "Invalid value: \"1d2h\": gatherers[0].lastGatherDuration in body should match '^(([0-9]+(?:\\.[0-9]+)?(ns|us|µs|μs|ms|s|m|h))+)$'"
380+
- name: lastGatherDuration cannot be updated with a negative value
381+
initial: |
382+
apiVersion: insights.openshift.io/v1alpha1
383+
kind: DataGather
384+
spec: {} # No spec is required for a DataGather
385+
updated: |
386+
apiVersion: insights.openshift.io/v1alpha1
387+
kind: DataGather
388+
spec: {} # No spec is required for a DataGather
389+
status:
390+
gatherers:
391+
- name: testGatherer
392+
lastGatherDuration: -0m5s
393+
conditions:
394+
- type: Gathered
395+
status: "True"
396+
reason: OK
397+
message: "test message"
398+
lastTransitionTime: "2024-12-01T08:04:21Z"
399+
expectedStatusError: "Invalid value: \"-0m5s\": gatherers[0].lastGatherDuration in body should match '^(([0-9]+(?:\\.[0-9]+)?(ns|us|µs|μs|ms|s|m|h))+)$'"

insights/v1alpha1/types_insights.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ type GathererStatus struct {
168168
// lastGatherDuration represents the time spent gathering.
169169
// +required
170170
// +kubebuilder:validation:Type=string
171-
// +kubebuilder:validation:Pattern="^([1-9][0-9]*(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
171+
// +kubebuilder:validation:Pattern="^(([0-9]+(?:\\.[0-9]+)?(ns|us|µs|μs|ms|s|m|h))+)$"
172172
LastGatherDuration metav1.Duration `json:"lastGatherDuration"`
173173
}
174174

insights/v1alpha1/zz_generated.crd-manifests/0000_10_insights_01_datagathers-CustomNoUpgrade.crd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ spec:
263263
x-kubernetes-list-type: map
264264
lastGatherDuration:
265265
description: lastGatherDuration represents the time spent gathering.
266-
pattern: ^([1-9][0-9]*(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
266+
pattern: ^(([0-9]+(?:\.[0-9]+)?(ns|us|µs|μs|ms|s|m|h))+)$
267267
type: string
268268
name:
269269
description: name is the name of the gatherer.

insights/v1alpha1/zz_generated.crd-manifests/0000_10_insights_01_datagathers-DevPreviewNoUpgrade.crd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ spec:
263263
x-kubernetes-list-type: map
264264
lastGatherDuration:
265265
description: lastGatherDuration represents the time spent gathering.
266-
pattern: ^([1-9][0-9]*(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
266+
pattern: ^(([0-9]+(?:\.[0-9]+)?(ns|us|µs|μs|ms|s|m|h))+)$
267267
type: string
268268
name:
269269
description: name is the name of the gatherer.

insights/v1alpha1/zz_generated.crd-manifests/0000_10_insights_01_datagathers-TechPreviewNoUpgrade.crd.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ spec:
263263
x-kubernetes-list-type: map
264264
lastGatherDuration:
265265
description: lastGatherDuration represents the time spent gathering.
266-
pattern: ^([1-9][0-9]*(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
266+
pattern: ^(([0-9]+(?:\.[0-9]+)?(ns|us|µs|μs|ms|s|m|h))+)$
267267
type: string
268268
name:
269269
description: name is the name of the gatherer.

insights/v1alpha1/zz_generated.featuregated-crd-manifests/datagathers.insights.openshift.io/InsightsOnDemandDataGather.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ spec:
263263
x-kubernetes-list-type: map
264264
lastGatherDuration:
265265
description: lastGatherDuration represents the time spent gathering.
266-
pattern: ^([1-9][0-9]*(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
266+
pattern: ^(([0-9]+(?:\.[0-9]+)?(ns|us|µs|μs|ms|s|m|h))+)$
267267
type: string
268268
name:
269269
description: name is the name of the gatherer.

0 commit comments

Comments
 (0)