fix schema validation and trim \ when unmarshalling maintenance window
This commit is contained in:
parent
7cc6354ddd
commit
ba67b23ed4
|
|
@ -102,19 +102,10 @@ spec:
|
|||
type: boolean
|
||||
default: false
|
||||
maintenance_windows:
|
||||
type: array
|
||||
nullable: true
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
endTime:
|
||||
type: string
|
||||
everyday:
|
||||
type: boolean
|
||||
startTime:
|
||||
type: string
|
||||
weekday:
|
||||
type: string
|
||||
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))\ *$'
|
||||
type: string
|
||||
type: array
|
||||
max_instances:
|
||||
type: integer
|
||||
description: "-1 = disabled"
|
||||
|
|
|
|||
|
|
@ -100,19 +100,10 @@ spec:
|
|||
type: boolean
|
||||
default: false
|
||||
maintenance_windows:
|
||||
type: array
|
||||
nullable: true
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
endTime:
|
||||
type: string
|
||||
everyday:
|
||||
type: boolean
|
||||
startTime:
|
||||
type: string
|
||||
weekday:
|
||||
type: string
|
||||
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))\ *$'
|
||||
type: string
|
||||
type: array
|
||||
max_instances:
|
||||
type: integer
|
||||
description: "-1 = disabled"
|
||||
|
|
|
|||
|
|
@ -128,25 +128,11 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
|
|||
Type: "boolean",
|
||||
},
|
||||
"maintenance_windows": {
|
||||
Type: "array",
|
||||
Nullable: true,
|
||||
Type: "array",
|
||||
Items: &apiextv1.JSONSchemaPropsOrArray{
|
||||
Schema: &apiextv1.JSONSchemaProps{
|
||||
Type: "object",
|
||||
Properties: map[string]apiextv1.JSONSchemaProps{
|
||||
"end_time": {
|
||||
Type: "string",
|
||||
},
|
||||
"everyday": {
|
||||
Type: "boolean",
|
||||
},
|
||||
"start_time": {
|
||||
Type: "string",
|
||||
},
|
||||
"weekday": {
|
||||
Type: "string",
|
||||
},
|
||||
},
|
||||
Type: "string",
|
||||
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))\\ *$",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ func (m *MaintenanceWindow) UnmarshalJSON(data []byte) error {
|
|||
err error
|
||||
)
|
||||
|
||||
parts := strings.Split(string(data), "-")
|
||||
dataStr := strings.Trim(string(data), "\"")
|
||||
parts := strings.Split(dataStr, "-")
|
||||
if len(parts) != 2 {
|
||||
return fmt.Errorf("incorrect maintenance window format")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,6 +91,13 @@ var maintenanceWindows = []struct {
|
|||
StartTime: mustParseTime("10:00"),
|
||||
EndTime: mustParseTime("20:00"),
|
||||
}, nil},
|
||||
{"regular every day scenario",
|
||||
[]byte(`"05:00-07:00"`),
|
||||
MaintenanceWindow{
|
||||
Everyday: true,
|
||||
StartTime: mustParseTime("05:00"),
|
||||
EndTime: mustParseTime("07:00"),
|
||||
}, nil},
|
||||
{"starts and ends at the same time",
|
||||
[]byte(`"Mon:10:00-10:00"`),
|
||||
MaintenanceWindow{
|
||||
|
|
|
|||
Loading…
Reference in New Issue