Merge pull request #903 from fluxcd/api-validate-duration

api: add custom validation for v1.Duration types
This commit is contained in:
Hidde Beydals 2022-09-20 09:46:23 +00:00 committed by GitHub
commit 54d706a226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 27 additions and 0 deletions

View File

@ -78,11 +78,15 @@ type BucketSpec struct {
SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"` SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"`
// Interval at which to check the Endpoint for updates. // Interval at which to check the Endpoint for updates.
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
// +required // +required
Interval metav1.Duration `json:"interval"` Interval metav1.Duration `json:"interval"`
// Timeout for fetch operations, defaults to 60s. // Timeout for fetch operations, defaults to 60s.
// +kubebuilder:default="60s" // +kubebuilder:default="60s"
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
// +optional // +optional
Timeout *metav1.Duration `json:"timeout,omitempty"` Timeout *metav1.Duration `json:"timeout,omitempty"`

View File

@ -62,11 +62,15 @@ type GitRepositorySpec struct {
SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"` SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"`
// Interval at which to check the GitRepository for updates. // Interval at which to check the GitRepository for updates.
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
// +required // +required
Interval metav1.Duration `json:"interval"` Interval metav1.Duration `json:"interval"`
// Timeout for Git operations like cloning, defaults to 60s. // Timeout for Git operations like cloning, defaults to 60s.
// +kubebuilder:default="60s" // +kubebuilder:default="60s"
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
// +optional // +optional
Timeout *metav1.Duration `json:"timeout,omitempty"` Timeout *metav1.Duration `json:"timeout,omitempty"`

View File

@ -46,6 +46,8 @@ type HelmChartSpec struct {
SourceRef LocalHelmChartSourceReference `json:"sourceRef"` SourceRef LocalHelmChartSourceReference `json:"sourceRef"`
// Interval is the interval at which to check the Source for updates. // Interval is the interval at which to check the Source for updates.
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
// +required // +required
Interval metav1.Duration `json:"interval"` Interval metav1.Duration `json:"interval"`

View File

@ -65,6 +65,8 @@ type HelmRepositorySpec struct {
PassCredentials bool `json:"passCredentials,omitempty"` PassCredentials bool `json:"passCredentials,omitempty"`
// Interval at which to check the URL for updates. // Interval at which to check the URL for updates.
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
// +required // +required
Interval metav1.Duration `json:"interval"` Interval metav1.Duration `json:"interval"`
@ -72,6 +74,8 @@ type HelmRepositorySpec struct {
// and for remote OCI Repository operations like pulling for an OCI helm repository. // and for remote OCI Repository operations like pulling for an OCI helm repository.
// Its default value is 60s. // Its default value is 60s.
// +kubebuilder:default:="60s" // +kubebuilder:default:="60s"
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
// +optional // +optional
Timeout *metav1.Duration `json:"timeout,omitempty"` Timeout *metav1.Duration `json:"timeout,omitempty"`

View File

@ -99,11 +99,15 @@ type OCIRepositorySpec struct {
CertSecretRef *meta.LocalObjectReference `json:"certSecretRef,omitempty"` CertSecretRef *meta.LocalObjectReference `json:"certSecretRef,omitempty"`
// The interval at which to check for image updates. // The interval at which to check for image updates.
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m|h))+$"
// +required // +required
Interval metav1.Duration `json:"interval"` Interval metav1.Duration `json:"interval"`
// The timeout for remote OCI Repository operations like pulling, defaults to 60s. // The timeout for remote OCI Repository operations like pulling, defaults to 60s.
// +kubebuilder:default="60s" // +kubebuilder:default="60s"
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ms|s|m))+$"
// +optional // +optional
Timeout *metav1.Duration `json:"timeout,omitempty"` Timeout *metav1.Duration `json:"timeout,omitempty"`

View File

@ -331,6 +331,7 @@ spec:
type: boolean type: boolean
interval: interval:
description: Interval at which to check the Endpoint for updates. description: Interval at which to check the Endpoint for updates.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
type: string type: string
provider: provider:
default: generic default: generic
@ -363,6 +364,7 @@ spec:
timeout: timeout:
default: 60s default: 60s
description: Timeout for fetch operations, defaults to 60s. description: Timeout for fetch operations, defaults to 60s.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
type: string type: string
required: required:
- bucketName - bucketName

View File

@ -459,6 +459,7 @@ spec:
type: array type: array
interval: interval:
description: Interval at which to check the GitRepository for updates. description: Interval at which to check the GitRepository for updates.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
type: string type: string
recurseSubmodules: recurseSubmodules:
description: RecurseSubmodules enables the initialization of all submodules description: RecurseSubmodules enables the initialization of all submodules
@ -510,6 +511,7 @@ spec:
default: 60s default: 60s
description: Timeout for Git operations like cloning, defaults to description: Timeout for Git operations like cloning, defaults to
60s. 60s.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
type: string type: string
url: url:
description: URL specifies the Git repository URL, it can be an HTTP/S description: URL specifies the Git repository URL, it can be an HTTP/S

View File

@ -352,6 +352,7 @@ spec:
interval: interval:
description: Interval is the interval at which to check the Source description: Interval is the interval at which to check the Source
for updates. for updates.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
type: string type: string
reconcileStrategy: reconcileStrategy:
default: ChartVersion default: ChartVersion

View File

@ -302,6 +302,7 @@ spec:
type: object type: object
interval: interval:
description: Interval at which to check the URL for updates. description: Interval at which to check the URL for updates.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
type: string type: string
passCredentials: passCredentials:
description: PassCredentials allows the credentials from the SecretRef description: PassCredentials allows the credentials from the SecretRef
@ -344,6 +345,7 @@ spec:
description: Timeout is used for the index fetch operation for an description: Timeout is used for the index fetch operation for an
HTTPS helm repository, and for remote OCI Repository operations HTTPS helm repository, and for remote OCI Repository operations
like pulling for an OCI helm repository. Its default value is 60s. like pulling for an OCI helm repository. Its default value is 60s.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
type: string type: string
type: type:
description: Type of the HelmRepository. When this field is set to "oci", description: Type of the HelmRepository. When this field is set to "oci",

View File

@ -78,6 +78,7 @@ spec:
type: boolean type: boolean
interval: interval:
description: The interval at which to check for image updates. description: The interval at which to check for image updates.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m|h))+$
type: string type: string
layerSelector: layerSelector:
description: LayerSelector specifies which layer should be extracted description: LayerSelector specifies which layer should be extracted
@ -140,6 +141,7 @@ spec:
default: 60s default: 60s
description: The timeout for remote OCI Repository operations like description: The timeout for remote OCI Repository operations like
pulling, defaults to 60s. pulling, defaults to 60s.
pattern: ^([0-9]+(\.[0-9]+)?(ms|s|m))+$
type: string type: string
url: url:
description: URL is a reference to an OCI artifact repository hosted description: URL is a reference to an OCI artifact repository hosted