Skip to content

Commit 664070e

Browse files
committed
FIXUP: review feedback
1 parent 98cba75 commit 664070e

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,12 +1955,11 @@ spec:
19551955
and unit: `3d`, `4 weeks`, `12 hr`, etc.
19561956
format: duration
19571957
minLength: 1
1958-
pattern: ^(PT)?(0|[0-9]+ *(?i:(h|hr|d|w|wk)|(hour|day|week)s?))+$
1958+
pattern: ^(PT)?[0-9]+ *(?i:(h|hr|d|w|wk)|(hour|day|week)s?)+$
19591959
type: string
19601960
x-kubernetes-validations:
1961-
- message: must be greater than one hour
1962-
rule: self == duration("0") || (self >= duration("1h") &&
1963-
self <= duration("8760h"))
1961+
- message: must be at least one hour
1962+
rule: duration("1h") <= self && self <= duration("8760h")
19641963
type: object
19651964
resources:
19661965
description: Resources holds the resource requirements for the

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11488,12 +11488,11 @@ spec:
1148811488
and unit: `3d`, `4 weeks`, `12 hr`, etc.
1148911489
format: duration
1149011490
minLength: 1
11491-
pattern: ^(PT)?(0|[0-9]+ *(?i:(h|hr|d|w|wk)|(hour|day|week)s?))+$
11491+
pattern: ^(PT)?[0-9]+ *(?i:(h|hr|d|w|wk)|(hour|day|week)s?)+$
1149211492
type: string
1149311493
x-kubernetes-validations:
11494-
- message: must be greater than one hour
11495-
rule: self == duration("0") || (self >= duration("1h") &&
11496-
self <= duration("8760h"))
11494+
- message: must be at least one hour
11495+
rule: duration("1h") <= self && self <= duration("8760h")
1149711496
type: object
1149811497
resources:
1149911498
description: Resources holds the resource requirements for the

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
k8s.io/apimachinery v0.31.0
2828
k8s.io/client-go v0.31.0
2929
k8s.io/component-base v0.31.0
30+
k8s.io/kube-openapi v0.0.0-20240521193020-835d969ad83a
3031
sigs.k8s.io/controller-runtime v0.19.3
3132
sigs.k8s.io/yaml v1.4.0
3233
)
@@ -120,7 +121,6 @@ require (
120121
k8s.io/apiextensions-apiserver v0.31.0 // indirect
121122
k8s.io/apiserver v0.31.0 // indirect
122123
k8s.io/klog/v2 v2.130.1 // indirect
123-
k8s.io/kube-openapi v0.0.0-20240521193020-835d969ad83a // indirect
124124
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
125125
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // indirect
126126
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect

internal/testing/validation/pgadmin_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ func TestPGAdminInstrumentation(t *testing.T) {
6060
"28 weeks",
6161
"90 DAY",
6262
"1 hr",
63-
"0 days",
64-
"0",
6563
"PT1D",
6664
} {
6765
u, err := runtime.ToUnstructuredObject(pgadmin)
@@ -72,5 +70,21 @@ func TestPGAdminInstrumentation(t *testing.T) {
7270
assert.NilError(t, cc.Create(ctx, u, client.DryRunAll), tt)
7371
}
7472
})
73+
74+
t.Run("Invalid", func(t *testing.T) {
75+
for _, tt := range []string{
76+
"0 days",
77+
"0",
78+
} {
79+
u, err := runtime.ToUnstructuredObject(pgadmin)
80+
assert.NilError(t, err)
81+
assert.NilError(t, unstructured.SetNestedField(u.Object,
82+
tt, "spec", "instrumentation", "logs", "retentionPeriod"))
83+
84+
err = cc.Create(ctx, u, client.DryRunAll)
85+
assert.Assert(t, apierrors.IsInvalid(err), tt)
86+
assert.ErrorContains(t, err, "retentionPeriod")
87+
}
88+
})
7589
})
7690
}

pkg/apis/postgres-operator.crunchydata.com/v1beta1/instrumentation_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ type InstrumentationLogsSpec struct {
5858
// ---
5959
// Kubernetes ensures the value is in the "duration" format, but go ahead
6060
// and loosely validate the format to show some acceptable units.
61-
// +kubebuilder:validation:Pattern=`^(PT)?(0|[0-9]+ *(?i:(h|hr|d|w|wk)|(hour|day|week)s?))+$`
61+
// +kubebuilder:validation:Pattern=`^(PT)?[0-9]+ *(?i:(h|hr|d|w|wk)|(hour|day|week)s?)+$`
6262
//
6363
// `controller-gen` needs to know "Type=string" to allow a "Pattern".
6464
// +kubebuilder:validation:Type=string
6565
//
66-
// +kubebuilder:validation:XValidation:rule=`self == duration("0") || (self >= duration("1h") && self <= duration("8760h"))`,message="must be greater than one hour"
66+
// +kubebuilder:validation:XValidation:rule=`duration("1h") <= self && self <= duration("8760h")`,message="must be at least one hour"
6767
// +optional
6868
RetentionPeriod *Duration `json:"retentionPeriod,omitempty"`
6969
}

pkg/apis/postgres-operator.crunchydata.com/v1beta1/shared_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func NewDuration(s string) (*Duration, error) {
6060
}
6161

6262
// AsDuration returns d as a [metav1.Duration].
63-
func (d Duration) AsDuration() metav1.Duration {
63+
func (d *Duration) AsDuration() metav1.Duration {
6464
return d.parsed
6565
}
6666

0 commit comments

Comments
 (0)