Fix postgresql CRD for more safely validation
This change will allow to immediately discard invalid values when parsing a logicalBackupSchedule string.
Previously used regular expression '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$' may pass invalid values to cron, like "00 03 * * 7"
Although "00 03 * * 7" may be valid on some systems, but this value will throw an error when applied to kubernetes.
https://en.wikipedia.org/wiki/Cron
FYI: kubernetes uses cron implementation from go module "github.com/robfig/cron/v3"
https://github.com/robfig/cron/blob/v3/spec.go
https://github.com/robfig/cron/blob/v3/parser.go
			
			
This commit is contained in:
		
							parent
							
								
									88a2931550
								
							
						
					
					
						commit
						a7a03ab0b2
					
				|  | @ -217,7 +217,7 @@ spec: | ||||||
|                   x-kubernetes-preserve-unknown-fields: true |                   x-kubernetes-preserve-unknown-fields: true | ||||||
|               logicalBackupSchedule: |               logicalBackupSchedule: | ||||||
|                 type: string |                 type: string | ||||||
|                 pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$' |                 pattern: '^((0?[0-9]|[1-5]?[0-9])|\*)(/(0?[0-9]|[1-5]?[0-9]))?(\s+(2[0-3]|1[0-9]|0?[0-9]|\*)(/(2[0-3]|1[0-9]|0?[0-9]))?)(\s+(3[01]|[12][0-9]|0?[1-9]|\*)(/(3[01]|[12][0-9]|0?[1-9]))?)(\s+(1[0-2]|0?[1-9]|\*)(/(1[0-2]|0?[1-9]))?)(\s+(0?[0-6]|\*)(/0?[0-6])?)$' | ||||||
|               maintenanceWindows: |               maintenanceWindows: | ||||||
|                 type: array |                 type: array | ||||||
|                 items: |                 items: | ||||||
|  |  | ||||||
|  | @ -215,7 +215,7 @@ spec: | ||||||
|                   x-kubernetes-preserve-unknown-fields: true |                   x-kubernetes-preserve-unknown-fields: true | ||||||
|               logicalBackupSchedule: |               logicalBackupSchedule: | ||||||
|                 type: string |                 type: string | ||||||
|                 pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$' |                 pattern: '^((0?[0-9]|[1-5]?[0-9])|\*)(/(0?[0-9]|[1-5]?[0-9]))?(\s+(2[0-3]|1[0-9]|0?[0-9]|\*)(/(2[0-3]|1[0-9]|0?[0-9]))?)(\s+(3[01]|[12][0-9]|0?[1-9]|\*)(/(3[01]|[12][0-9]|0?[1-9]))?)(\s+(1[0-2]|0?[1-9]|\*)(/(1[0-2]|0?[1-9]))?)(\s+(0?[0-6]|\*)(/0?[0-6])?)$' | ||||||
|               maintenanceWindows: |               maintenanceWindows: | ||||||
|                 type: array |                 type: array | ||||||
|                 items: |                 items: | ||||||
|  |  | ||||||
|  | @ -344,7 +344,7 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{ | ||||||
| 					}, | 					}, | ||||||
| 					"logicalBackupSchedule": { | 					"logicalBackupSchedule": { | ||||||
| 						Type:    "string", | 						Type:    "string", | ||||||
| 						Pattern: "^(\\d+|\\*)(/\\d+)?(\\s+(\\d+|\\*)(/\\d+)?){4}$", | 						Pattern: "^((0?[0-9]|[1-5]?[0-9])|\\*)(/(0?[0-9]|[1-5]?[0-9]))?(\\s+(2[0-3]|1[0-9]|0?[0-9]|\\*)(/(2[0-3]|1[0-9]|0?[0-9]))?)(\\s+(3[01]|[12][0-9]|0?[1-9]|\\*)(/(3[01]|[12][0-9]|0?[1-9]))?)(\\s+(1[0-2]|0?[1-9]|\\*)(/(1[0-2]|0?[1-9]))?)(\\s+(0?[0-6]|\\*)(/0?[0-6])?)$", | ||||||
| 					}, | 					}, | ||||||
| 					"maintenanceWindows": { | 					"maintenanceWindows": { | ||||||
| 						Type: "array", | 						Type: "array", | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue