Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit Pattern to validate Duration fields #1690

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apis/hive/v1/clusterclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ type ClusterClaimSpec struct {
// Lifetime is the maximum lifetime of the claim after it is assigned a cluster. If the claim still exists
// when the lifetime has elapsed, the claim will be deleted by Hive.
// This is a Duration value; see https://pkg.go.dev/time#ParseDuration for accepted formats.
// Note: due to discrepancies in validation vs parsing, we use a Pattern instead of `Format=duration`. See
// https://bugzilla.redhat.com/show_bug.cgi?id=2050332
// https://github.com/kubernetes/apimachinery/issues/131
// https://github.com/kubernetes/apiextensions-apiserver/issues/56
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
Lifetime *metav1.Duration `json:"lifetime,omitempty"`
}

Expand Down
6 changes: 5 additions & 1 deletion apis/hive/v1/clusterdeployment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@ type ClusterDeploymentSpec struct {
// given duration. The time that a cluster has been running is the time since the cluster was installed or the
// time since the cluster last came out of hibernation.
// This is a Duration value; see https://pkg.go.dev/time#ParseDuration for accepted formats.
// Note: due to discrepancies in validation vs parsing, we use a Pattern instead of `Format=duration`. See
// https://bugzilla.redhat.com/show_bug.cgi?id=2050332
// https://github.com/kubernetes/apimachinery/issues/131
// https://github.com/kubernetes/apiextensions-apiserver/issues/56
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
HibernateAfter *metav1.Duration `json:"hibernateAfter,omitempty"`

// InstallAttemptsLimit is the maximum number of times Hive will attempt to install the cluster.
Expand Down
18 changes: 15 additions & 3 deletions apis/hive/v1/clusterpool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ type ClusterPoolSpec struct {
// that a cluster has been running is the time since the cluster was installed or the time since the cluster last came
// out of hibernation.
// This is a Duration value; see https://pkg.go.dev/time#ParseDuration for accepted formats.
// Note: due to discrepancies in validation vs parsing, we use a Pattern instead of `Format=duration`. See
// https://bugzilla.redhat.com/show_bug.cgi?id=2050332
// https://github.com/kubernetes/apimachinery/issues/131
// https://github.com/kubernetes/apiextensions-apiserver/issues/56
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
HibernateAfter *metav1.Duration `json:"hibernateAfter,omitempty"`

// SkipMachinePools allows creating clusterpools where the machinepools are not managed by hive after cluster creation
Expand All @@ -80,18 +84,26 @@ type ClusterPoolSpec struct {
type ClusterPoolClaimLifetime struct {
// Default is the default lifetime of the claim when no lifetime is set on the claim itself.
// This is a Duration value; see https://pkg.go.dev/time#ParseDuration for accepted formats.
// Note: due to discrepancies in validation vs parsing, we use a Pattern instead of `Format=duration`. See
// https://bugzilla.redhat.com/show_bug.cgi?id=2050332
// https://github.com/kubernetes/apimachinery/issues/131
// https://github.com/kubernetes/apiextensions-apiserver/issues/56
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
Default *metav1.Duration `json:"default,omitempty"`

// Maximum is the maximum lifetime of the claim after it is assigned a cluster. If the claim still exists
// when the lifetime has elapsed, the claim will be deleted by Hive.
// The lifetime of a claim is the mimimum of the lifetimes set by the cluster pool and the claim itself.
// This is a Duration value; see https://pkg.go.dev/time#ParseDuration for accepted formats.
// Note: due to discrepancies in validation vs parsing, we use a Pattern instead of `Format=duration`. See
// https://bugzilla.redhat.com/show_bug.cgi?id=2050332
// https://github.com/kubernetes/apimachinery/issues/131
// https://github.com/kubernetes/apiextensions-apiserver/issues/56
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=duration
// +kubebuilder:validation:Pattern="^([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$"
Maximum *metav1.Duration `json:"maximum,omitempty"`
}

Expand Down
9 changes: 6 additions & 3 deletions config/crds/hive.openshift.io_clusterclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,14 @@ spec:
which to claim a cluster.
type: string
lifetime:
description: Lifetime is the maximum lifetime of the claim after it
is assigned a cluster. If the claim still exists when the lifetime
description: 'Lifetime is the maximum lifetime of the claim after
it is assigned a cluster. If the claim still exists when the lifetime
has elapsed, the claim will be deleted by Hive. This is a Duration
value; see https://pkg.go.dev/time#ParseDuration for accepted formats.
format: duration
Note: due to discrepancies in validation vs parsing, we use a Pattern
instead of `Format=duration`. See https://bugzilla.redhat.com/show_bug.cgi?id=2050332
https://github.com/kubernetes/apimachinery/issues/131 https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
type: string
namespace:
description: Namespace is the namespace containing the ClusterDeployment
Expand Down
8 changes: 5 additions & 3 deletions config/crds/hive.openshift.io_clusterdeployments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,15 @@ spec:
type: object
type: object
hibernateAfter:
description: HibernateAfter will transition a cluster to hibernating
description: 'HibernateAfter will transition a cluster to hibernating
power state after it has been running for the given duration. The
time that a cluster has been running is the time since the cluster
was installed or the time since the cluster last came out of hibernation.
This is a Duration value; see https://pkg.go.dev/time#ParseDuration
for accepted formats.
format: duration
for accepted formats. Note: due to discrepancies in validation vs
parsing, we use a Pattern instead of `Format=duration`. See https://bugzilla.redhat.com/show_bug.cgi?id=2050332
https://github.com/kubernetes/apimachinery/issues/131 https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
type: string
ingress:
description: Ingress allows defining desired clusteringress/shards
Expand Down
21 changes: 15 additions & 6 deletions config/crds/hive.openshift.io_clusterpools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,39 @@ spec:
cluster pool.
properties:
default:
description: Default is the default lifetime of the claim when
description: 'Default is the default lifetime of the claim when
no lifetime is set on the claim itself. This is a Duration value;
see https://pkg.go.dev/time#ParseDuration for accepted formats.
format: duration
Note: due to discrepancies in validation vs parsing, we use
a Pattern instead of `Format=duration`. See https://bugzilla.redhat.com/show_bug.cgi?id=2050332
https://github.com/kubernetes/apimachinery/issues/131 https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
type: string
maximum:
description: Maximum is the maximum lifetime of the claim after
description: 'Maximum is the maximum lifetime of the claim after
it is assigned a cluster. If the claim still exists when the
lifetime has elapsed, the claim will be deleted by Hive. The
lifetime of a claim is the mimimum of the lifetimes set by the
cluster pool and the claim itself. This is a Duration value;
see https://pkg.go.dev/time#ParseDuration for accepted formats.
format: duration
Note: due to discrepancies in validation vs parsing, we use
a Pattern instead of `Format=duration`. See https://bugzilla.redhat.com/show_bug.cgi?id=2050332
https://github.com/kubernetes/apimachinery/issues/131 https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
type: string
type: object
hibernateAfter:
description: HibernateAfter will be applied to new ClusterDeployments
description: 'HibernateAfter will be applied to new ClusterDeployments
created for the pool. HibernateAfter will transition clusters in
the clusterpool to hibernating power state after it has been running
for the given duration. The time that a cluster has been running
is the time since the cluster was installed or the time since the
cluster last came out of hibernation. This is a Duration value;
see https://pkg.go.dev/time#ParseDuration for accepted formats.
format: duration
Note: due to discrepancies in validation vs parsing, we use a Pattern
instead of `Format=duration`. See https://bugzilla.redhat.com/show_bug.cgi?id=2050332
https://github.com/kubernetes/apimachinery/issues/131 https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: ^([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$
type: string
imageSetRef:
description: ImageSetRef is a reference to a ClusterImageSet. The
Expand Down
41 changes: 26 additions & 15 deletions hack/app-sre/saas-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,14 @@ objects:
which to claim a cluster.
type: string
lifetime:
description: Lifetime is the maximum lifetime of the claim after
description: 'Lifetime is the maximum lifetime of the claim after
it is assigned a cluster. If the claim still exists when the lifetime
has elapsed, the claim will be deleted by Hive. This is a Duration
value; see https://pkg.go.dev/time#ParseDuration for accepted
formats.
format: duration
formats. Note: due to discrepancies in validation vs parsing,
we use a Pattern instead of `Format=duration`. See https://bugzilla.redhat.com/show_bug.cgi?id=2050332
https://github.com/kubernetes/apimachinery/issues/131 https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: "^([0-9]+(\\.[0-9]+)?(ns|us|\xB5s|ms|s|m|h))+$"
type: string
namespace:
description: Namespace is the namespace containing the ClusterDeployment
Expand Down Expand Up @@ -495,13 +497,16 @@ objects:
type: object
type: object
hibernateAfter:
description: HibernateAfter will transition a cluster to hibernating
description: 'HibernateAfter will transition a cluster to hibernating
power state after it has been running for the given duration.
The time that a cluster has been running is the time since the
cluster was installed or the time since the cluster last came
out of hibernation. This is a Duration value; see https://pkg.go.dev/time#ParseDuration
for accepted formats.
format: duration
for accepted formats. Note: due to discrepancies in validation
vs parsing, we use a Pattern instead of `Format=duration`. See
https://bugzilla.redhat.com/show_bug.cgi?id=2050332 https://github.com/kubernetes/apimachinery/issues/131
https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: "^([0-9]+(\\.[0-9]+)?(ns|us|\xB5s|ms|s|m|h))+$"
type: string
ingress:
description: Ingress allows defining desired clusteringress/shards
Expand Down Expand Up @@ -1762,33 +1767,39 @@ objects:
the cluster pool.
properties:
default:
description: Default is the default lifetime of the claim when
description: 'Default is the default lifetime of the claim when
no lifetime is set on the claim itself. This is a Duration
value; see https://pkg.go.dev/time#ParseDuration for accepted
formats.
format: duration
formats. Note: due to discrepancies in validation vs parsing,
we use a Pattern instead of `Format=duration`. See https://bugzilla.redhat.com/show_bug.cgi?id=2050332
https://github.com/kubernetes/apimachinery/issues/131 https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: "^([0-9]+(\\.[0-9]+)?(ns|us|\xB5s|ms|s|m|h))+$"
type: string
maximum:
description: Maximum is the maximum lifetime of the claim after
description: 'Maximum is the maximum lifetime of the claim after
it is assigned a cluster. If the claim still exists when the
lifetime has elapsed, the claim will be deleted by Hive. The
lifetime of a claim is the mimimum of the lifetimes set by
the cluster pool and the claim itself. This is a Duration
value; see https://pkg.go.dev/time#ParseDuration for accepted
formats.
format: duration
formats. Note: due to discrepancies in validation vs parsing,
we use a Pattern instead of `Format=duration`. See https://bugzilla.redhat.com/show_bug.cgi?id=2050332
https://github.com/kubernetes/apimachinery/issues/131 https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: "^([0-9]+(\\.[0-9]+)?(ns|us|\xB5s|ms|s|m|h))+$"
type: string
type: object
hibernateAfter:
description: HibernateAfter will be applied to new ClusterDeployments
description: 'HibernateAfter will be applied to new ClusterDeployments
created for the pool. HibernateAfter will transition clusters
in the clusterpool to hibernating power state after it has been
running for the given duration. The time that a cluster has been
running is the time since the cluster was installed or the time
since the cluster last came out of hibernation. This is a Duration
value; see https://pkg.go.dev/time#ParseDuration for accepted
formats.
format: duration
formats. Note: due to discrepancies in validation vs parsing,
we use a Pattern instead of `Format=duration`. See https://bugzilla.redhat.com/show_bug.cgi?id=2050332
https://github.com/kubernetes/apimachinery/issues/131 https://github.com/kubernetes/apiextensions-apiserver/issues/56'
pattern: "^([0-9]+(\\.[0-9]+)?(ns|us|\xB5s|ms|s|m|h))+$"
type: string
imageSetRef:
description: ImageSetRef is a reference to a ClusterImageSet. The
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading