Skip to content

Commit

Permalink
ScheduledCapacity API (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
njtran authored Jan 14, 2021
1 parent 3d01994 commit 75a994e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 11 deletions.
35 changes: 28 additions & 7 deletions pkg/apis/autoscaling/v1alpha1/metricsproducer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type MetricsProducerSpec struct {
ReservedCapacity *ReservedCapacitySpec `json:"reservedCapacity,omitempty"`
// ScheduledCapacity produces a metric according to a specified schedule.
// +optional
ScheduledCapacity *ScheduledCapacitySpec `json:"scheduledCapacity,omitempty"`
Schedule *ScheduleSpec `json:"scheduleSpec,omitempty"`
}

type ReservedCapacitySpec struct {
Expand All @@ -46,17 +46,38 @@ type PendingCapacitySpec struct {
NodeSelector map[string]string `json:"nodeSelector"`
}

type ScheduledCapacitySpec struct {
// NodeSelector specifies a node group. The selector must uniquely identify a set of nodes.
NodeSelector map[string]string `json:"nodeSelector"`
type Timezone string

type ScheduleSpec struct {
// Behaviors may be layered to achieve complex scheduling autoscaling logic
Behaviors []ScheduledBehavior `json:"behaviors"`
// Defaults to UTC. Users will specify their schedules assuming this is their timezone
// ref: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
// +optional
Timezone *Timezone `json:"timezone,omitempty"`
// A schedule defaults to this value when no behaviors are active
DefaultReplicas int32 `json:"defaultReplicas"`
}

// ScheduledBehavior defines a crontab which sets the metric to a specific replica value on a schedule.
// ScheduledBehavior sets the metric to a replica value based on a start and end pattern.
type ScheduledBehavior struct {
Crontab string `json:"crontab"`
Replicas int32 `json:"replicas"`
// The value the MetricsProducer will emit when the current time is within start and end
Replicas int32 `json:"replicas"`
Start *Pattern `json:"start"`
End *Pattern `json:"end"`
}

// Pattern is a strongly-typed version of crontabs
type Pattern struct {
// When minutes or hours are left out, they are assumed to match to 0
Minutes *string `json:"minutes,omitempty"`
Hours *string `json:"hours,omitempty"`
// When Days, Months, or Weekdays are left out, they are represented by wildcards, meaning any time matches
Days *string `json:"days,omitempty"`
// List of 3-letter abbreviations i.e. Jan, Feb, Mar
Months *string `json:"months,omitempty"`
// List of 3-letter abbreviations i.e. "Mon, Tue, Wed"
Weekdays *string `json:"weekdays,omitempty"`
}

// PendingPodsSpec outputs a metric that identifies scheduling opportunities for pending pods in specified node groups.
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/autoscaling/v1alpha1/metricsproducer_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ type QueueStatus struct {
}

type ScheduledCapacityStatus struct {
// The current recommendation - the metric the MetricsProducer is emitting
CurrentValue *int32 `json:"currentValue,omitempty"`

// The time in the future where CurrentValue will switch to NextValue
NextValueTime *apis.VolatileTime `json:"nextValueTime,omitempty"`

// The next recommendation for the metric
NextValue *int32 `json:"nextValue,omitempty"`
}

// We use knative's libraries for ConditionSets to manage status conditions.
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/autoscaling/v1alpha1/metricsproducer_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func (mp *MetricsProducerSpec) Validate() error {
if mp.ReservedCapacity != nil {
return mp.ReservedCapacity.validate()
}
if mp.ScheduledCapacity != nil {
return mp.ScheduledCapacity.validate()
if mp.Schedule != nil {
return mp.Schedule.validate()
}
return nil
}
Expand All @@ -64,6 +64,6 @@ func (s *ReservedCapacitySpec) validate() error {
}

// Validate ScheduledCapacity
func (s *ScheduledCapacitySpec) validate() error {
func (s *ScheduleSpec) validate() error {
return nil
}
2 changes: 1 addition & 1 deletion pkg/metrics/producers/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (f *Factory) For(mp *v1alpha1.MetricsProducer) metrics.Producer {
Client: f.Client,
}
}
if mp.Spec.ScheduledCapacity != nil {
if mp.Spec.Schedule != nil {
return &scheduledcapacity.Producer{
MetricsProducer: mp,
}
Expand Down

0 comments on commit 75a994e

Please sign in to comment.