Skip to content

Commit 27f4ed5

Browse files
committed
api: add custom validation for v1.Duration types
To solve discrepancies between parsing versus validation. xref: kubernetes/apimachinery#131 Signed-off-by: Hidde Beydals <[email protected]>
1 parent 7b4a193 commit 27f4ed5

10 files changed

+27
-0
lines changed

api/v1beta2/bucket_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,15 @@ type BucketSpec struct {
7878
SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"`
7979

8080
// Interval at which to check the Endpoint for updates.
81+
// +kubebuilder:validation:Type=string
82+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
8183
// +required
8284
Interval metav1.Duration `json:"interval"`
8385

8486
// Timeout for fetch operations, defaults to 60s.
8587
// +kubebuilder:default="60s"
88+
// +kubebuilder:validation:Type=string
89+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
8690
// +optional
8791
Timeout *metav1.Duration `json:"timeout,omitempty"`
8892

api/v1beta2/gitrepository_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ type GitRepositorySpec struct {
6262
SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"`
6363

6464
// Interval at which to check the GitRepository for updates.
65+
// +kubebuilder:validation:Type=string
66+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
6567
// +required
6668
Interval metav1.Duration `json:"interval"`
6769

6870
// Timeout for Git operations like cloning, defaults to 60s.
6971
// +kubebuilder:default="60s"
72+
// +kubebuilder:validation:Type=string
73+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
7074
// +optional
7175
Timeout *metav1.Duration `json:"timeout,omitempty"`
7276

api/v1beta2/helmchart_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type HelmChartSpec struct {
4646
SourceRef LocalHelmChartSourceReference `json:"sourceRef"`
4747

4848
// Interval is the interval at which to check the Source for updates.
49+
// +kubebuilder:validation:Type=string
50+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
4951
// +required
5052
Interval metav1.Duration `json:"interval"`
5153

api/v1beta2/helmrepository_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@ type HelmRepositorySpec struct {
6565
PassCredentials bool `json:"passCredentials,omitempty"`
6666

6767
// Interval at which to check the URL for updates.
68+
// +kubebuilder:validation:Type=string
69+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
6870
// +required
6971
Interval metav1.Duration `json:"interval"`
7072

7173
// Timeout is used for the index fetch operation for an HTTPS helm repository,
7274
// and for remote OCI Repository operations like pulling for an OCI helm repository.
7375
// Its default value is 60s.
7476
// +kubebuilder:default:="60s"
77+
// +kubebuilder:validation:Type=string
78+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
7579
// +optional
7680
Timeout *metav1.Duration `json:"timeout,omitempty"`
7781

api/v1beta2/ocirepository_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ type OCIRepositorySpec struct {
9999
CertSecretRef *meta.LocalObjectReference `json:"certSecretRef,omitempty"`
100100

101101
// The interval at which to check for image updates.
102+
// +kubebuilder:validation:Type=string
103+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
102104
// +required
103105
Interval metav1.Duration `json:"interval"`
104106

105107
// The timeout for remote OCI Repository operations like pulling, defaults to 60s.
106108
// +kubebuilder:default="60s"
109+
// +kubebuilder:validation:Type=string
110+
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
107111
// +optional
108112
Timeout *metav1.Duration `json:"timeout,omitempty"`
109113

config/crd/bases/source.toolkit.fluxcd.io_buckets.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ spec:
331331
type: boolean
332332
interval:
333333
description: Interval at which to check the Endpoint for updates.
334+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
334335
type: string
335336
provider:
336337
default: generic
@@ -363,6 +364,7 @@ spec:
363364
timeout:
364365
default: 60s
365366
description: Timeout for fetch operations, defaults to 60s.
367+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
366368
type: string
367369
required:
368370
- bucketName

config/crd/bases/source.toolkit.fluxcd.io_gitrepositories.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ spec:
459459
type: array
460460
interval:
461461
description: Interval at which to check the GitRepository for updates.
462+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
462463
type: string
463464
recurseSubmodules:
464465
description: RecurseSubmodules enables the initialization of all submodules
@@ -510,6 +511,7 @@ spec:
510511
default: 60s
511512
description: Timeout for Git operations like cloning, defaults to
512513
60s.
514+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
513515
type: string
514516
url:
515517
description: URL specifies the Git repository URL, it can be an HTTP/S

config/crd/bases/source.toolkit.fluxcd.io_helmcharts.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ spec:
352352
interval:
353353
description: Interval is the interval at which to check the Source
354354
for updates.
355+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
355356
type: string
356357
reconcileStrategy:
357358
default: ChartVersion

config/crd/bases/source.toolkit.fluxcd.io_helmrepositories.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ spec:
302302
type: object
303303
interval:
304304
description: Interval at which to check the URL for updates.
305+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
305306
type: string
306307
passCredentials:
307308
description: PassCredentials allows the credentials from the SecretRef
@@ -344,6 +345,7 @@ spec:
344345
description: Timeout is used for the index fetch operation for an
345346
HTTPS helm repository, and for remote OCI Repository operations
346347
like pulling for an OCI helm repository. Its default value is 60s.
348+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
347349
type: string
348350
type:
349351
description: Type of the HelmRepository. When this field is set to "oci",

config/crd/bases/source.toolkit.fluxcd.io_ocirepositories.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ spec:
7878
type: boolean
7979
interval:
8080
description: The interval at which to check for image updates.
81+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
8182
type: string
8283
layerSelector:
8384
description: LayerSelector specifies which layer should be extracted
@@ -140,6 +141,7 @@ spec:
140141
default: 60s
141142
description: The timeout for remote OCI Repository operations like
142143
pulling, defaults to 60s.
144+
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
143145
type: string
144146
url:
145147
description: URL is a reference to an OCI artifact repository hosted

0 commit comments

Comments
 (0)