diff --git a/CHANGELOG.md b/CHANGELOG.md index d72d239bb2b..8a0ea210164 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,7 +26,7 @@ ### Improvements -- TODO ([#XXX](https://github.com/kedacore/keda/pull/XXX)) +- Improve validation in Cron scaler in case start & end input is same.([#2032](https://github.com/kedacore/keda/pull/2032)) ### Breaking Changes diff --git a/pkg/scalers/cron_scaler.go b/pkg/scalers/cron_scaler.go index 81b98922a25..71fbf2a122d 100644 --- a/pkg/scalers/cron_scaler.go +++ b/pkg/scalers/cron_scaler.go @@ -89,6 +89,9 @@ func parseCronMetadata(config *ScalerConfig) (*cronMetadata, error) { } else { return nil, fmt.Errorf("no end schedule specified. %s", config.TriggerMetadata) } + if meta.start == meta.end { + return nil, fmt.Errorf("error parsing schedule. %s: start and end can not have exactly same time input", config.TriggerMetadata) + } if val, ok := config.TriggerMetadata["desiredReplicas"]; ok && val != "" { metadataDesiredReplicas, err := strconv.Atoi(val) if err != nil { diff --git a/pkg/scalers/cron_scaler_test.go b/pkg/scalers/cron_scaler_test.go index 68e841c2c29..0a0c2975dba 100644 --- a/pkg/scalers/cron_scaler_test.go +++ b/pkg/scalers/cron_scaler_test.go @@ -36,6 +36,7 @@ var testCronMetadata = []parseCronMetadataTestData{ {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}, + {map[string]string{"timezone": "Asia/Kolkata", "start": "30 * * * *", "end": "30 * * * *", "desiredReplicas": "10"}, true}, } var cronMetricIdentifiers = []cronMetricIdentifier{