Skip to content

Commit

Permalink
updates based on feedback for types, comments, etcd factoring, remova…
Browse files Browse the repository at this point in the history
…l of Enabled field
  • Loading branch information
pweil- committed Mar 18, 2015
1 parent 6268fba commit 952e5d5
Show file tree
Hide file tree
Showing 11 changed files with 743 additions and 352 deletions.
11 changes: 4 additions & 7 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1468,25 +1468,22 @@ 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"`
MaxAutoScaleCount int64 `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"`
MinAutoScaleCount int64 `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
// MonitorSelector defines a set of resources 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.
// statistics. Example: get statistic X for object Y (the monitored object) to see if threshold is passed.
MonitorSelector map[string]string `json:"monitorSelector,omitempty"`
}

Expand Down
22 changes: 17 additions & 5 deletions pkg/api/v1beta1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1369,23 +1369,35 @@ func init() {
out.PodID = in.Name
return nil
},
func(in *newer.AutoScalerList, out *AutoScalerList, s conversion.Scope) error {
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.ListMeta, &out.TypeMeta, 0); err != nil {
if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.Items, &out.Items, 0); err != nil {
if err := s.Convert(&in.Labels, &out.Labels, 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
},
func(in *newer.AutoScaler, out *AutoScaler, s conversion.Scope) error {
func(in *AutoScaler, out *newer.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 {
if err := s.Convert(&in.TypeMeta, &out.ObjectMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
return err
}

Expand Down
12 changes: 5 additions & 7 deletions pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,7 @@ type SecretList struct {
// AutoScaler monitors other resources that are resizeable and adjusts them according to configuration.
type AutoScaler struct {
TypeMeta `json:",inline"`
Labels map[string]string `json:"labels,omitempty"`

// Spec defines the auto-scaler targets and thresholds.
Spec AutoScalerSpec `json:"spec,omitempty"`
Expand All @@ -1205,25 +1206,22 @@ 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"`
MaxAutoScaleCount int64 `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"`
MinAutoScaleCount int64 `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
// MonitorSelector defines a set of resources 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.
// statistics. Example: get statistic X for object Y (the monitored object) to see if threshold is passed.
MonitorSelector map[string]string `json:"monitorSelector,omitempty"`
}

Expand Down
22 changes: 17 additions & 5 deletions pkg/api/v1beta2/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,23 +1297,35 @@ func init() {
out.PodID = in.Name
return nil
},
func(in *newer.AutoScalerList, out *AutoScalerList, s conversion.Scope) error {
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.ListMeta, &out.TypeMeta, 0); err != nil {
if err := s.Convert(&in.ObjectMeta, &out.TypeMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
return err
}

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

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

return nil
},
func(in *newer.AutoScaler, out *AutoScaler, s conversion.Scope) error {
func(in *AutoScaler, out *newer.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 {
if err := s.Convert(&in.TypeMeta, &out.ObjectMeta, 0); err != nil {
return err
}
if err := s.Convert(&in.Labels, &out.Labels, 0); err != nil {
return err
}

Expand Down
12 changes: 5 additions & 7 deletions pkg/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,7 @@ type SecretList struct {
// AutoScaler monitors other resources that are resizeable and adjusts them according to configuration.
type AutoScaler struct {
TypeMeta `json:",inline"`
Labels map[string]string `json:"labels,omitempty"`

// Spec defines the auto-scaler targets and thresholds.
Spec AutoScalerSpec `json:"spec,omitempty"`
Expand All @@ -1268,25 +1269,22 @@ 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"`
MaxAutoScaleCount int64 `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"`
MinAutoScaleCount int64 `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
// MonitorSelector defines a set of resources 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.
// statistics. Example: get statistic X for object Y (the resource) to see if threshold is passed.
MonitorSelector map[string]string `json:"monitorSelector,omitempty"`
}

Expand Down
11 changes: 4 additions & 7 deletions pkg/api/v1beta3/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1341,25 +1341,22 @@ 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"`
MaxAutoScaleCount int64 `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"`
MinAutoScaleCount int64 `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
// MonitorSelector defines a set of resources 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.
// statistics. Example: get statistic X for object Y (the monitored object) to see if threshold is passed.
MonitorSelector map[string]string `json:"monitorSelector,omitempty"`
}

Expand Down
101 changes: 101 additions & 0 deletions pkg/registry/autoscaler/etcd/etcd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/*
Copyright 2014 Google Inc. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package etcd

import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/fields"
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/autoscaler"
"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic"
etcdgeneric "github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic/etcd"
"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime"
"github.com/GoogleCloudPlatform/kubernetes/pkg/tools"
"github.com/GoogleCloudPlatform/kubernetes/pkg/watch"
)

// rest implements a RESTStorage for pods against etcd
type REST struct {
store *etcdgeneric.Etcd
}

func NewREST(h tools.EtcdHelper) *REST {
prefix := "/registry/autoScalers"
return &REST{
store: &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.AutoScaler{} },
NewListFunc: func() runtime.Object { return &api.AutoScalerList{} },
KeyRootFunc: func(ctx api.Context) string {
return etcdgeneric.NamespaceKeyRootFunc(ctx, prefix)
},
KeyFunc: func(ctx api.Context, name string) (string, error) {
return etcdgeneric.NamespaceKeyFunc(ctx, prefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.AutoScaler).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return autoscaler.MatchAutoScaler(label, field)
},
CreateStrategy: autoscaler.AutoScalers,
UpdateStrategy: autoscaler.AutoScalers,
EndpointName: "autoScalers",

Helper: h,
},
}
}

// New returns a new object
func (r *REST) New() runtime.Object {
return r.store.NewFunc()
}

// NewList returns a new list object
func (r *REST) NewList() runtime.Object {
return r.store.NewListFunc()
}

// List obtains a list of autoscalers with labels that match selector.
func (r *REST) List(ctx api.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {
return r.store.List(ctx, label, field)
}

// Watch begins watching for new, changed, or deleted autoscalers.
func (r *REST) Watch(ctx api.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {
return r.store.Watch(ctx, label, field, resourceVersion)
}

// Get gets a specific autoscalers specified by its ID.
func (r *REST) Get(ctx api.Context, name string) (runtime.Object, error) {
return r.store.Get(ctx, name)
}

// Create creates a autoscalers based on a specification.
func (r *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, error) {
return r.store.Create(ctx, obj)
}

// Update changes a autoscalers specification.
func (r *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, bool, error) {
return r.store.Update(ctx, obj)
}

// Delete deletes an existing autoscalers specified by its ID.
func (r *REST) Delete(ctx api.Context, name string) (runtime.Object, error) {
return r.store.Delete(ctx, name)
}
Loading

0 comments on commit 952e5d5

Please sign in to comment.