Skip to content

Commit ba67b23

Browse files
committed
fix schema validation and trim \ when unmarshalling maintenance window
1 parent 7cc6354 commit ba67b23

File tree

5 files changed

+18
-42
lines changed

5 files changed

+18
-42
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,10 @@ spec:
102102
type: boolean
103103
default: false
104104
maintenance_windows:
105-
type: array
106-
nullable: true
107105
items:
108-
type: object
109-
properties:
110-
endTime:
111-
type: string
112-
everyday:
113-
type: boolean
114-
startTime:
115-
type: string
116-
weekday:
117-
type: string
106+
pattern: '^\ *((Mon|Tue|Wed|Thu|Fri|Sat|Sun):(2[0-3]|[01]?\d):([0-5]?\d)|(2[0-3]|[01]?\d):([0-5]?\d))-((2[0-3]|[01]?\d):([0-5]?\d)|(2[0-3]|[01]?\d):([0-5]?\d))\ *$'
107+
type: string
108+
type: array
118109
max_instances:
119110
type: integer
120111
description: "-1 = disabled"

manifests/operatorconfiguration.crd.yaml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,10 @@ spec:
100100
type: boolean
101101
default: false
102102
maintenance_windows:
103-
type: array
104-
nullable: true
105103
items:
106-
type: object
107-
properties:
108-
endTime:
109-
type: string
110-
everyday:
111-
type: boolean
112-
startTime:
113-
type: string
114-
weekday:
115-
type: string
104+
pattern: '^\ *((Mon|Tue|Wed|Thu|Fri|Sat|Sun):(2[0-3]|[01]?\d):([0-5]?\d)|(2[0-3]|[01]?\d):([0-5]?\d))-((2[0-3]|[01]?\d):([0-5]?\d)|(2[0-3]|[01]?\d):([0-5]?\d))\ *$'
105+
type: string
106+
type: array
116107
max_instances:
117108
type: integer
118109
description: "-1 = disabled"

pkg/apis/acid.zalan.do/v1/crds.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,25 +128,11 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
128128
Type: "boolean",
129129
},
130130
"maintenance_windows": {
131-
Type: "array",
132-
Nullable: true,
131+
Type: "array",
133132
Items: &apiextv1.JSONSchemaPropsOrArray{
134133
Schema: &apiextv1.JSONSchemaProps{
135-
Type: "object",
136-
Properties: map[string]apiextv1.JSONSchemaProps{
137-
"end_time": {
138-
Type: "string",
139-
},
140-
"everyday": {
141-
Type: "boolean",
142-
},
143-
"start_time": {
144-
Type: "string",
145-
},
146-
"weekday": {
147-
Type: "string",
148-
},
149-
},
134+
Type: "string",
135+
Pattern: "^\\ *((Mon|Tue|Wed|Thu|Fri|Sat|Sun):(2[0-3]|[01]?\\d):([0-5]?\\d)|(2[0-3]|[01]?\\d):([0-5]?\\d))-((Mon|Tue|Wed|Thu|Fri|Sat|Sun):(2[0-3]|[01]?\\d):([0-5]?\\d)|(2[0-3]|[01]?\\d):([0-5]?\\d))\\ *$",
150136
},
151137
},
152138
},

pkg/apis/acid.zalan.do/v1/marshal.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func (m *MaintenanceWindow) UnmarshalJSON(data []byte) error {
3131
err error
3232
)
3333

34-
parts := strings.Split(string(data), "-")
34+
dataStr := strings.Trim(string(data), "\"")
35+
parts := strings.Split(dataStr, "-")
3536
if len(parts) != 2 {
3637
return fmt.Errorf("incorrect maintenance window format")
3738
}

pkg/apis/acid.zalan.do/v1/util_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ var maintenanceWindows = []struct {
9191
StartTime: mustParseTime("10:00"),
9292
EndTime: mustParseTime("20:00"),
9393
}, nil},
94+
{"regular every day scenario",
95+
[]byte(`"05:00-07:00"`),
96+
MaintenanceWindow{
97+
Everyday: true,
98+
StartTime: mustParseTime("05:00"),
99+
EndTime: mustParseTime("07:00"),
100+
}, nil},
94101
{"starts and ends at the same time",
95102
[]byte(`"Mon:10:00-10:00"`),
96103
MaintenanceWindow{

0 commit comments

Comments
 (0)