diff --git a/internal/helpers/helpers_cron.go b/internal/helpers/helpers_cron.go index 250fe737..5b1563b3 100644 --- a/internal/helpers/helpers_cron.go +++ b/internal/helpers/helpers_cron.go @@ -145,6 +145,15 @@ func ConvertCrontab(namespace, cron string) (string, error) { hours = val continue } + sVal := strings.Split(val, ",") + if len(sVal) > 1 { + for _, r := range sVal { + if isInRange(r, 0, 23) { + continue + } + } + hours = val + } // if the value is not valid, return an error with where the issue is if hours == "" { return "", fmt.Errorf("cron definition '%s' is invalid, unable to determine hours value", cron) diff --git a/internal/helpers/helpers_cron_test.go b/internal/helpers/helpers_cron_test.go index 1208b416..df5359e0 100644 --- a/internal/helpers/helpers_cron_test.go +++ b/internal/helpers/helpers_cron_test.go @@ -191,6 +191,14 @@ func TestConvertCrontab(t *testing.T) { wantErrMsg: "cron definition '*/1 * * * * 7' is invalid, 6 fields provided, required 5", wantErr: true, }, + { + name: "test22 - split range hours", + args: args{ + namespace: "example-com-main", + cron: "*/30 0-12,22-23 * * *", + }, + want: "1,31 0-12,22-23 * * *", + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {