Skip to content

Commit

Permalink
auto-scaler types
Browse files Browse the repository at this point in the history
  • Loading branch information
pweil- committed Mar 12, 2015
1 parent 91131a6 commit 95c023f
Show file tree
Hide file tree
Showing 18 changed files with 1,066 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/api/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func init() {
&NamespaceList{},
&Secret{},
&SecretList{},
&AutoScaler{},
&AutoScalerList{},
)
// Legacy names are supported
Scheme.AddKnownTypeWithName("", "Minion", &Node{})
Expand Down Expand Up @@ -91,3 +93,5 @@ func (*Namespace) IsAnAPIObject() {}
func (*NamespaceList) IsAnAPIObject() {}
func (*Secret) IsAnAPIObject() {}
func (*SecretList) IsAnAPIObject() {}
func (*AutoScaler) IsAnAPIObject() {}
func (*AutoScalerList) IsAnAPIObject() {}
27 changes: 27 additions & 0 deletions pkg/api/rest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,30 @@ func (namespaceStrategy) Validate(obj runtime.Object) errors.ValidationErrorList
namespace := obj.(*api.Namespace)
return validation.ValidateNamespace(namespace)
}

// autoScalerStrategy implements behavior for AutoScalers
type autoScalerStrategy struct {
runtime.ObjectTyper
api.NameGenerator
}

// AutoScalers is the default logic that applies when creating and updating AutoScalers
// objects.
var AutoScalers RESTCreateStrategy = autoScalerStrategy{api.Scheme, api.SimpleNameGenerator}

// NamespaceScoped is true for AutoScalers.
func (autoScalerStrategy) NamespaceScoped() bool {
return true
}

// ResetBeforeCreate clears fields that are not allowed to be set by end users on creation.
func (autoScalerStrategy) ResetBeforeCreate(obj runtime.Object) {
autoScaler := obj.(*api.AutoScaler)
autoScaler.Status = api.AutoScalerStatus{}
}

// Validate validates a new AutoScalers.
func (autoScalerStrategy) Validate(obj runtime.Object) errors.ValidationErrorList {
autoScaler := obj.(*api.AutoScaler)
return validation.ValidateAutoScaler(autoScaler)
}
5 changes: 5 additions & 0 deletions pkg/api/testing/fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,11 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
ss.ContainerPort.StrVal = "x" + ss.ContainerPort.StrVal // non-empty
}
},
func(a *api.AutoScaler, c fuzz.Continue) {
c.Fuzz(&a.TypeMeta)
c.Fuzz(&a.ObjectMeta)
c.Fuzz(&a.Spec)
},
)
return f
}
91 changes: 91 additions & 0 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1456,3 +1456,94 @@ func AddToNodeAddresses(addresses *[]NodeAddress, addAddresses ...NodeAddress) {
}
}
}

// AutoScaler monitors other resources that are resizeable and adjusts them according to configuration.
type AutoScaler struct {
TypeMeta `json:",inline"`
ObjectMeta `json:"metadata,omitempty"`

// Spec defines the auto-scaler targets and thresholds.
Spec AutoScalerSpec `json:"spec,omitempty"`

// Status defines the actions the auto-scaler has taken.
Status AutoScalerStatus `json:"status,omitempty"`
}

// AutoScalerStatus provides the status of an auto-scaler.
type AutoScalerStatus struct {
// TODO: open for discussion on what meaningful information can be reported in the status
// The status may return the replica count here but we may want more information
// such as if the count reflects a threshold being passed.
}

// AutoScalerSpec defines the auto-scaler targets and thresholds.
type AutoScalerSpec struct {
// Thresholds holds a collection of AutoScaleThresholds that drive the auto-scaler.
Thresholds []AutoScaleThreshold `json:"thresholds,omitempty"`

// Enabled turns auto scaling on or off.
Enabled bool `json:"enabled,omitempty"`

// MaxAutoScaleCount defines the max replicas that the auto-scaler can use. This value must be
// >= MinAutoScaleCount.
MaxAutoScaleCount int `json:"maxAutoScaleCount,omitempty"`

// MinAutoScaleCount defines the minimum number replicas that the auto-scaler can reduce to,
// 0 means that the application is allowed to idle.
MinAutoScaleCount int `json:"minAutoScaleCount,omitempty"`

// TargetSelector provides the resizeable target(s). Right now this is a ReplicationController
// in the future it could be a job or any resource that implements resize. If multiple targets
// are resolved by the selector the auto-scaler will resize the largest one.
TargetSelector map[string]string `json:"targetSelector,omitempty"`

// MonitorSelector defines a set of capacity that the auto-scaler is monitoring
// (replication controllers). Monitored objects are used by thresholds to examine
// statistics. Example: get statistic X for object Y to see if threshold is passed.
MonitorSelector map[string]string `json:"monitorSelector,omitempty"`
}

// AutoScaleThreshold is a behavior based on statistics used to drive the auto-scaler in scaling decisions.
type AutoScaleThreshold struct {
// Type is the type of threshold being used, intention or value.
Type AutoScaleThresholdType `json:"type,omitempty"`

// IntentionConfig holds the config for intention based thresholds.
IntentionConfig AutoScaleIntentionThresholdConfig `json:"intentionConfig,omitempty"`
}

// AutoScaleIntentionThresholdConfig holds configuration for intention based thresholds.
// The scaler will adjust by 1 accordingly and maintain once the intention is reached.
type AutoScaleIntentionThresholdConfig struct {
// Intent is the lexicon of what intention is requested.
Intent AutoScaleIntentionType `json:"intent,omitempty"`

// Value is intention dependent in terms of above, below, equal and represents
// the value to check against.
Value float32 `json:"value,omitempty"`
}

// AutoScaleThresholdType is either intention based or value based.
type AutoScaleThresholdType string

// AutoScaleIntentionType is a lexicon for intentions such as "cpu-utilization",
// "max-rps-per-endpoint".
type AutoScaleIntentionType string

// Constants for auto-scalers and any auto-scaling child types like intentions
const (
// AutoScaleThresholdTypeIntention is used when defining an intention based threshold.
AutoScaleThresholdTypeIntention AutoScaleThresholdType = "Intention"

// TODO: AutoScaleIntentionType types
// example: AutoScaleIntentionTypeMaxRPS AutoScaleIntentionType = "MaxRPS"
)

// AutoScalerList is a list of AutoScaler items
type AutoScalerList struct {
TypeMeta `json:",inline"`
ListMeta `json:"metadata,omitempty"`

// Items is a list of AutoScaler objects.
Items []AutoScaler `json:"items"`
}
30 changes: 30 additions & 0 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,36 @@ func init() {
out.PodID = in.Name
return nil
},
func(in *newer.AutoScalerList, out *AutoScalerList, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.ListMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.Items, &out.Items, 0); err != nil {
return err
}
return nil
},
func(in *newer.AutoScaler, out *AutoScaler, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil {
return err
}

if err := s.Convert(&in.Spec, &out.Spec, 0); err != nil {
return err
}

if err := s.Convert(&in.Status, &out.Status, 0); err != nil {
return err
}

return nil
},
)
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/v1beta1/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func init() {
&NamespaceList{},
&Secret{},
&SecretList{},
&AutoScaler{},
&AutoScalerList{},
)
// Future names are supported
api.Scheme.AddKnownTypeWithName("v1beta1", "Node", &Minion{})
Expand Down Expand Up @@ -98,3 +100,5 @@ func (*Namespace) IsAnAPIObject() {}
func (*NamespaceList) IsAnAPIObject() {}
func (*Secret) IsAnAPIObject() {}
func (*SecretList) IsAnAPIObject() {}
func (*AutoScaler) IsAnAPIObject() {}
func (*AutoScalerList) IsAnAPIObject() {}
89 changes: 89 additions & 0 deletions pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1195,3 +1195,92 @@ type SecretList struct {

Items []Secret `json:"items" description:"items is a list of secret objects"`
}

// AutoScaler monitors other resources that are resizeable and adjusts them according to configuration.
type AutoScaler struct {
TypeMeta `json:",inline"`

// Spec defines the auto-scaler targets and thresholds.
Spec AutoScalerSpec `json:"spec,omitempty"`

// Status defines the actions the auto-scaler has taken.
Status AutoScalerStatus `json:"status,omitempty"`
}

// AutoScalerStatus provides the status of an auto-scaler.
type AutoScalerStatus struct {
// TODO: open for discussion on what meaningful information can be reported in the status
// The status may return the replica count here but we may want more information
// such as if the count reflects a threshold being passed.
}

// AutoScalerSpec defines the auto-scaler targets and thresholds.
type AutoScalerSpec struct {
// Thresholds holds a collection of AutoScaleThresholds that drive the auto-scaler.
Thresholds []AutoScaleThreshold `json:"thresholds,omitempty"`

// Enabled turns auto scaling on or off.
Enabled bool `json:"enabled,omitempty"`

// MaxAutoScaleCount defines the max replicas that the auto-scaler can use. This value must be
// >= MinAutoScaleCount.
MaxAutoScaleCount int `json:"maxAutoScaleCount,omitempty"`

// MinAutoScaleCount defines the minimum number replicas that the auto-scaler can reduce to,
// 0 means that the application is allowed to idle.
MinAutoScaleCount int `json:"minAutoScaleCount,omitempty"`

// TargetSelector provides the resizeable target(s). Right now this is a ReplicationController
// in the future it could be a job or any resource that implements resize. If multiple targets
// are resolved by the selector the auto-scaler will resize the largest one.
TargetSelector map[string]string `json:"targetSelector,omitempty"`

// MonitorSelector defines a set of capacity that the auto-scaler is monitoring
// (replication controllers). Monitored objects are used by thresholds to examine
// statistics. Example: get statistic X for object Y to see if threshold is passed.
MonitorSelector map[string]string `json:"monitorSelector,omitempty"`
}

// AutoScaleThreshold is a behavior based on statistics used to drive the auto-scaler in scaling decisions.
type AutoScaleThreshold struct {
// Type is the type of threshold being used, intention or value.
Type AutoScaleThresholdType `json:"type,omitempty"`

// IntentionConfig holds the config for intention based thresholds.
IntentionConfig AutoScaleIntentionThresholdConfig `json:"intentionConfig,omitempty"`
}

// AutoScaleIntentionThresholdConfig holds configuration for intention based thresholds.
// The scaler will adjust by 1 accordingly and maintain once the intention is reached.
type AutoScaleIntentionThresholdConfig struct {
// Intent is the lexicon of what intention is requested.
Intent AutoScaleIntentionType `json:"intent,omitempty"`

// Value is intention dependent in terms of above, below, equal and represents
// the value to check against.
Value float32 `json:"value,omitempty"`
}

// AutoScaleThresholdType is either intention based or value based.
type AutoScaleThresholdType string

// AutoScaleIntentionType is a lexicon for intentions such as "cpu-utilization",
// "max-rps-per-endpoint".
type AutoScaleIntentionType string

// Constants for auto-scalers and any auto-scaling child types like intentions
const (
// AutoScaleThresholdTypeIntention is used when defining an intention based threshold.
AutoScaleThresholdTypeIntention AutoScaleThresholdType = "Intention"

// TODO: AutoScaleIntentionType types
// example: AutoScaleIntentionTypeMaxRPS AutoScaleIntentionType = "MaxRPS"
)

// AutoScalerList is a list of AutoScaler items
type AutoScalerList struct {
TypeMeta `json:",inline"`

// Items is a list of AutoScaler objects.
Items []AutoScaler `json:"items"`
}
30 changes: 30 additions & 0 deletions pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,36 @@ func init() {
out.PodID = in.Name
return nil
},
func(in *newer.AutoScalerList, out *AutoScalerList, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.ListMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.Items, &out.Items, 0); err != nil {
return err
}
return nil
},
func(in *newer.AutoScaler, out *AutoScaler, s conversion.Scope) error {
if err := s.Convert(&in.TypeMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil {
return err
}

if err := s.Convert(&in.Spec, &out.Spec, 0); err != nil {
return err
}

if err := s.Convert(&in.Status, &out.Status, 0); err != nil {
return err
}

return nil
},
)
if err != nil {
// If one of the conversion functions is malformed, detect it immediately.
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/v1beta2/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func init() {
&NamespaceList{},
&Secret{},
&SecretList{},
&AutoScaler{},
&AutoScalerList{},
)
// Future names are supported
api.Scheme.AddKnownTypeWithName("v1beta2", "Node", &Minion{})
Expand Down Expand Up @@ -98,3 +100,5 @@ func (*Namespace) IsAnAPIObject() {}
func (*NamespaceList) IsAnAPIObject() {}
func (*Secret) IsAnAPIObject() {}
func (*SecretList) IsAnAPIObject() {}
func (*AutoScaler) IsAnAPIObject() {}
func (*AutoScalerList) IsAnAPIObject() {}
Loading

0 comments on commit 95c023f

Please sign in to comment.