diff --git a/acceptance/deploy.sh b/acceptance/deploy.sh index 64554e3b64..4b7e2b9a98 100755 --- a/acceptance/deploy.sh +++ b/acceptance/deploy.sh @@ -57,7 +57,7 @@ if [ -n "${TEST_ORG}" ]; then cat acceptance/testdata/org.runnerdeploy.yaml | envsubst | kubectl apply -f - if [ -n "${TEST_ORG_REPO}" ]; then - cat acceptance/testdata/org.hra.yaml | kubectl apply -f - + cat acceptance/testdata/org.hra.yaml | envsubst | kubectl apply -f - else echo 'Skipped deploying organizational hra. Set TEST_ORG_REPO to "yourorg/yourrepo" to deploy.' fi diff --git a/acceptance/testdata/org.hra.yaml b/acceptance/testdata/org.hra.yaml index 8425562d48..a5c7b949db 100644 --- a/acceptance/testdata/org.hra.yaml +++ b/acceptance/testdata/org.hra.yaml @@ -12,6 +12,16 @@ spec: status: "queued" amount: 1 duration: "1m" + scheduledOverrides: + - startTime: "2021-05-11T16:05:00+09:00" + endTime: "2021-05-11T16:40:00+09:00" + minReplicas: 2 + - startTime: "2021-05-01T00:00:00+09:00" + endTime: "2021-05-03T00:00:00+09:00" + recurrenceRule: + frequency: Weekly + untilTime: "2022-05-01T00:00:00+09:00" + minReplicas: 0 minReplicas: 0 maxReplicas: 5 metrics: diff --git a/controllers/horizontalrunnerautoscaler_controller.go b/controllers/horizontalrunnerautoscaler_controller.go index 00dc248307..3fae2c8e3a 100644 --- a/controllers/horizontalrunnerautoscaler_controller.go +++ b/controllers/horizontalrunnerautoscaler_controller.go @@ -190,6 +190,15 @@ func (r *HorizontalRunnerAutoscalerReconciler) matchScheduledOverrides(log logr. var active, upcoming *Period for _, o := range hra.Spec.ScheduledOverrides { + log.V(1).Info( + "Checking scheduled override", + "now", now, + "startTime", o.StartTime, + "endTime", o.EndTime, + "frequency", o.RecurrenceRule.Frequency, + "untilTime", o.RecurrenceRule.UntilTime, + ) + a, u, err := MatchSchedule( now, o.StartTime.Time, o.EndTime.Time, RecurrenceRule{ @@ -203,16 +212,30 @@ func (r *HorizontalRunnerAutoscalerReconciler) matchScheduledOverrides(log logr. // Use the first when there are two or more active scheduled overrides, // as the spec defines that the earlier scheduled override is prioritized higher than later ones. - if active == nil { + if a != nil && active == nil { active = a if o.MinReplicas != nil { minReplicas = o.MinReplicas + + log.V(1).Info( + "Found active scheduled override", + "activeStartTime", a.StartTime, + "activeEndTime", a.EndTime, + "activeMinReplicas", minReplicas, + ) } } - if upcoming == nil || (u != nil && u.StartTime.Before(upcoming.StartTime)) { + if u != nil && (upcoming == nil || u.StartTime.Before(upcoming.StartTime)) { upcoming = u + + log.V(1).Info( + "Found upcoming scheduled override", + "upcomingStartTime", u.StartTime, + "upcomingEndTime", u.EndTime, + "upcomingMinReplicas", o.MinReplicas, + ) } }