Skip to content

Commit 1a958b5

Browse files
authored
Merge pull request #45 from kitianFresh/feature/support-cron-for-ehpa
support cron for ehpa
2 parents 1618a98 + a26913d commit 1a958b5

File tree

4 files changed

+493
-271
lines changed

4 files changed

+493
-271
lines changed

artifacts/deploy/autoscaling.crane.io_effectivehorizontalpodautoscalers.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,43 @@ spec:
181181
type: integer
182182
type: object
183183
type: object
184+
crons:
185+
description: Crons contains cron specs to use crontab to scale workloads
186+
items:
187+
description: CronSpec defines the cron scale info
188+
properties:
189+
description:
190+
description: Description is the description of the cron
191+
type: string
192+
end:
193+
description: End is a crontab format, see https://en.wikipedia.org/wiki/Cron
194+
Define the cron schedule end, when it ended, EHPA will stop
195+
to trigger hpa to scale. Between the start and end, EHPA will
196+
keep replicas of the targetRef to equal to TargetReplicas,
197+
a scaling is a process rather than a instant action, make
198+
it as a final consistent system.
199+
type: string
200+
name:
201+
description: Name is the identifier of this cron scale. name
202+
must be unique in the same ehpa
203+
type: string
204+
start:
205+
description: Start is a crontab format, see https://en.wikipedia.org/wiki/Cron
206+
Define the cron schedule start, when the cron start is triggered,
207+
hpa will reconcile targetRef to scale to the TargetReplicas
208+
continuously.
209+
type: string
210+
targetReplicas:
211+
description: TargetReplicas is the target replicas when it is
212+
time to do scale between cron start and end
213+
format: int32
214+
type: integer
215+
timezone:
216+
description: TimeZone is the time zone of this cron schedule
217+
running in, default is UTC time.
218+
type: string
219+
type: object
220+
type: array
184221
maxReplicas:
185222
description: MaxReplicas is the upper limit replicas to the scale
186223
target which the autoscaler can scale up to. It cannot be less that

autoscaling/v1alpha1/ehpa_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77
_ "k8s.io/metrics/pkg/apis/custom_metrics"
88
_ "k8s.io/metrics/pkg/apis/custom_metrics/v1beta1"
99
_ "k8s.io/metrics/pkg/apis/custom_metrics/v1beta2"
10+
_ "k8s.io/metrics/pkg/apis/external_metrics"
11+
_ "k8s.io/metrics/pkg/apis/external_metrics/v1beta1"
1012
_ "k8s.io/metrics/pkg/apis/metrics"
1113
_ "k8s.io/metrics/pkg/apis/metrics/v1beta1"
1214

@@ -56,6 +58,9 @@ type EffectiveHorizontalPodAutoscalerSpec struct {
5658
// If not set, the default metric will be set to 80% average CPU utilization.
5759
// +optional
5860
Metrics []autoscalingv2.MetricSpec `json:"metrics,omitempty"`
61+
// Crons contains cron specs to use crontab to scale workloads
62+
// +optional
63+
Crons []CronSpec `json:"crons,omitempty"`
5964
// behavior configures the scaling behavior of the target
6065
// in both Up and Down directions (scaleUp and scaleDown fields respectively).
6166
// If not set, the default HPAScalingRules for scale up and scale down are used.
@@ -66,6 +71,33 @@ type EffectiveHorizontalPodAutoscalerSpec struct {
6671
Prediction *Prediction `json:"prediction,omitempty"`
6772
}
6873

74+
// CronSpec defines the cron scale info
75+
type CronSpec struct {
76+
// Name is the identifier of this cron scale. name must be unique in the same ehpa
77+
// +kubebuilder:validation:Type=string
78+
Name string `json:"name,omitempty"`
79+
// Description is the description of the cron
80+
// +optional
81+
// +kubebuilder:validation:Type=string
82+
Description string `json:"description,omitempty"`
83+
// TimeZone is the time zone of this cron schedule running in, default is UTC time.
84+
// +optional
85+
// +kubebuilder:validation:Type=string
86+
TimeZone *string `json:"timezone,omitempty"`
87+
// Start is a crontab format, see https://en.wikipedia.org/wiki/Cron
88+
// Define the cron schedule start, when the cron start is triggered, hpa will reconcile targetRef to scale to the TargetReplicas continuously.
89+
// +kubebuilder:validation:Type=string
90+
Start string `json:"start,omitempty"`
91+
// End is a crontab format, see https://en.wikipedia.org/wiki/Cron
92+
// Define the cron schedule end, when it ended, EHPA will stop to trigger hpa to scale.
93+
// Between the start and end, EHPA will keep replicas of the targetRef to equal to TargetReplicas, a scaling is a process rather than a instant action, make it as a final consistent system.
94+
// +kubebuilder:validation:Type=string
95+
End string `json:"end,omitempty"`
96+
// TargetReplicas is the target replicas when it is time to do scale between cron start and end
97+
// +kubebuilder:validation:Type=integer
98+
TargetReplicas int32 `json:"targetReplicas,omitempty"`
99+
}
100+
69101
// Prediction defines configurations for predict resources
70102
type Prediction struct {
71103
// PredictionWindowSeconds is the time window seconds to predict metrics in the future.

autoscaling/v1alpha1/zz_generated.deepcopy.go

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)