From b3cae25741162dbe5f5d2828b0f1396da6b1df23 Mon Sep 17 00:00:00 2001 From: Yusuke Kuoka Date: Mon, 3 May 2021 22:31:54 +0900 Subject: [PATCH] Enhance HorizontalRunnerAutoscaler API for ScheduledOverrides (#514) This adds types and CRD changes related to HorizontalRunnerAutoscaler for the upcoming ScheduledOverrides feature. Ref #484 --- .../horizontalrunnerautoscaler_types.go | 40 +++++++++++++++ api/v1alpha1/zz_generated.deepcopy.go | 46 +++++++++++++++++ ...rwind.dev_horizontalrunnerautoscalers.yaml | 51 +++++++++++++++++++ ...rwind.dev_horizontalrunnerautoscalers.yaml | 51 +++++++++++++++++++ 4 files changed, 188 insertions(+) diff --git a/api/v1alpha1/horizontalrunnerautoscaler_types.go b/api/v1alpha1/horizontalrunnerautoscaler_types.go index 2bf5cb66..701ded0f 100644 --- a/api/v1alpha1/horizontalrunnerautoscaler_types.go +++ b/api/v1alpha1/horizontalrunnerautoscaler_types.go @@ -142,6 +142,46 @@ type MetricSpec struct { // You can only specify either ScaleDownFactor or ScaleDownAdjustment. // +optional ScaleDownAdjustment int `json:"scaleDownAdjustment,omitempty"` + + // ScheduledOverrides is the list of ScheduledOverride. + // It can be used to override a few fields of HorizontalRunnerAutoscalerSpec on schedule. + // The earlier a scheduled override is, the higher it is prioritized. + // +optional + ScheduledOverrides []ScheduledOverride `json:"scheduledOverrides,omitempty"` +} + +// ScheduledOverride can be used to override a few fields of HorizontalRunnerAutoscalerSpec on schedule. +// A schedule can optionally be recurring, so that the correspoding override happens every day, week, month, or year. +type ScheduledOverride struct { + // StartTime is the time at which the first override starts. + StartTime metav1.Time `json:"startTime"` + + // EndTime is the time at which the first override ends. + EndTime metav1.Time `json:"endTime"` + + // MinReplicas is the number of runners while overriding. + // If omitted, it doesn't override minReplicas. + // +optional + // +nullable + // +kubebuilder:validation:Minimum=0 + MinReplicas *int `json:"minReplicas,omitempty"` + + // +optional + RecurrenceRule RecurrenceRule `json:"recurrenceRule,omitempty"` +} + +type RecurrenceRule struct { + // Frequency is the name of a predefined interval of each recurrence. + // The valid values are "Daily", "Weekly", "Monthly", and "Yearly". + // If empty, the corresponding override happens only once. + // +optional + // +kubebuilder:validation:Enum=Daily;Weekly;Monthly;Yearly + Frequency string `json:"frequency,omitempty"` + + // UntilTime is the time of the final recurrence. + // If empty, the schedule recurs forever. + // +optional + UntilTime metav1.Time `json:"untilTime,omitempty"` } type HorizontalRunnerAutoscalerStatus struct { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index fd310ae1..e47cc1c4 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -263,6 +263,13 @@ func (in *MetricSpec) DeepCopyInto(out *MetricSpec) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.ScheduledOverrides != nil { + in, out := &in.ScheduledOverrides, &out.ScheduledOverrides + *out = make([]ScheduledOverride, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MetricSpec. @@ -315,6 +322,22 @@ func (in *PushSpec) DeepCopy() *PushSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *RecurrenceRule) DeepCopyInto(out *RecurrenceRule) { + *out = *in + in.UntilTime.DeepCopyInto(&out.UntilTime) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RecurrenceRule. +func (in *RecurrenceRule) DeepCopy() *RecurrenceRule { + if in == nil { + return nil + } + out := new(RecurrenceRule) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Runner) DeepCopyInto(out *Runner) { *out = *in @@ -833,3 +856,26 @@ func (in *ScaleUpTrigger) DeepCopy() *ScaleUpTrigger { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ScheduledOverride) DeepCopyInto(out *ScheduledOverride) { + *out = *in + in.StartTime.DeepCopyInto(&out.StartTime) + in.EndTime.DeepCopyInto(&out.EndTime) + if in.MinReplicas != nil { + in, out := &in.MinReplicas, &out.MinReplicas + *out = new(int) + **out = **in + } + in.RecurrenceRule.DeepCopyInto(&out.RecurrenceRule) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ScheduledOverride. +func (in *ScheduledOverride) DeepCopy() *ScheduledOverride { + if in == nil { + return nil + } + out := new(ScheduledOverride) + in.DeepCopyInto(out) + return out +} diff --git a/charts/actions-runner-controller/crds/actions.summerwind.dev_horizontalrunnerautoscalers.yaml b/charts/actions-runner-controller/crds/actions.summerwind.dev_horizontalrunnerautoscalers.yaml index b7cd99ae..fe42777d 100644 --- a/charts/actions-runner-controller/crds/actions.summerwind.dev_horizontalrunnerautoscalers.yaml +++ b/charts/actions-runner-controller/crds/actions.summerwind.dev_horizontalrunnerautoscalers.yaml @@ -105,6 +105,57 @@ spec: description: ScaleUpThreshold is the percentage of busy runners greater than which will trigger the hpa to scale runners up. type: string + scheduledOverrides: + description: ScheduledOverrides is the list of ScheduledOverride. + It can be used to override a few fields of HorizontalRunnerAutoscalerSpec + on schedule. The earlier a scheduled override is, the higher + it is prioritized. + items: + description: ScheduledOverride can be used to override a few + fields of HorizontalRunnerAutoscalerSpec on schedule. A schedule + can optionally be recurring, so that the correspoding override + happens every day, week, month, or year. + properties: + endTime: + description: EndTime is the time at which the first override + ends. + format: date-time + type: string + minReplicas: + description: MinReplicas is the number of runners while + overriding. If omitted, it doesn't override minReplicas. + minimum: 0 + nullable: true + type: integer + recurrenceRule: + properties: + frequency: + description: Frequency is the name of a predefined interval + of each recurrence. The valid values are "Daily", + "Weekly", "Monthly", and "Yearly". If empty, the corresponding + override happens only once. + enum: + - Daily + - Weekly + - Monthly + - Yearly + type: string + untilTime: + description: UntilTime is the time of the final recurrence. + If empty, the schedule recurs forever. + format: date-time + type: string + type: object + startTime: + description: StartTime is the time at which the first override + starts. + format: date-time + type: string + required: + - endTime + - startTime + type: object + type: array type: description: Type is the type of metric to be used for autoscaling. The only supported Type is TotalNumberOfQueuedAndInProgressWorkflowRuns diff --git a/config/crd/bases/actions.summerwind.dev_horizontalrunnerautoscalers.yaml b/config/crd/bases/actions.summerwind.dev_horizontalrunnerautoscalers.yaml index b7cd99ae..fe42777d 100644 --- a/config/crd/bases/actions.summerwind.dev_horizontalrunnerautoscalers.yaml +++ b/config/crd/bases/actions.summerwind.dev_horizontalrunnerautoscalers.yaml @@ -105,6 +105,57 @@ spec: description: ScaleUpThreshold is the percentage of busy runners greater than which will trigger the hpa to scale runners up. type: string + scheduledOverrides: + description: ScheduledOverrides is the list of ScheduledOverride. + It can be used to override a few fields of HorizontalRunnerAutoscalerSpec + on schedule. The earlier a scheduled override is, the higher + it is prioritized. + items: + description: ScheduledOverride can be used to override a few + fields of HorizontalRunnerAutoscalerSpec on schedule. A schedule + can optionally be recurring, so that the correspoding override + happens every day, week, month, or year. + properties: + endTime: + description: EndTime is the time at which the first override + ends. + format: date-time + type: string + minReplicas: + description: MinReplicas is the number of runners while + overriding. If omitted, it doesn't override minReplicas. + minimum: 0 + nullable: true + type: integer + recurrenceRule: + properties: + frequency: + description: Frequency is the name of a predefined interval + of each recurrence. The valid values are "Daily", + "Weekly", "Monthly", and "Yearly". If empty, the corresponding + override happens only once. + enum: + - Daily + - Weekly + - Monthly + - Yearly + type: string + untilTime: + description: UntilTime is the time of the final recurrence. + If empty, the schedule recurs forever. + format: date-time + type: string + type: object + startTime: + description: StartTime is the time at which the first override + starts. + format: date-time + type: string + required: + - endTime + - startTime + type: object + type: array type: description: Type is the type of metric to be used for autoscaling. The only supported Type is TotalNumberOfQueuedAndInProgressWorkflowRuns