Skip to content

Commit

Permalink
cron: adding validation for range or hyphenated inputs for start and …
Browse files Browse the repository at this point in the history
…end (#1836)

Signed-off-by: Ritikaa96 <[email protected]>
  • Loading branch information
Ritikaa96 authored Jun 2, 2021
1 parent e882be5 commit dff7b32
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/scalers/cron_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ func parseCronMetadata(config *ScalerConfig) (*cronMetadata, error) {
return nil, fmt.Errorf("no timezone specified. %s", config.TriggerMetadata)
}
if val, ok := config.TriggerMetadata["start"]; ok && val != "" {
if strings.Contains(val, "-") {
return nil, fmt.Errorf("error parsing start schedule. %s: range or hyphenated inputs are not allowed", config.TriggerMetadata)
}
meta.start = val
} else {
return nil, fmt.Errorf("no start schedule specified. %s", config.TriggerMetadata)
}
if val, ok := config.TriggerMetadata["end"]; ok && val != "" {
if strings.Contains(val, "-") {
return nil, fmt.Errorf("error parsing end schedule. %s: range or hyphenated inputs are not allowed", config.TriggerMetadata)
}
meta.end = val
} else {
return nil, fmt.Errorf("no end schedule specified. %s", config.TriggerMetadata)
Expand Down
5 changes: 5 additions & 0 deletions pkg/scalers/cron_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ var testCronMetadata = []parseCronMetadataTestData{
{validCronMetadata, false},
{map[string]string{"timezone": "Asia/Kolkata", "start": "30 * * * *", "end": "45 * * * *"}, true},
{map[string]string{"start": "30 * * * *", "end": "45 * * * *", "desiredReplicas": "10"}, true},
{map[string]string{"timezone": "Asia/Kolkata", "start": "30-33 * * * *", "end": "45 * * * *", "desiredReplicas": "10"}, true},
{map[string]string{"timezone": "Asia/Kolkata", "start": "30 * * * *", "end": "45-50 * * * *", "desiredReplicas": "10"}, true},
{map[string]string{"timezone": "Asia/Kolkata", "start": "-30 * * * *", "end": "45 * * * *", "desiredReplicas": "10"}, true},
{map[string]string{"timezone": "Asia/Kolkata", "start": "30 * * * *", "end": "-50 * * * *", "desiredReplicas": "10"}, true},
{map[string]string{"timezone": "Asia/Kolkata", "start": "30 * * * *", "end": "50 * * -3 *", "desiredReplicas": "10"}, true},
}

var cronMetricIdentifiers = []cronMetricIdentifier{
Expand Down

0 comments on commit dff7b32

Please sign in to comment.